Bitrix-D7  20.5.0
Класс Provider

Открытые статические члены

static getProductData ($basketList, array $context)
 
static getBundleItems (Sale\BasketItemBase $basketItem, array $context)
 
static checkAvailableQuantityByBasketItem (Sale\BasketItemBase $basketItem, array $context=array())
 
static getAvailableQuantityAndPriceByBasketItem (Sale\BasketItemBase $basketItem, array $context=array())
 
static tryReserveShipment (Sale\Shipment $shipment, array $context=array())
 
static tryReserveShipmentItem (Sale\ShipmentItem $shipmentItem, array $context=array())
 
static tryUnreserveShipmentItem (Sale\ShipmentItem $shipmentItem)
 
static tryUnreserveShipment (Sale\Shipment $shipment)
 
static tryShipShipment (Sale\Shipment $shipment, array $context=array())
 
static createProviderItemsMap (Sale\ShipmentItemCollection $shipmentItemCollection)
 
static createProviderItemsMapByRules (array $rulesProducts)
 
static createMapShipmentItemStoreData (Sale\ShipmentItem $shipmentItem)
 
static createMapShipmentItemCollectionStoreData ($shipmentItemList)
 
static save (Sale\Order $order, array $context=array())
 
static getOrderByShipment (Sale\Shipment $shipment)
 
static getProviderName ($module, $name)
 
static getProviderEntity ($name)
 
static isProviderCallbackFunction ($name)
 
static setIgnoreErrors ($value)
 
static isIgnoreErrors ()
 

Поля данных

const SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_SHIP = true
 
const SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP = false
 
const SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_EMPTY = null
 

Подробное описание

См. определение в файле sale/lib/internals/catalog/provider.php строка 17

Методы

◆ checkAvailableQuantityByBasketItem()

static checkAvailableQuantityByBasketItem ( Sale\BasketItemBase  $basketItem,
array  $context = array() 
)
static
Аргументы
Sale\BasketItemBase$basketItem
array | null$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 114

115  {
116  $result = new Sale\Result();
117 
118  /** @var \Bitrix\Sale\Basket $basket */
119  if (!$basket = $basketItem->getCollection())
120  {
121  throw new Main\ObjectNotFoundException('Entity "Basket" not found');
122  }
123 
124  $order = $basket->getOrder();
125  if (empty($context) && $order)
126  {
127  $context = static::prepareContext($order, $context);
128  }
129 
130  $r = static::checkContext($context);
131  if (!$r->isSuccess())
132  {
133  return $r;
134  }
135 
136  $quantity = $basketItem->getQuantity();
137  $productId = $basketItem->getProductId();
138  $poolQuantity = 0;
139 
140  if ($order)
141  {
142  $fields = $basketItem->getFields();
143  $originalValues = $fields->getOriginalValues();
144  $values = $fields->getValues();
145  $deltaQuantity = floatval($values['QUANTITY']) - floatval($originalValues['QUANTITY']);
146 
147  if ($deltaQuantity <= 0)
148  {
149  $result->setData(
150  array(
151  'AVAILABLE_QUANTITY' => $quantity
152  )
153  );
154 
155  return $result;
156  }
157 
158  $pool = PoolQuantity::getInstance($order->getInternalId());
159  $poolQuantity = $pool->get(PoolQuantity::POOL_RESERVE_TYPE, $productId);
160  if (!empty($poolQuantity))
161  {
162  $tryQuantity = $quantity + $poolQuantity;
163  if ($tryQuantity == 0)
164  {
165  $result->setData(array(
166  'AVAILABLE_QUANTITY' => $quantity
167  ));
168 
169  return $result;
170  }
171  }
172  }
173 
174 
175  $resultList = array();
176 
177  $creator = Sale\Internals\ProviderCreator::create($context);
178 
179  /** @var Sale\BasketItem $basketItem */
180  $creator->addBasketItem($basketItem);
181 
182  $r = $creator->getAvailableQuantity();
183  if ($r->isSuccess())
184  {
185  $providerName = null;
186  $providerName = $basketItem->getProviderName();
187 
188  if (strval(trim($providerName)) == '')
189  {
190  $providerName = $basketItem->getCallbackFunction();
191  }
192 
193  if (!empty($providerName) && $providerName[0] == "\\")
194  {
195  $providerName = ltrim($providerName, '\\');
196  }
197 
198  $checkProviderName = $providerName;
199  $data = $r->getData();
200  if (array_key_exists('AVAILABLE_QUANTITY_LIST', $data) && isset($data['AVAILABLE_QUANTITY_LIST'][$checkProviderName]))
201  {
202  $resultList = $data['AVAILABLE_QUANTITY_LIST'][$checkProviderName];
203  }
204  }
205  else
206  {
207  $result->addErrors($r->getErrors());
208  }
209 
210  if (isset($resultList[$productId]))
211  {
212  $result->setData(
213  array(
214  'AVAILABLE_QUANTITY' => $resultList[$productId] - $poolQuantity
215  )
216  );
217  }
218 
219  return $result;
220  }

◆ createMapShipmentItemCollectionStoreData()

static createMapShipmentItemCollectionStoreData (   $shipmentItemList)
static

См. определение в файле sale/lib/internals/catalog/provider.php строка 1355

1356  {
1357  $resultList = array();
1358 
1359  /** @var Sale\ShipmentItem $shipmentItem */
1360  foreach ($shipmentItemList as $shipmentItem)
1361  {
1362  $basketCode = $shipmentItem->getBasketCode();
1363 
1364  if (!isset($resultList[$basketCode]))
1365  {
1366  $resultList[$basketCode] = array();
1367  }
1368 
1369  $map = static::createMapShipmentItemStoreData($shipmentItem);
1370  if (!empty($map) && is_array($map))
1371  {
1372  $resultList[$basketCode] = $map + $resultList[$basketCode];
1373  }
1374  }
1375 
1376  return $resultList;
1377  }

◆ createMapShipmentItemStoreData()

static createMapShipmentItemStoreData ( Sale\ShipmentItem  $shipmentItem)
static

См. определение в файле sale/lib/internals/catalog/provider.php строка 1294

1295  {
1296  $resultList = array();
1297 
1298  /** @var Sale\BasketItem $basketItem */
1299  if (!$basketItem = $shipmentItem->getBasketItem())
1300  {
1301  throw new Main\ObjectNotFoundException('Entity "BasketItem" not found');
1302  }
1303 
1304  if ($basketItem->isBundleParent())
1305  {
1306  return false;
1307  }
1308 
1309  /** @var Sale\ShipmentItemStoreCollection $shipmentItemStoreCollection */
1310  if (!$shipmentItemStoreCollection = $shipmentItem->getShipmentItemStoreCollection())
1311  {
1312  throw new Main\ObjectNotFoundException('Entity "ShipmentItemStoreCollection" not found');
1313  }
1314 
1315  if ($shipmentItemStoreCollection->count() > 0)
1316  {
1317  $countBarcode = 0;
1318  /** @var Sale\ShipmentItemStore $shipmentItemStore */
1319  foreach ($shipmentItemStoreCollection as $shipmentItemStore)
1320  {
1321  $productId = $basketItem->getProductId();
1322 
1323  $storeId = $shipmentItemStore->getStoreId();
1324 
1325  if (!isset($resultList[$storeId]))
1326  {
1327  $resultList[$storeId] = array(
1328  'PRODUCT_ID' => $productId,
1329  'QUANTITY' => 0,
1330  'STORE_ID' => $storeId,
1331  'IS_BARCODE_MULTI' => $basketItem->isBarcodeMulti(),
1332  'BARCODE' => array()
1333  );
1334  }
1335 
1336  $barcodeId = ($shipmentItemStore->getId() > 0)? $shipmentItemStore->getId() : 'n'.$countBarcode;
1337  $countBarcode++;
1338  $resultList[$storeId]['QUANTITY'] += $basketItem->isBarcodeMulti()? 1 : $shipmentItemStore->getQuantity();
1339  $resultList[$storeId]['BARCODE'][$barcodeId] = $shipmentItemStore->getBarcode();
1340 
1341  }
1342  }
1343 
1344  return $resultList;
1345  }

◆ createProviderItemsMap()

static createProviderItemsMap ( Sale\ShipmentItemCollection  $shipmentItemCollection)
static
Аргументы
Sale\ShipmentItemCollection$shipmentItemCollection
Возвращает
array
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 1174

1175  {
1176  $providerProductList = array();
1177  /** @var Sale\ShipmentItem $shipmentItem */
1178  foreach ($shipmentItemCollection as $shipmentItem)
1179  {
1180  $basketItem = $shipmentItem->getBasketItem();
1181 
1182  if (!$basketItem)
1183  {
1184  throw new Main\ObjectNotFoundException('Entity "BasketItem" not found');
1185  }
1186  if ($basketItem->isBundleParent())
1187  {
1188  continue;
1189  }
1190 
1191  $productId = $basketItem->getProductId();
1192  $providerName = $basketItem->getProvider();
1193  if (!isset($providerProductList[$providerName][$productId]))
1194  {
1195  $fields = array(
1196  'PRODUCT_ID' => $productId,
1197  'QUANTITY' => floatval($shipmentItem->getQuantity()),
1198  'SHIPMENT_ITEM_LIST' => array(),
1199  'IS_BUNDLE_CHILD' => $basketItem->isBundleChild(),
1200  );
1201  }
1202  else
1203  {
1204  $fields = $providerProductList[$providerName][$productId];
1205  $fields['QUANTITY'] += floatval($shipmentItem->getQuantity());
1206  }
1207 
1208  $shipmentItemIndex = $shipmentItem->getInternalIndex();
1209  $barcodeStoreData = static::createMapShipmentItemStoreData($shipmentItem);
1210  if (!empty($barcodeStoreData))
1211  {
1212  $fields['STORE'][$shipmentItemIndex] = $barcodeStoreData;
1213 // $fields['STORE'][$shipmentItemIndex]['IS_BARCODE_MULTI'] = $basketItem->isBarcodeMulti();
1214  }
1215 
1216  $fields['SHIPMENT_ITEM_LIST'][$shipmentItemIndex] = $shipmentItem;
1217 
1218  $providerProductList[$providerName][$productId] = $fields;
1219  }
1220 
1221  return $providerProductList;
1222  }

◆ createProviderItemsMapByRules()

static createProviderItemsMapByRules ( array  $rulesProducts)
static
Аргументы
array$rulesProducts
Возвращает
array
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 1230

1231  {
1232  $providerProductList = array();
1233 
1234  foreach ($rulesProducts as $ruleData)
1235  {
1236  /** @var Sale\ShipmentItem $shipmentItem */
1237  $shipmentItem = $ruleData['SHIPMENT_ITEM'];
1238  if (!$shipmentItem)
1239  {
1240  throw new Main\ObjectNotFoundException('Entity "ShipmentItem" not found');
1241  }
1242 
1243 
1244  $productId = $ruleData['PRODUCT_ID'];
1245  $providerName = $ruleData['PROVIDER_NAME'];
1246  $shipmentItemIndex = $shipmentItem->getInternalIndex();
1247 
1248 
1249  if (!isset($providerProductList[$providerName][$productId]))
1250  {
1251  $fields = $ruleData;
1252  unset($fields['SHIPMENT_ITEM']);
1253  unset($fields['STORE']);
1254  unset($fields['NEED_RESERVE']);
1255  unset($fields['NEED_SHIP']);
1256  $fields['SHIPMENT_ITEM_LIST'] = array();
1257  }
1258  else
1259  {
1260  $fields = $providerProductList[$providerName][$productId];
1261  $fields['QUANTITY'] += $ruleData['QUANTITY'];
1262  }
1263 
1264  if (array_key_exists('NEED_RESERVE', $ruleData))
1265  {
1266  $fields['NEED_RESERVE'][$shipmentItemIndex] = $ruleData['NEED_RESERVE'];
1267  }
1268 
1269  if (array_key_exists('NEED_SHIP', $ruleData))
1270  {
1271  $fields['NEED_SHIP'][$shipmentItemIndex] = $ruleData['NEED_SHIP'];
1272  }
1273 
1274  if (!empty($ruleData['STORE']))
1275  {
1276  $fields['STORE'][$shipmentItemIndex] = $ruleData['STORE'][$shipmentItemIndex];
1277  }
1278 
1279  $fields['SHIPMENT_ITEM_LIST'][$shipmentItemIndex] = $shipmentItem;
1280 
1281  $providerProductList[$providerName][$productId] = $fields;
1282  }
1283 
1284  return $providerProductList;
1285  }

◆ getAvailableQuantityAndPriceByBasketItem()

static getAvailableQuantityAndPriceByBasketItem ( Sale\BasketItemBase  $basketItem,
array  $context = array() 
)
static
Аргументы
Sale\BasketItemBase$basketItem
array | null$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 230

231  {
232  $result = new Sale\Result();
233 
234  /** @var \Bitrix\Sale\Basket $basket */
235  if (!$basket = $basketItem->getCollection())
236  {
237  throw new Main\ObjectNotFoundException('Entity "Basket" not found');
238  }
239 
240  $order = $basket->getOrder();
241 
242  if (empty($context) && !$order)
243  {
244  $context = $basket->getContext();
245  }
246 
247  if (empty($context) && $order)
248  {
249  $context = static::prepareContext($order, $context);
250  }
251 
252  $r = static::checkContext($context);
253  if (!$r->isSuccess())
254  {
255  return $r;
256  }
257 
258  $resultData = array();
259 
260  $creator = Sale\Internals\ProviderCreator::create($context);
261 
262  /** @var Sale\BasketItem $basketItem */
263  $creator->addBasketItem($basketItem);
264 
265  $r = $creator->getAvailableQuantityAndPrice();
266  if ($r->isSuccess())
267  {
268  $providerName = $basketItem->getProviderName();
269 
270  if (strval($providerName) == '')
271  {
272  $providerName = $basketItem->getCallbackFunction();
273  }
274 
275  $providerName = static::clearProviderName($providerName);
276 
277  $checkProviderName = $providerName;
278  $data = $r->getData();
279  if (array_key_exists('PRODUCT_DATA_LIST', $data) && isset($data['PRODUCT_DATA_LIST'][$checkProviderName]))
280  {
281  $productData = $data['PRODUCT_DATA_LIST'][$checkProviderName];
282 
283  if (isset($productData['PRICE_LIST'][$basketItem->getProductId()][$basketItem->getBasketCode()]))
284  {
285  $resultData['PRICE_DATA'] = $productData['PRICE_LIST'][$basketItem->getProductId()][$basketItem->getBasketCode()];
286  }
287 
288  if (isset($productData['AVAILABLE_QUANTITY_LIST'][$basketItem->getProductId()]))
289  {
290  $resultData['AVAILABLE_QUANTITY'] = $productData['AVAILABLE_QUANTITY_LIST'][$basketItem->getProductId()];
291  }
292  }
293  }
294  else
295  {
296  $result->addErrors($r->getErrors());
297  }
298 
299  if (isset($resultData))
300  {
301  $result->setData(
302  $resultData
303  );
304  }
305 
306  return $result;
307  }

◆ getBundleItems()

static getBundleItems ( Sale\BasketItemBase  $basketItem,
array  $context 
)
static
Аргументы
Sale\BasketItemBase$basketItem
array$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 80

81  {
82  if (empty($context))
83  {
84  throw new Main\ArgumentNullException('context');
85  }
86 
87  $result = new Sale\Result();
88 
89  $creator = Sale\Internals\ProviderCreator::create($context);
90  /** @var Sale\BasketItem $basketItem */
91  $creator->addBasketItem($basketItem);
92 
93  $r = $creator->getBundleItems();
94  if ($r->isSuccess())
95  {
96  return $r;
97  }
98  else
99  {
100  $result->addErrors($r->getErrors());
101  }
102 
103  return $result;
104  }

◆ getOrderByShipment()

static getOrderByShipment ( Sale\Shipment  $shipment)
static
Аргументы
Sale\Shipment$shipment
Возвращает
Sale\Order
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 1441

1442  {
1443  /** @var Sale\ShipmentCollection $shipmentCollection */
1444  $shipmentCollection = $shipment->getCollection();
1445  if (!$shipmentCollection)
1446  {
1447  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
1448  }
1449 
1450  $order = $shipmentCollection->getOrder();
1451  if (!$order)
1452  {
1453  throw new Main\ObjectNotFoundException('Entity "Order" not found');
1454  }
1455 
1456  return $order;
1457  }

◆ getProductData()

static getProductData (   $basketList,
array  $context 
)
static
Аргументы
$basketList
array$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 35

36  {
37  $result = new Sale\Result();
38 
39  if (empty($context))
40  {
41  throw new Main\ArgumentNullException('context');
42  }
43 
44  if (!is_array($basketList) && !($basketList instanceof Sale\BasketBase))
45  {
46  throw new Main\ArgumentTypeException('basketList');
47  }
48 
49  $creator = Sale\Internals\ProviderCreator::create($context);
50  /** @var Sale\BasketItem $basketItem */
51  foreach ($basketList as $basketItem)
52  {
53  $creator->addBasketItem($basketItem);
54  }
55 
56  $r = $creator->getProductData();
57  if ($r->isSuccess())
58  {
59  $data = $r->getData();
60  if (array_key_exists('PRODUCT_DATA_LIST', $data))
61  {
62  $result->setData($data);
63  }
64  }
65  else
66  {
67  $result->addErrors($r->getErrors());
68  }
69 
70  return $result;
71  }
Class RestHandler \Handlers\PaySystem.

◆ getProviderEntity()

static getProviderEntity (   $name)
static
Аргументы
$name
Возвращает
mixed|null

См. определение в файле sale/lib/internals/catalog/provider.php строка 1602

1603  {
1604  static $providerEntityProxy = array();
1605  if (array_key_exists($name, $providerEntityProxy))
1606  {
1607  return $providerEntityProxy[$name];
1608  }
1609 
1610  if (class_exists($name))
1611  {
1612  $productProvider = new $name();
1613  if ($productProvider instanceof Sale\SaleProviderBase || array_key_exists("IBXSaleProductProvider", class_implements($name)))
1614  {
1615  $providerEntityProxy[$name] = $productProvider;
1616  return $productProvider;
1617  }
1618  }
1619 
1620  return null;
1621  }

◆ getProviderName()

static getProviderName (   $module,
  $name 
)
static
Аргументы
$module
$name
Возвращает
string|null
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 1569

1570  {
1571  static $providerProxy = array();
1572  $code = $module."|".$name;
1573 
1574  if (array_key_exists($code, $providerProxy))
1575  {
1576  return $providerProxy[$code];
1577  }
1578 
1579  $providerName = null;
1580  if (strval($module) != '' && Main\Loader::includeModule($module) && class_exists($name))
1581  {
1582  $provider = static::getProviderEntity($name);
1583  if ($provider)
1584  {
1585  $providerName = $name;
1586  }
1587  }
1588 
1589  if ($providerName !== null)
1590  {
1591  $providerProxy[$code] = $providerName;
1592  }
1593 
1594  return $providerName;
1595  }
static includeModule($moduleName)
Includes a module by its name.

◆ isIgnoreErrors()

static isIgnoreErrors ( )
static

См. определение в файле sale/lib/internals/catalog/provider.php строка 1662

1663  {
1664  return static::$ignoreErrors;
1665  }

◆ isProviderCallbackFunction()

static isProviderCallbackFunction (   $name)
static
Аргументы
$name
Возвращает
bool

См. определение в файле sale/lib/internals/catalog/provider.php строка 1628

1629  {
1630  return (array_key_exists("IBXSaleProductProvider", class_implements($name)));
1631  }

◆ save()

static save ( Sale\Order  $order,
array  $context = array() 
)
static
Аргументы
Sale\Order$order
array | null$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 1387

1388  {
1389  $result = new Sale\Result();
1390 
1391  $context = static::prepareContext($order, $context);
1392 
1393  $r = static::checkContext($context);
1394  if (!$r->isSuccess())
1395  {
1396  $result->addErrors($r->getErrors());
1397  return $result;
1398  }
1399 
1400  $pool = PoolQuantity::getInstance($order->getInternalId());
1401  /** @var array $poolQuantitiesList */
1402  $poolQuantitiesList = $pool->getQuantities(PoolQuantity::POOL_QUANTITY_TYPE);
1403 
1404  /** @var array $poolReservationList */
1405  $poolReservationList = $pool->getQuantities(PoolQuantity::POOL_RESERVE_TYPE);
1406 
1407  if (empty($poolQuantitiesList) && empty($poolReservationList))
1408  return $result;
1409 
1410  $rulesMap = ShipmentRules::createOrderRuleMap($order, $pool);
1411 
1412  if (empty($rulesMap))
1413  {
1414  return $result;
1415  }
1416 
1417  $r = ShipmentRules::saveRules($rulesMap, $context);
1418  if (!$r->isSuccess())
1419  {
1420  $result->addErrors($r->getErrors());
1421  }
1422 
1423  if ($r->hasWarnings())
1424  {
1425  $result->addWarnings($r->getWarnings());
1426  }
1427 
1428  $pool->reset(PoolQuantity::POOL_QUANTITY_TYPE);
1429  $pool->reset(PoolQuantity::POOL_RESERVE_TYPE);
1430 
1431  return $result;
1432  }
static saveRules(array $rules, array $context)
static createOrderRuleMap(Sale\Order $order, PoolQuantity $pool)

◆ setIgnoreErrors()

static setIgnoreErrors (   $value)
static

См. определение в файле sale/lib/internals/catalog/provider.php строка 1653

1654  {
1655  static::$ignoreErrors = ($value === true);
1656  }

◆ tryReserveShipment()

static tryReserveShipment ( Sale\Shipment  $shipment,
array  $context = array() 
)
static
Аргументы
Sale\Shipment$shipment
array$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 317

318  {
319  $result = new Sale\Result();
320 
321  /** @var Sale\ShipmentCollection $shipmentCollection */
322  if (!$shipmentCollection = $shipment->getCollection())
323  {
324  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
325  }
326 
327  /** @var Sale\Order $order */
328  $order = $shipmentCollection->getOrder();
329  if (!$order)
330  {
331  throw new Main\ObjectNotFoundException('Entity "Order" not found');
332  }
333 
334  $context = static::prepareContext($order, $context);
335  $r = static::checkContext($context);
336  if (!$r->isSuccess())
337  {
338  return $r;
339  }
340 
341  $pool = PoolQuantity::getInstance($order->getInternalId());
342 
343  /** @var Sale\ShipmentItemCollection $shipmentCollection */
344  $shipmentItemCollection = $shipment->getShipmentItemCollection();
345 
346  $availableQuantityList = array();
347  $needQuantityList = array();
348 
349  /** @var Sale\Result $r */
350  $r = static::getNeedQuantityByShipmentItemCollection($shipmentItemCollection);
351  if (!$r->isSuccess())
352  {
353  $result->addErrors($r->getErrors());
354  }
355  else
356  {
357  $data = $r->getData();
358  if (!empty($data['NEED_QUANTITY_LIST']))
359  {
360  $needQuantityList = $data['NEED_QUANTITY_LIST'];
361  }
362  }
363 
364  if ($r->hasWarnings())
365  {
366  $result->addWarnings($r->getWarnings());
367  }
368 
369  if ($shipmentItemCollection->count() == 0)
370  {
371  return $result;
372  }
373 
374  $creator = Sale\Internals\ProviderCreator::create($context);
375  /** @var Sale\ShipmentItem $shipmentItem */
376  foreach ($shipmentItemCollection as $shipmentItem)
377  {
378  $shipmentProductData = $creator->createItemForReserve($shipmentItem);
379  $creator->addShipmentProductData($shipmentProductData);
380  }
381 
382  $r = $creator->getAvailableQuantity();
383  if ($r->isSuccess())
384  {
385  $data = $r->getData();
386  if (array_key_exists('AVAILABLE_QUANTITY_LIST', $data))
387  {
388  $availableQuantityList = $data['AVAILABLE_QUANTITY_LIST'] + $availableQuantityList;
389  }
390  }
391  else
392  {
393  $result->addErrors($r->getErrors());
394  }
395 
396  if ($r->hasWarnings())
397  {
398  $result->addWarnings($r->getWarnings());
399  }
400 
401  if (!empty($needQuantityList) && $result->isSuccess())
402  {
403  $applyItemsList = array();
404 
405  foreach ($availableQuantityList as $providerName => $productAvailableQuantityList)
406  {
407  $providerName = trim($providerName);
408  foreach ($productAvailableQuantityList as $productId => $productAvailableQuantity)
409  {
410  if (array_key_exists($productId, $needQuantityList[$providerName]))
411  {
413  {
414  $poolQuantity = 0;
415  if ($order->getId() > 0)
416  {
417  $poolQuantity = (float)$pool->get(PoolQuantity::POOL_RESERVE_TYPE, $productId);
418  }
419  $needQuantity = $needQuantityList[$providerName][$productId];
420 
421  $productAvailableQuantity -= $poolQuantity;
422  $reservedQuantity = ($needQuantity >= $productAvailableQuantity ? $productAvailableQuantity : $needQuantity);
423 
424  $applyItemsList[$providerName][$productId] = $reservedQuantity;
425  }
426  }
427  else
428  {
429  /** @var Sale\ShipmentItem $shipmentItem */
430  foreach ($shipmentItemCollection as $shipmentItem)
431  {
432  $basketItem = $shipmentItem->getBasketItem();
433 
434  if ($basketItem->getProductId() == $productId)
435  {
436  $result->addWarning( new Sale\ResultWarning(Main\Localization\Loc::getMessage('SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY', array(
437  '#PRODUCT_NAME#' => $basketItem->getField('NAME')
438  )), 'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY') );
439  break;
440  }
441  }
442  }
443  }
444 
445  }
446 
447  if (!empty($applyItemsList))
448  {
449  $shipmentProductIndex = static::createProductShipmentItemMapByShipmentItemCollection($shipmentItemCollection);
450 
451  /** @var Sale\Shipment $shipment */
452  if (!$shipment = $shipmentItemCollection->getShipment())
453  {
454  throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollectionCollection" not found');
455  }
456 
457  /** @var Sale\ShipmentCollection $shipmentCollection */
458  if (!$shipmentCollection = $shipment->getCollection())
459  {
460  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
461  }
462 
463  /** @var Sale\Order $order */
464  if (!$order = $shipmentCollection->getOrder())
465  {
466  throw new Main\ObjectNotFoundException('Entity "Order" not found');
467  }
468 
469  $pool = PoolQuantity::getInstance($order->getInternalId());
470 
471  static::setAvailableQuantityToShipmentItemCollection($pool, $shipmentProductIndex, $applyItemsList);
472  }
473  }
474 
475  return $result;
476  }
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
static getProductReservationCondition()
Returns current reservation condition.

◆ tryReserveShipmentItem()

static tryReserveShipmentItem ( Sale\ShipmentItem  $shipmentItem,
array  $context = array() 
)
static
Аргументы
Sale\ShipmentItem$shipmentItem
array$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 489

490  {
491  $result = new Sale\Result();
492 
493  /** @var Sale\ShipmentItemCollection $shipmentItemCollection */
494  $shipmentItemCollection = $shipmentItem->getCollection();
495  if (!$shipmentItemCollection)
496  {
497  throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
498  }
499 
500  /** @var Sale\Shipment $shipment */
501  $shipment = $shipmentItemCollection->getShipment();
502  if (!$shipment)
503  {
504  throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
505  }
506 
507  /** @var Sale\ShipmentCollection $shipmentCollection */
508  $shipmentCollection = $shipment->getCollection();
509  if (!$shipmentCollection)
510  {
511  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
512  }
513 
514  /** @var Sale\Order $order */
515  $order = $shipmentCollection->getOrder();
516  if (!$order)
517  {
518  throw new Main\ObjectNotFoundException('Entity "Order" not found');
519  }
520 
521  $context = static::prepareContext($order, $context);
522  $r = static::checkContext($context);
523  if (!$r->isSuccess())
524  {
525  return $r;
526  }
527 
528  $pool = PoolQuantity::getInstance($order->getInternalId());
529 
530  /** @var Sale\ShipmentItemCollection $shipmentCollection */
531  $shipmentItemCollection = $shipment->getShipmentItemCollection();
532 
533  $availableQuantityList = [];
534  $needQuantityList = [];
535 
536  $r = static::getNeedQuantityByShipmentItem($shipmentItem);
537  if (!$r->isSuccess())
538  {
539  $result->addErrors($r->getErrors());
540  }
541  else
542  {
543  $data = $r->getData();
544  if (!empty($data['NEED_QUANTITY_LIST']))
545  {
546  $needQuantityList = $data['NEED_QUANTITY_LIST'];
547  }
548  }
549 
550  $creator = Sale\Internals\ProviderCreator::create($context);
551 
552  $shipmentProductData = $creator->createItemForReserve($shipmentItem);
553  $creator->addShipmentProductData($shipmentProductData);
554 
555  $r = $creator->getAvailableQuantity();
556  if ($r->isSuccess())
557  {
558  $data = $r->getData();
559  if (array_key_exists('AVAILABLE_QUANTITY_LIST', $data))
560  {
561  $availableQuantityList = $data['AVAILABLE_QUANTITY_LIST'];
562  }
563  }
564  else
565  {
566  $result->addErrors($r->getErrors());
567  }
568 
569  if ($r->hasWarnings())
570  {
571  $result->addWarnings($r->getWarnings());
572  }
573 
574  if (!empty($needQuantityList) && $result->isSuccess())
575  {
576  $applyItemsList = [];
577 
578  foreach ($availableQuantityList as $providerName => $productAvailableQuantityList)
579  {
580  $providerName = trim($providerName);
581  foreach ($productAvailableQuantityList as $productId => $productAvailableQuantity)
582  {
583  if (array_key_exists($productId, $needQuantityList[$providerName]))
584  {
586  {
587  $poolQuantity = 0;
588  if ($order->getId() > 0)
589  {
590  $poolQuantity = (float)$pool->get(PoolQuantity::POOL_RESERVE_TYPE, $productId);
591  }
592  $needQuantity = $needQuantityList[$providerName][$productId];
593 
594  $productAvailableQuantity -= $poolQuantity;
595  $reservedQuantity = ($needQuantity >= $productAvailableQuantity ? $productAvailableQuantity : $needQuantity);
596 
597  $applyItemsList[$providerName][$productId] = $reservedQuantity;
598  }
599  }
600  else
601  {
602  /** @var Sale\ShipmentItem $shipmentItem */
603  $basketItem = $shipmentItem->getBasketItem();
604 
605  if ($basketItem->getProductId() == $productId)
606  {
607  $result->addWarning( new Sale\ResultWarning(Main\Localization\Loc::getMessage('SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY', array(
608  '#PRODUCT_NAME#' => $basketItem->getField('NAME')
609  )), 'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY') );
610  break;
611  }
612  }
613  }
614 
615  }
616 
617  if (!empty($applyItemsList))
618  {
619  $shipmentProductIndex = static::createProductShipmentItemMapByShipmentItem($shipmentItem);
620 
621  /** @var Sale\Shipment $shipment */
622  if (!$shipment = $shipmentItemCollection->getShipment())
623  {
624  throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollectionCollection" not found');
625  }
626 
627  /** @var Sale\ShipmentCollection $shipmentCollection */
628  if (!$shipmentCollection = $shipment->getCollection())
629  {
630  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
631  }
632 
633  /** @var Sale\Order $order */
634  if (!$order = $shipmentCollection->getOrder())
635  {
636  throw new Main\ObjectNotFoundException('Entity "Order" not found');
637  }
638 
639  $pool = PoolQuantity::getInstance($order->getInternalId());
640  static::setAvailableQuantityToShipmentItemCollection($pool, $shipmentProductIndex, $applyItemsList);
641  }
642  }
643 
644  return $result;
645  }

◆ tryShipShipment()

static tryShipShipment ( Sale\Shipment  $shipment,
array  $context = array() 
)
static
Аргументы
Sale\Shipment$shipment
array$context
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 1060

1061  {
1062  $result = new Sale\Result();
1063 
1064  $context = static::prepareContextByShipment($shipment, $context);
1065 
1066  /** @var Sale\ShipmentCollection $shipmentCollection */
1067  $shipmentCollection = $shipment->getCollection();
1068  if (!$shipmentCollection)
1069  {
1070  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
1071  }
1072 
1073  $order = $shipmentCollection->getOrder();
1074  if (!$order)
1075  {
1076  throw new Main\ObjectNotFoundException('Entity "Order" not found');
1077  }
1078 
1079  $pool = PoolQuantity::getInstance($order->getInternalId());
1080 
1081  /** @var Sale\ShipmentItemCollection $shipmentCollection */
1082  $shipmentItemCollection = $shipment->getShipmentItemCollection();
1083 
1084  $needShipList = array();
1085  $creator = Sale\Internals\ProviderCreator::create($context);
1086  /** @var Sale\ShipmentItem $shipmentItem */
1087  foreach ($shipmentItemCollection as $shipmentItem)
1088  {
1089  $creator->addShipmentItem($shipmentItem);
1090  }
1091 
1092  $r = $creator->isNeedShip();
1093  if ($r->isSuccess())
1094  {
1095  $data = $r->getData();
1096  if (array_key_exists('IS_NEED_SHIP', $data))
1097  {
1098  $needShipList = $data['IS_NEED_SHIP'] + $needShipList;
1099  }
1100  }
1101 
1102  $creator = Sale\Internals\ProviderCreator::create($context);
1103  /** @var Sale\ShipmentItem $shipmentItem */
1104  foreach ($shipmentItemCollection as $shipmentItem)
1105  {
1106  $shipmentProductData = $creator->createItemForShip($shipmentItem, $needShipList);
1107  $creator->addShipmentProductData($shipmentProductData);
1108  }
1109 
1110  $tryShipProductList = array();
1111 
1112  $isIgnoreErrors = false;
1113 
1114  $r = $creator->tryShip();
1115 
1116  $needSetAfterResult = false;
1117  if ($r->isSuccess())
1118  {
1119  if ($r->hasWarnings())
1120  {
1121  $result->addWarnings($r->getWarnings());
1122  }
1123  else
1124  {
1125  $needSetAfterResult = true;
1126  }
1127  }
1128  else
1129  {
1130  $result->addWarnings($r->getErrors());
1131 
1132  if (static::isIgnoreErrors())
1133  {
1134  $isIgnoreErrors = true;
1135  $needSetAfterResult = true;
1136  }
1137  else
1138  {
1139  $result->addErrors($r->getErrors());
1140  }
1141 
1142  }
1143 
1144  $data = $r->getData();
1145  if (array_key_exists('TRY_SHIP_PRODUCTS_LIST', $data))
1146  {
1147  $tryShipProductList = $data['TRY_SHIP_PRODUCTS_LIST'] + $tryShipProductList;
1148  }
1149 
1150  if ($needSetAfterResult && !empty($tryShipProductList))
1151  {
1152 
1153  if ($isIgnoreErrors)
1154  {
1155  foreach ($tryShipProductList as $providerName => &$productList)
1156  {
1157  $productList = array_fill_keys(array_keys($productList), true);
1158  }
1159  }
1160 
1161  $creator->setItemsResultAfterTryShip($pool, $tryShipProductList);
1162  }
1163 
1164  return $result;
1165  }

◆ tryUnreserveShipment()

static tryUnreserveShipment ( Sale\Shipment  $shipment)
static
Аргументы
Sale\Shipment$shipment
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 825

826  {
827  $result = new Sale\Result();
828 
829  /** @var Sale\ShipmentCollection $shipmentCollection */
830  if (!$shipmentCollection = $shipment->getCollection())
831  {
832  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
833  }
834 
835  /** @var Sale\Order $order */
836  if (!$order = $shipmentCollection->getOrder())
837  {
838  throw new Main\ObjectNotFoundException('Entity "Order" not found');
839  }
840 
841  $pool = PoolQuantity::getInstance($order->getInternalId());
842 
843  /** @var Sale\ShipmentItemCollection $shipmentCollection */
844  $shipmentItemCollection = $shipment->getShipmentItemCollection();
845 
846  /** @var Sale\ShipmentItem $shipmentItem */
847  foreach ($shipmentItemCollection as $shipmentItem)
848  {
849  /** @var Sale\BasketItem $basketItem */
850  if (!$basketItem = $shipmentItem->getBasketItem())
851  {
852  continue;
853  }
854 
855  $productId = $basketItem->getProductId();
856 
857  $reservedQuantity = $shipmentItem->getReservedQuantity();
858 
859  if ($reservedQuantity == 0)
860  continue;
861 
862  $pool->add(Sale\Internals\PoolQuantity::POOL_RESERVE_TYPE, $productId, -1 * $reservedQuantity);
863  if ($shipmentItem)
864  {
865  $foundItem = false;
866  $poolItems = Sale\Internals\ItemsPool::get($order->getInternalId(), $productId);
867  if (!empty($poolItems))
868  {
869  /** @var Sale\Shipment $poolItem */
870  foreach ($poolItems as $poolItem)
871  {
872  if ($poolItem->getInternalIndex() == $shipmentItem->getInternalIndex())
873  {
874  $foundItem = true;
875  break;
876  }
877  }
878  }
879 
880  if (!$foundItem)
881  {
882  Sale\Internals\ItemsPool::add($order->getInternalId(), $productId, $shipmentItem);
883  }
884  }
885 
886  $r = $shipmentItem->setField('RESERVED_QUANTITY', $shipmentItem->getReservedQuantity() + -1 * $reservedQuantity);
887  if (!$r->isSuccess())
888  {
889  $result->addErrors($r->getErrors());
890  }
891 
892  }
893 
894  return $result;
895  }
static add($code, $type, $value)
Definition: poolbase.php:51
static get($code, $type)
Definition: poolbase.php:19

◆ tryUnreserveShipmentItem()

static tryUnreserveShipmentItem ( Sale\ShipmentItem  $shipmentItem)
static
Аргументы
Sale\ShipmentItem$shipmentItem
Возвращает
Sale\Result
Исключения
Main

См. определение в файле sale/lib/internals/catalog/provider.php строка 656

657  {
658  $result = new Sale\Result();
659 
660  /** @var Sale\ShipmentItemCollection $shipmentItemCollection */
661  $shipmentItemCollection = $shipmentItem->getCollection();
662  if (!$shipmentItemCollection)
663  {
664  throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
665  }
666 
667  /** @var Sale\Shipment $shipment */
668  $shipment = $shipmentItemCollection->getShipment();
669  if (!$shipment)
670  {
671  throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
672  }
673 
674  /** @var Sale\ShipmentCollection $shipmentCollection */
675  $shipmentCollection = $shipment->getCollection();
676  if (!$shipmentCollection)
677  {
678  throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
679  }
680 
681  /** @var Sale\Order $order */
682  $order = $shipmentCollection->getOrder();
683  if (!$order)
684  {
685  throw new Main\ObjectNotFoundException('Entity "Order" not found');
686  }
687 
688  $pool = PoolQuantity::getInstance($order->getInternalId());
689 
690  /** @var Sale\BasketItem $basketItem */
691  $basketItem = $shipmentItem->getBasketItem();
692  if (!$basketItem)
693  {
694  throw new Main\ObjectNotFoundException('Entity "BasketItem" not found');
695  }
696 
697  $productId = $basketItem->getProductId();
698 
699  $reservedQuantity = $shipmentItem->getReservedQuantity();
700 
701  if ($reservedQuantity == 0)
702  {
703  return $result;
704  }
705 
706  $pool->add(Sale\Internals\PoolQuantity::POOL_RESERVE_TYPE, $productId, -1 * $reservedQuantity);
707  if ($shipmentItem)
708  {
709  $foundItem = false;
710  $poolItems = Sale\Internals\ItemsPool::get($order->getInternalId(), $productId);
711  if (!empty($poolItems))
712  {
713  /** @var Sale\Shipment $poolItem */
714  foreach ($poolItems as $poolItem)
715  {
716  if ($poolItem->getInternalIndex() == $shipmentItem->getInternalIndex())
717  {
718  $foundItem = true;
719  break;
720  }
721  }
722  }
723 
724  if (!$foundItem)
725  {
726  Sale\Internals\ItemsPool::add($order->getInternalId(), $productId, $shipmentItem);
727  }
728  }
729 
730  $r = $shipmentItem->setField('RESERVED_QUANTITY', $shipmentItem->getReservedQuantity() + -1 * $reservedQuantity);
731  if (!$r->isSuccess())
732  {
733  $result->addErrors($r->getErrors());
734  }
735 
736  return $result;
737  }

Поля

◆ SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_EMPTY

const SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_EMPTY = null

См. определение в файле sale/lib/internals/catalog/provider.php строка 22

◆ SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP

const SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP = false

См. определение в файле sale/lib/internals/catalog/provider.php строка 21

◆ SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_SHIP

const SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_SHIP = true

См. определение в файле sale/lib/internals/catalog/provider.php строка 20


Объявления и описания членов класса находятся в файле: