Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basestorequantityaction.php
1<?php
2
4
5use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
12use CCatalogProduct;
13use CCatalogStoreProduct;
14
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 return CCatalogProduct::Update($this->productId, [
81 'QUANTITY' => (float)$row['SUM_AMOUNT'] - $this->getProductTotalReservedQuantity()
82 ]);
83 }
84
90 abstract protected function getProductAmountNew(): float;
91
95 public function execute(): Result
96 {
97 $result = new Result();
98
99 $ret = CCatalogStoreProduct::UpdateFromForm([
100 'STORE_ID' => $this->storeId,
101 'PRODUCT_ID' => $this->productId,
102 'AMOUNT' => $this->getProductAmountNew(),
103 ]);
104 if (!$ret)
105 {
106 $result->addError(
107 new Error(Loc::getMessage('CATALOG_STORE_DOCS_ERR_CANT_UPDATE_STORE_PRODUCT'))
108 );
109 }
110
111 if (!$this->updateProductQuantity())
112 {
113 $result->addError(
114 new Error(Loc::getMessage("CATALOG_STORE_DOCS_ERR_PURCHASING_INFO_ERROR"))
115 );
116 }
117
118 return $result;
119 }
120}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getRow(array $parameters)
__construct(int $storeId, int $productId, float $amount)