Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderarchive.php
1<?php
9
10use Bitrix\Main;
11use Bitrix\Sale;
12
29class OrderArchiveTable extends Main\Entity\DataManager
30{
36 public static function getTableName()
37 {
38 return 'b_sale_order_archive';
39 }
40
46 public static function getMap()
47 {
48 return array(
49 new Main\Entity\IntegerField(
50 'ID',
51 array(
52 'autocomplete' => true,
53 'primary' => true,
54 )
55 ),
56 new Main\Entity\StringField(
57 'LID',
58 array(
59 'required' => true,
60 )
61 ),
62 new Main\Entity\IntegerField(
63 'ORDER_ID',
64 array(
65 'required' => true,
66 )
67 ),
68 new Main\Entity\StringField(
69 'ACCOUNT_NUMBER',
70 array(
71 'size' => 100,
72 'required' => true,
73 )
74 ),
75 new Main\Entity\StringField(
76 'USER_ID',
77 array(
78 'required' => true,
79 )
80 ),
81 new Main\Entity\ReferenceField(
82 'USER',
83 '\Bitrix\Main\User',
84 array('=this.USER_ID' => 'ref.ID'),
85 array('join_type' => 'INNER')
86 ),
87 new Main\Entity\StringField(
88 'PERSON_TYPE_ID',
89 array(
90 'required' => true,
91 )
92 ),
93
94 new Main\Entity\StringField('STATUS_ID'),
95
96 new Main\Entity\ReferenceField(
97 'STATUS',
98 'Bitrix\Sale\Internals\StatusLang',
99 array(
100 '=this.STATUS_ID' => 'ref.STATUS_ID',
101 '=ref.LID' => array('?', LANGUAGE_ID)
102 )
103 ),
104
105 new Main\Entity\BooleanField(
106 'PAYED',
107 array(
108 'values' => array('N', 'Y')
109 )
110 ),
111
112 new Main\Entity\BooleanField(
113 'DEDUCTED',
114 array(
115 'values' => array('N','Y')
116 )
117 ),
118
119 new Main\Entity\BooleanField(
120 'CANCELED',
121 array(
122 'values' => array('N', 'Y')
123 )
124 ),
125
126 new Main\Entity\FloatField(
127 'PRICE',
128 array(
129 'default_value' => '0.0000'
130 )
131 ),
132
133 new Main\Entity\FloatField(
134 'SUM_PAID',
135 array(
136 'default_value' => '0.0000'
137 )
138 ),
139
140 new Main\Entity\StringField(
141 'CURRENCY',
142 array(
143 'required' => true,
144 'size' => 3
145 )
146 ),
147
148 new Main\Entity\IntegerField(
149 'VERSION',
150 array(
151 'required' => true,
152 )
153 ),
154
155 new Main\Entity\IntegerField('XML_ID'),
156
157 new Main\Entity\IntegerField('ID_1C'),
158
159 new Main\Entity\DatetimeField('DATE_ARCHIVED'),
160
161 new Main\Entity\DatetimeField('DATE_INSERT'),
162
163 new Main\Entity\IntegerField('RESPONSIBLE_ID'),
164
165 new Main\Entity\IntegerField('COMPANY_ID'),
166
167 new Main\Entity\StringField('ORDER_DATA'),
168
169 new Main\Entity\ReferenceField(
170 'BASKET_ARCHIVE',
171 'Bitrix\Sale\Internals\BasketArchive',
172 array(
173 '=ref.ARCHIVE_ID' => 'this.ID'
174 )
175 ),
176
177 new Main\Entity\ReferenceField(
178 'ORDER_PACKED',
179 'Bitrix\Sale\Internals\OrderArchivePacked',
180 array('=this.ID' => 'ref.ORDER_ARCHIVE_ID'),
181 array('join_type' => 'INNER')
182 )
183 );
184 }
185
203 public static function add(array $data)
204 {
205 $orderData = $data['ORDER_DATA'];
206 unset($data['ORDER_DATA']);
207
208 $result = parent::add($data);
209
210 if ($result->isSuccess())
211 {
212 OrderArchivePackedTable::add(array(
213 "ORDER_ARCHIVE_ID" => $result->getId(),
214 "ORDER_DATA" => $orderData
215 ));
216 }
217
218 return $result;
219 }
220
230 public static function delete($primary)
231 {
232 $result = parent::delete($primary);
233
234 if ($result->isSuccess())
235 {
236 $checkOrderData = OrderArchivePackedTable::getById($primary);
237 if ($checkOrderData->fetch())
238 {
239 OrderArchivePackedTable::delete($primary);
240 }
241 }
242
243 return $result;
244 }
245
253 public static function renew(array $filter = array())
254 {
255 $result = new Main\Result();
256 $parameters = array("select" => array('ID'));
257
258 if (!empty($filter))
259 $parameters['filter'] = $filter;
260
261 $idList = array();
262 $archivedOrderData = self::getList($parameters);
263 while ($archiveRow = $archivedOrderData->fetch())
264 {
265 $idList[] = $archiveRow['ID'];
266 }
267
268 if (empty($idList))
269 return $result;
270
271 $idListChunk = array_chunk($idList, 1000);
272 foreach ($idListChunk as $chunk)
273 {
274 $packedData = OrderArchivePackedTable::getList(array(
275 "filter" => array("ORDER_ARCHIVE_ID" => $chunk)
276 ));
277
278 while ($packed = $packedData->fetch())
279 {
280 $orderData = unserialize($packed['ORDER_DATA'], ['allowed_classes' => false]);
281 if (is_array($orderData['ORDER']))
282 {
283 $preparedOrderData = array_intersect_key($orderData['ORDER'], array_flip(Sale\Archive\Manager::getOrderFieldNames()));
284 $result = self::update($packed['ORDER_ARCHIVE_ID'], $preparedOrderData);
285 if (!$result->isSuccess())
286 return $result;
287 }
288 }
289 }
290
291 return $result;
292 }
293}
static renew(array $filter=array())