Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
shipmentitem.php
1<?php
2
3
5
6
7use Bitrix\Main\Entity\DataManager;
12
13class ShipmentItem extends Base
14{
15 public function getFields()
16 {
17 return [
18 'ID'=>[
19 'TYPE'=>self::TYPE_INT,
20 'ATTRIBUTES'=>[Attributes::ReadOnly]
21 ],
22 'ORDER_DELIVERY_ID'=>[
23 'TYPE'=>self::TYPE_INT,
24 'ATTRIBUTES'=>[
27 ]
28 ],
29 'BASKET_ID'=>[
30 'TYPE'=>self::TYPE_INT,
31 'ATTRIBUTES'=>[
34 ]
35 ],
36 'QUANTITY'=>[
37 'TYPE'=>self::TYPE_FLOAT,
38 'ATTRIBUTES'=>[Attributes::Required]
39 ],
40 'XML_ID'=>[
41 'TYPE'=>self::TYPE_STRING
42 ],
43 'DATE_INSERT'=>[
44 'TYPE'=>self::TYPE_DATETIME,
45 'ATTRIBUTES'=>[Attributes::ReadOnly]
46 ],
47 'RESERVED_QUANTITY'=>[
48 'TYPE'=>self::TYPE_FLOAT,
49 'ATTRIBUTES'=>[Attributes::ReadOnly]
50 ],
51 'STORES'=>[
52 'TYPE'=>self::TYPE_LIST,
53 'ATTRIBUTES'=>[Attributes::Hidden]
54 ]
55 ];
56 }
57
58 public function internalizeFieldsModify($fields, $fieldsInfo=[])
59 {
60 $result = [];
61
62 $fieldsInfo = empty($fieldsInfo)? $this->getFields():$fieldsInfo;
63 $listFieldsInfoAdd = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly]]]);
64 $listFieldsInfoUpdate = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable], 'skipFields'=>['ID']]]);
65
66 foreach ($fields['SHIPMENT']['SHIPMENT_ITEMS'] as $k=>$item)
67 {
68 $result['SHIPMENT']['SHIPMENT_ITEMS'][$k] = $this->internalizeFields($item,
69 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
70 );
71 }
72
73 return $result;
74 }
75
76 public function checkFieldsModify($fields)
77 {
78 $r = new Result();
79
80 $emptyFields = [];
81
82 if(!isset($fields['SHIPMENT']['ID']))
83 {
84 $emptyFields[] = '[shipment][id]';
85 }
86 if(!isset($fields['SHIPMENT']['SHIPMENT_ITEMS']) || !is_array($fields['SHIPMENT']['SHIPMENT_ITEMS']))
87 {
88 $emptyFields[] = '[shipment][shipmentItems][]';
89 }
90
91 if(count($emptyFields)>0)
92 {
93 $r->addError(new Error(implode(', ', $emptyFields)));
94 }
95 else
96 {
97 $r = parent::checkFieldsModify($fields);
98 }
99
100 return $r;
101 }
102
103 public function checkRequiredFieldsModify($fields)
104 {
105 $r = new Result();
106
107 $listFieldsInfoAdd = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly], 'ignoredFields'=>['ORDER_DELIVERY_ID']]]);
108 $listFieldsInfoUpdate = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable]]]);
109
110 foreach ($fields['SHIPMENT']['SHIPMENT_ITEMS'] as $k=>$item)
111 {
112 $required = $this->checkRequiredFields($item,
113 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
114 );
115 if(!$required->isSuccess())
116 {
117 $r->addError(new Error('[shipmentItems]['.$k.'] - '.implode(', ', $required->getErrorMessages()).'.'));
118 }
119 }
120
121 return $r;
122 }
123}
getListFieldInfo(array $fieldsInfo, $params=[])
Definition base.php:62
internalizeFields($fields, array $fieldsInfo)
Definition base.php:281
checkRequiredFields($fields, array $fieldsInfo, $params=[])
Definition base.php:676
internalizeFieldsModify($fields, $fieldsInfo=[])