Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
transferproviderbase.php
1<?php
2
4
7
12{
13 protected $providerClass = null;
14 protected $context = null;
15
19 protected function __construct()
20 {
21
22 }
23
27 protected function getProviderClass()
28 {
30 }
31
35 protected function getProviderName()
36 {
37 $providerName = null;
39
41 {
42 $reflect = new \ReflectionClass($providerClass);
43 $providerName = $reflect->getName();
44 }
45
46 return $providerName;
47 }
48
52 protected function getContext()
53 {
54 return $this->context;
55 }
56
64 public static function create($providerClass, array $context)
65 {
66 $transferProvider = new static();
68 {
69 $transferProvider->providerClass = $providerClass;
70 }
71
72 $transferProvider->context = $context;
73
74 return $transferProvider;
75 }
76
82 abstract public function getProductData(array $products);
83
90 abstract public function tryShip(array $products);
91
98 abstract public function isNeedShip(array $products);
99
105 abstract public function ship(array $products);
106
112 abstract public function reserve(array $products);
113
120 abstract public function deliver(array $products);
121
128 abstract public function viewProduct(array $products);
129
136 abstract public function getProductListStores(array $products);
137
146 abstract public function setItemsResultAfterTryShip(PoolQuantity $pool, array $products, array $productTryShipList);
147
155 public function setItemsResultAfterShip(array $products, Sale\Result $resultAfterShip)
156 {
157 $result = new Sale\Result();
158
159 $needReverse = false;
160 $shippedProductList = array();
161 $resultData = $resultAfterShip->getData();
162 if (!empty($resultData['SHIPPED_PRODUCTS_LIST']))
163 {
164 $shippedProductList = $resultData['SHIPPED_PRODUCTS_LIST'];
165
166 foreach ($shippedProductList as $isShipped)
167 {
168 if ($isShipped === false)
169 {
170 $needReverse = true;
171 break;
172 }
173 }
174 }
175
176 $shipmentList = array();
177 $productIndex = array();
178
179 foreach ($products as $productId => $itemData)
180 {
181 if (!empty($itemData['SHIPMENT_ITEM_LIST']))
182 {
184 foreach ($itemData['SHIPMENT_ITEM_LIST'] as $shipmentItemIndex => $shipmentItem)
185 {
186 $basketItem = $shipmentItem->getBasketItem();
187 $shipment = $shipmentItem->getCollection()->getShipment();
188
189 if (isset($itemData['NEED_RESERVE_BY_STORE_LIST'][$shipmentItemIndex]))
190 {
191 $needReverseByStore = $itemData['NEED_RESERVE_BY_STORE_LIST'][$shipmentItemIndex];
192 foreach ($needReverseByStore as $storeId => $isNeeded)
193 {
195 $reserveQuantityCollection = $basketItem->getReserveQuantityCollection();
196
197 if (
198 $isNeeded
199 && $reserveQuantityCollection
200 && $shipment->needShip() !== Catalog\Provider::SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP)
201 {
203 foreach ($reserveQuantityCollection as $reserve)
204 {
205 if ($reserve->getStoreId() !== $storeId)
206 {
207 continue;
208 }
209
210 if (isset($itemData['STORE_DATA_LIST'][$shipmentItemIndex][$storeId]))
211 {
212 $reserveQuantity = $itemData['STORE_DATA_LIST'][$shipmentItemIndex][$storeId]['RESERVED_QUANTITY'];
213 }
214 else
215 {
216 $reserveQuantity = $shipmentItem->getQuantity();
217 }
218
219 if ($reserve->getQuantity() > $reserveQuantity)
220 {
221 $reserve->setFieldNoDemand('QUANTITY', $reserve->getQuantity() - $reserveQuantity);
222 }
223 else
224 {
225 $reserve->deleteNoDemand();
226 }
227 }
228 }
229 }
230
231 if ($shipment->needShip() !== Catalog\Provider::SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP)
232 {
233 $shipmentItem->getFields()->set('RESERVED_QUANTITY', 0);
234 }
235 }
236
237 $shipmentIndex = $shipment->getInternalIndex();
238 if (!array_key_exists($shipmentIndex, $shipmentList))
239 {
240 $shipmentList[$shipmentIndex] = $shipment;
241 }
242
243 if (
244 !isset($productIndex[$shipmentIndex][$shipmentItemIndex])
245 || !in_array($productId, $productIndex[$shipmentIndex][$shipmentItemIndex])
246 )
247 {
248 $productIndex[$shipmentIndex][$shipmentItemIndex] = $productId;
249 }
250 }
251 }
252 }
253
254 $reverseProducts = array();
255 if ($needReverse && !empty($productIndex))
256 {
257 foreach ($productIndex as $productList)
258 {
259 foreach ($productList as $productId)
260 {
261 $isExistsProduct = array_key_exists($productId, $shippedProductList);
262
263 if (
264 $isExistsProduct
265 && $shippedProductList[$productId] === true
266 && empty($reverseProducts[$productId])
267 )
268 {
269 $reverseProducts[$productId] = $products[$productId];
270 $reverseProducts[$productId]['QUANTITY'] *= -1;
271 }
272 }
273 }
274 }
275
276 if ($needReverse && !empty($reverseProducts))
277 {
278 $r = $this->ship($reverseProducts);
279 }
280
281 return $result;
282 }
283
289 abstract public function getAvailableQuantity(array $products);
290
296 abstract public function getAvailableQuantityByStore(array $products);
297
303 abstract public function getAvailableQuantityAndPrice(array $products);
304
310 abstract public function getBundleItems(array $products);
311
315 abstract public function getStoresCount();
316
321 public function writeOffProductBatches(array $products): Sale\Result
322 {
323 return new Sale\Result();
324 }
325
330 public function returnProductBatches(array $products): Sale\Result
331 {
332 return new Sale\Result();
333 }
334}
static create($providerClass, array $context)
setItemsResultAfterTryShip(PoolQuantity $pool, array $products, array $productTryShipList)