Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basereservestoreproductaction.php
1<?php
2
4
5use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
10use CCatalogProduct;
11use CCatalogStoreProduct;
12
14 Application::getDocumentRoot() .'/bitrix/modules/catalog/general/store_docs_type.php'
15);
16
21{
22 use ProductAndStoreInfo;
23
27 protected $storeId;
28
32 protected $productId;
33
37 protected $amount;
38
44 public function __construct(int $storeId, int $productId, float $amount)
45 {
46 $this->storeId = $storeId;
47 $this->productId = $productId;
48 $this->amount = $amount;
49 }
50
56 abstract protected function getNewProductQuantity(): float;
57
63 abstract protected function getNewProductReservedQuantity(): float;
64
70 abstract protected function getNewStoreReservedQuantity(): float;
71
75 public function execute(): Result
76 {
77 $result = new Result();
78
79 // update store info
80 $ret = CCatalogStoreProduct::UpdateFromForm([
81 'PRODUCT_ID' => $this->productId,
82 'STORE_ID' => $this->storeId,
83 'AMOUNT' => $this->getStoreProductAmount(),
84 'QUANTITY_RESERVED' => $this->getNewStoreReservedQuantity(),
85 ]);
86 if (!$ret)
87 {
88 $result->addError(
89 new Error(Loc::getMessage("CATALOG_STORE_DOCS_ERR_CANT_UPDATE_STORE_PRODUCT"))
90 );
91 return $result;
92 }
93
94 // update product info
95 $ret = CCatalogProduct::Update($this->productId, [
96 'QUANTITY' => $this->getNewProductQuantity(),
97 'QUANTITY_RESERVED' => $this->getNewProductReservedQuantity(),
98 ]);
99 if (!$ret)
100 {
101 $result->addError(
102 new Error(Loc::getMessage("CATALOG_STORE_DOCS_ERR_PURCHASING_INFO_ERROR"))
103 );
104 return $result;
105 }
106
107 return $result;
108 }
109}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct(int $storeId, int $productId, float $amount)