14 private const RECORD_LIMIT = 100;
18 public function execute(array &$result)
20 $processedRecords = 0;
24 $orderClass = $registry->getOrderClassName();
26 $days_ago = (int) Option::get(
"sale",
"product_reserve_clear_period");
32 if (!is_object($USER))
40 'ORDER_ID' =>
'ORDER.ID',
46 '<=DATE_RESERVE_END' => $date,
47 '=ORDER.PAYED' =>
'N',
48 '=ORDER.CANCELED' =>
'N',
51 new Main\Entity\ReferenceField(
53 Sale\Internals\BasketTable::class,
55 '=this.BASKET_ID' =>
'ref.ID',
57 [
'join_type' =>
'inner']
59 new Main\Entity\ReferenceField(
61 Sale\Internals\OrderTable::class,
63 '=this.BASKET.ORDER_ID' =>
'ref.ID',
65 [
'join_type' =>
'inner']
68 'limit' => self::RECORD_LIMIT,
72 $res = Sale\ReserveQuantityCollection::getList($parameters);
73 while ($data = $res->fetch())
75 if (!isset($orderList[$data[
'ORDER_ID']]))
77 $orderList[$data[
'ORDER_ID']] = [];
80 if (!isset($orderList[$data[
'ORDER_ID']][$data[
'BASKET_ID']]))
82 $orderList[$data[
'ORDER_ID']][$data[
'BASKET_ID']] = [];
85 $orderList[$data[
'ORDER_ID']][$data[
'BASKET_ID']][] = $data[
'ID'];
88 foreach ($orderList as $orderId => $basketItemIds)
90 $order = $orderClass::load($orderId);
96 $basket = $order->getBasket();
97 foreach ($basketItemIds as $basketItemId => $reserveIds)
100 $basketItem = $basket->getItemById($basketItemId);
106 foreach ($reserveIds as $reserveId)
109 $reserveCollection = $basketItem->getReserveQuantityCollection();
110 if (!$reserveCollection)
115 $reserve = $reserveCollection->getItemById($reserveId);
128 if (!$r->isSuccess())
130 $errorText = (string)$order->getField(
'REASON_MARKED');
131 if ($errorText !==
'')
136 foreach($r->getErrorMessages() as $error)
138 if ((
string)$error !==
'')
140 $errorText .= $error.
"\n";
144 Sale\Internals\OrderTable::update($order->getId(), [
146 "REASON_MARKED" => $errorText
152 if (!is_object($USER) || $USER->GetID() <= 0)
154 ORM\Entity::destroy(
Sale\Internals\OrderTable::getEntity());
158 if ($processedRecords < self::RECORD_LIMIT)