1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basereservestoreproductaction.php
См. документацию.
1<?php
2
4
5use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
11use CCatalogStoreProduct;
12
13Loc::loadMessages(
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 $productService = new ProductInternalService(true);
95
96 // update product info
97 $ret = $productService->update($this->productId, [
98 'QUANTITY' => $this->getNewProductQuantity(),
99 'QUANTITY_RESERVED' => $this->getNewProductReservedQuantity(),
100 ]);
101 if (!$ret->isSuccess())
102 {
103 $result->addError(
104 new Error(Loc::getMessage("CATALOG_STORE_DOCS_ERR_PURCHASING_INFO_ERROR"))
105 );
106 return $result;
107 }
108
109 return $result;
110 }
111}
Определения error.php:15
$result
Определения get_property_values.php:14
__construct(int $storeId, int $productId, float $amount)