Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
decreasestorequantityaction.php
1<?php
2
4
16
18 Application::getDocumentRoot() .'/bitrix/modules/catalog/general/store_docs_type.php'
19);
20
25{
27
28 private string $docType;
29
36 public function __construct(int $storeId, int $productId, float $amount, string $docType)
37 {
38 $this->storeId = $storeId;
39 $this->productId = $productId;
40 $this->amount = $amount;
41 $this->docType = $docType;
42 }
43
47 public function canExecute(): Result
48 {
49 $result = new Result();
50
52 if ($amount < 0)
53 {
54 $can = false;
55
56 $product = ProductTable::getRowById($this->productId);
58 {
59 $can = AccessController::getCurrent()->check(
60 ActionDictionary::ACTION_STORE_DOCUMENT_ALLOW_NEGATION_PRODUCT_QUANTITY,
61 StoreDocument::createFromArray([
62 'DOC_TYPE' => $this->docType,
63 ])
64 );
65 }
67 {
68 $can = $product['CAN_BUY_ZERO'] === 'Y';
69 }
70
71 if (!$can)
72 {
73 $message = Loc::getMessage("CATALOG_STORE_DOCS_ERR_INSUFFICIENTLY_AMOUNT_EXT", [
74 "#STORE#" => $this->getStoreName(),
75 "#PRODUCT#" => $this->getProductName(),
76 ]);
77 $result->addError(new Error($message));
78 }
79 }
80
81 return $result;
82 }
83
87 protected function getProductAmountNew(): float
88 {
89 return $this->getStoreProductAmount() - $this->amount;
90 }
91
95 protected function getStoreProductRow(): array
96 {
97 $row = null;
98
99 $storeId = $this->getStoreId();
100 $productId = $this->getProductId();
101 if (isset($storeId, $productId))
102 {
103 // load without cache to maintain the actual state.
105 'select' => [
106 'AMOUNT',
107 'QUANTITY_RESERVED',
108 ],
109 'filter' => [
110 '=PRODUCT_ID' => $productId,
111 '=STORE_ID' => $storeId,
112 ],
113 ]);
114 }
115
116 return $row ?? [];
117 }
118}
__construct(int $storeId, int $productId, float $amount, string $docType)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getRow(array $parameters)