12 private static $basketReserves = [];
21 public static function OnSaleBasketItemSetField(
Event $event):
void
25 if ($name !==
'PRODUCT_ID' || !($basketItem instanceof
BasketItem))
30 $reserveQuantityCollection = $basketItem->getReserveQuantityCollection();
31 if (!isset($reserveQuantityCollection) || $reserveQuantityCollection->isEmpty())
37 foreach ($reserveQuantityCollection as $reserveQuantity)
44 'STORE_ID' => $reserveQuantity->getStoreId(),
45 'QUANTITY' => $reserveQuantity->getQuantity(),
46 'DATE_RESERVE_END' => $reserveQuantity->getField(
'DATE_RESERVE_END'),
48 $result = $reserveQuantity->delete();
50 if (!$result->isSuccess())
52 $reserveQuantity->setFieldNoDemand(
'QUANTITY', 0);
54 Provider::tryReserve($reserveQuantity);
56 $reserveQuantity->deleteNoDemand();
60 self::$basketReserves[$basketItem->getBasketCode()] = $reserves;
74 if ($name !==
'PRODUCT_ID' || !($basketItem instanceof
BasketItem))
79 $reserveQuantityCollection = $basketItem->getReserveQuantityCollection();
80 if (!isset($reserveQuantityCollection))
85 $reserves = self::$basketReserves[$basketItem->getBasketCode()] ??
null;
91 foreach ($reserves as $reserve)
93 $reserveQuantity = $reserveQuantityCollection->create();
94 $result = $reserveQuantity->setFields($reserve);
96 if (!$result->isSuccess())
98 $reserveQuantity->setFieldsNoDemand($reserve);
99 Provider::tryReserve($reserveQuantity);
103 unset(self::$basketReserves[$basketItem->getBasketCode()]);