1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basestorequantityaction.php
См. документацию.
1<?php
2
4
5use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
13use CCatalogStoreProduct;
14
15Loc::loadMessages(
16 Application::getDocumentRoot() .'/bitrix/modules/catalog/general/store_docs_type.php'
17);
18
23{
24 use ProductAndStoreInfo;
25
29 protected $storeId;
30
34 protected $productId;
35
39 protected $amount;
40
46 public function __construct(int $storeId, int $productId, float $amount)
47 {
48 $this->storeId = $storeId;
49 $this->productId = $productId;
50 $this->amount = $amount;
51 }
52
58 protected function updateProductQuantity(): bool
59 {
61 'select' => [
62 'SUM_AMOUNT',
63 ],
64 'filter' => [
65 '=STORE.ACTIVE' => 'Y',
66 '=PRODUCT_ID' => $this->productId,
67 ],
68 'runtime' => [
69 new ExpressionField('SUM_AMOUNT', 'SUM(%s)', 'AMOUNT'),
70 ],
71 'group' => [
72 'PRODUCT_ID',
73 ],
74 ]);
75 if (!$row)
76 {
77 return false;
78 }
79
80 $productService = new ProductInternalService(true);
81
82 $res = $productService->update($this->productId, [
83 'QUANTITY' => (float)$row['SUM_AMOUNT'] - $this->getProductTotalReservedQuantity()
84 ]);
85
86 return $res->isSuccess();
87 }
88
94 abstract protected function getProductAmountNew(): float;
95
99 public function execute(): Result
100 {
101 $result = new Result();
102
103 $ret = CCatalogStoreProduct::UpdateFromForm([
104 'STORE_ID' => $this->storeId,
105 'PRODUCT_ID' => $this->productId,
106 'AMOUNT' => $this->getProductAmountNew(),
107 ]);
108 if (!$ret)
109 {
110 $result->addError(
111 new Error(Loc::getMessage('CATALOG_STORE_DOCS_ERR_CANT_UPDATE_STORE_PRODUCT'))
112 );
113 }
114
115 if (!$this->updateProductQuantity())
116 {
117 $result->addError(
118 new Error(Loc::getMessage("CATALOG_STORE_DOCS_ERR_PURCHASING_INFO_ERROR"))
119 );
120 }
121
122 return $result;
123 }
124}
Определения error.php:15
static getRow(array $parameters)
Определения datamanager.php:398
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
__construct(int $storeId, int $productId, float $amount)
Определения basestorequantityaction.php:46