Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
providerbuilder.php
1<?php
2
4
7
13{
17 public function addProductByBasketItem(Sale\BasketItemBase $basketItem)
18 {
19 $fields = array(
20 'ITEM_CODE' => $basketItem->getProductId(),
21 'BASKET_ID' => $basketItem->getId(),
22 'BASKET_CODE' => $basketItem->getBasketCode(),
23 'PRODUCT_ID' => $basketItem->getProductId(),
24 'QUANTITY' => $basketItem->getNotPurchasedQuantity(),
25 'RESERVED_QUANTITY' => $basketItem->getReservedQuantity(),
26 'IS_BARCODE_MULTI' => $basketItem->isBarcodeMulti(),
27 'BUNDLE_CHILD' => false,
28 'SUBSCRIBE' => $basketItem->getField('SUBSCRIBE') === 'Y',
29 );
30
31 if ($basketItem instanceof Sale\BasketItem)
32 {
33 $fields['BUNDLE_CHILD'] = $basketItem->isBundleChild();
34 }
35
36 $this->addItem($basketItem->getProductId(), $fields);
37 }
38
42 public function addProductByShipmentItem(Sale\ShipmentItem $shipmentItem)
43 {
44 $basketItem = $shipmentItem->getBasketItem();
45 $productId = $basketItem->getProductId();
46
47 $fields = [
48 'ITEM_CODE' => $productId,
49 'BASKET_CODE' => $basketItem->getBasketCode(),
50 'PRODUCT_ID' => $productId,
51 'QUANTITY' => $shipmentItem->getQuantity(),
52 'IS_BARCODE_MULTI' => $basketItem->isBarcodeMulti(),
53 'BUNDLE_CHILD' => $basketItem->isBundleChild(),
54 'SHIPMENT_ITEM_DATA' => [
55 $shipmentItem->getInternalIndex() => $shipmentItem->getQuantity(),
56 ],
57 'SHIPMENT_ITEM' => $shipmentItem,
58 ];
59
61 {
62 $storeData = Sale\Internals\Catalog\Provider::createMapShipmentItemStoreData($shipmentItem);
63
64 $reservedQuantity = 0;
65 $needReserveByStore = [];
66
67 if ($storeData)
68 {
69 foreach ($storeData as $item)
70 {
71 $reservedQuantity += $item['RESERVED_QUANTITY'];
72
73 $needReserveByStore[$item['STORE_ID']] = $item['RESERVED_QUANTITY'] > 0;
74 }
75 }
76
77 $fields['STORE_DATA'] = array(
78 $shipmentItem->getInternalIndex() => $storeData,
79 );
80
81 $fields['NEED_RESERVE_BY_STORE'] = [
82 $shipmentItem->getInternalIndex() => $needReserveByStore,
83 ];
84 }
85 else
86 {
87 $reservedQuantity = $basketItem->getReservedQuantity();
88 }
89
90 $fields['RESERVED_QUANTITY'] = $reservedQuantity;
91 $fields['NEED_RESERVE'] = [
92 $shipmentItem->getInternalIndex() => $reservedQuantity > 0,
93 ];
94
95 $this->addItem($productId, $fields);
96 }
97
102 public function addProductData(array $productData)
103 {
104 if ($productData['QUANTITY'] == 0)
105 {
106 return;
107 }
108
110 $shipmentItem = $productData['SHIPMENT_ITEM'] ?? null;
111 $basketItem = $productData['BASKET_ITEM'];
112 $productId = $productData['PRODUCT_ID'] ?? $basketItem->getProductId();
113
114 $fields = [
115 'ITEM_CODE' => $productId,
116 'BASKET_CODE' => $basketItem->getBasketCode(),
117 'PRODUCT_ID' => $productId,
118 'QUANTITY' => $productData['QUANTITY'],
119 'BUNDLE_PARENT' => $basketItem->isBundleParent(),
120 'BUNDLE_CHILD' => $basketItem->isBundleChild(),
121 'IS_BARCODE_MULTI' => $basketItem->isBarcodeMulti(),
122 'RESERVED_QUANTITY' => $productData['RESERVED_QUANTITY'] ?? 0.0,
123 ];
124
125 if ($shipmentItem)
126 {
127 $fields['SHIPMENT_ITEM'] = $shipmentItem;
128 $fields['SHIPMENT_ITEM_DATA'] = [$shipmentItem->getInternalIndex() => $shipmentItem->getQuantity()];
129 $fields['NEED_RESERVE'] = [$shipmentItem->getInternalIndex() => $productData["NEED_RESERVE"] ?? null];
130 }
131
133 {
134 if ($shipmentItem)
135 {
136 $storeData = Sale\Internals\Catalog\Provider::createMapShipmentItemStoreData($shipmentItem);
137
138 if (!empty($storeData))
139 {
140 $fields['STORE_DATA'] = [
141 $shipmentItem->getInternalIndex() => $storeData,
142 ];
143 }
144 }
145 }
146
147 if (isset($productData['NEED_RESERVE_BY_STORE']))
148 {
149 $fields['NEED_RESERVE_BY_STORE'] = $productData['NEED_RESERVE_BY_STORE'];
150 }
151
152 if (isset($productData['QUANTITY_BY_STORE']))
153 {
154 $fields['QUANTITY_BY_STORE'] = $productData['QUANTITY_BY_STORE'];
155 }
156
157 if (isset($productData['RESERVED_QUANTITY_BY_STORE']))
158 {
159 $fields['RESERVED_QUANTITY_BY_STORE'] = $productData['RESERVED_QUANTITY_BY_STORE'];
160 }
161
162 $this->addItem($productId, $fields);
163 }
164
172 public function setItemsResultAfterTryShip(PoolQuantity $pool, array $productTryShipList)
173 {
174 $products = $this->getItems();
175
176 if (empty($products))
177 {
178 return new Sale\Result();
179 }
180
181 foreach ($products as $productId => $productData)
182 {
183 if (!isset($productTryShipList[$productId]))
184 {
185 continue;
186 }
187
188 if (empty($productData['SHIPMENT_ITEM_DATA_LIST']))
189 {
190 continue;
191 }
192
193 if (empty($productData['SHIPMENT_ITEM_LIST']))
194 {
195 continue;
196 }
197
202 foreach ($productData['SHIPMENT_ITEM_DATA_LIST'] as $shipmentItemIndex => $shipmentItemQuantity)
203 {
204 $shipmentItem = $productData['SHIPMENT_ITEM_LIST'][$shipmentItemIndex] ?? null;
205 if ($shipmentItem === null)
206 {
207 continue;
208 }
209
210 $shipment = $shipmentItem->getCollection()->getShipment();
211
212 $coefficient = -1;
213 if ($shipment->needShip() === Sale\Internals\Catalog\Provider::SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP)
214 {
215 $coefficient = 1;
216 }
217
218 $shipmentItemQuantity = $shipmentItem->getQuantity();
219
221 $shipmentItemStoreCollection = $shipmentItem->getShipmentItemStoreCollection();
222 if ($shipmentItemStoreCollection)
223 {
225 foreach ($shipmentItemStoreCollection as $shipmentItemStore)
226 {
227 $quantity = $coefficient * $shipmentItemStore->getQuantity();
228 $pool->addByStore(PoolQuantity::POOL_QUANTITY_TYPE, $productId, $shipmentItemStore->getStoreId(), $quantity);
229
230 $shipmentItemQuantity -= $shipmentItemStore->getQuantity();
231 }
232 }
233
234 if ($shipmentItemQuantity > 0)
235 {
236 $pool->add(PoolQuantity::POOL_QUANTITY_TYPE, $productId, $shipmentItemQuantity);
237 }
238
239 $foundItem = false;
240 $poolItems = Sale\Internals\ItemsPool::get($shipment->getOrder()->getInternalId(), $productId);
241 if (!empty($poolItems))
242 {
244 foreach ($poolItems as $poolItem)
245 {
246 if (
247 $poolItem instanceof Sale\ShipmentItem
248 && $poolItem->getInternalIndex() == $shipmentItem->getInternalIndex()
249 )
250 {
251 $foundItem = true;
252 break;
253 }
254 }
255 }
256
257 if (!$foundItem)
258 {
259 Sale\Internals\ItemsPool::add($shipment->getOrder()->getInternalId(), $productId, $shipmentItem);
260 }
261 }
262 }
263
264 return new Sale\Result();
265 }
266
270 public function getTransferClassName()
271 {
272 return '\Bitrix\Sale\Internals\TransferProvider';
273 }
274
275}
setItemsResultAfterTryShip(PoolQuantity $pool, array $productTryShipList)
addProductByBasketItem(Sale\BasketItemBase $basketItem)
addProductByShipmentItem(Sale\ShipmentItem $shipmentItem)