Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
decreasestorequantityaction.php
1
<?php
2
3
namespace
Bitrix\Catalog\Document\Action\Store
;
4
5
use
Bitrix\Catalog\Access\AccessController
;
6
use
Bitrix\Catalog\Access\ActionDictionary
;
7
use
Bitrix\Catalog\Access\Model\StoreDocument
;
8
use
Bitrix\Catalog\Config\Options\CheckRightsOnDecreaseStoreAmount
;
9
use
Bitrix\Catalog\Document\Action
;
10
use
Bitrix\Catalog\ProductTable
;
11
use
Bitrix\Catalog\StoreProductTable
;
12
use
Bitrix\Main\Application
;
13
use
Bitrix\Main\Result
;
14
use
Bitrix\Main\Error
;
15
use
Bitrix\Main\Localization\Loc
;
16
17
Loc::loadMessages
(
18
Application::getDocumentRoot
() .
'/bitrix/modules/catalog/general/store_docs_type.php'
19
);
20
24
class
DecreaseStoreQuantityAction
implements
Action
25
{
26
use
BaseStoreQuantityAction
;
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
51
$amount
= $this->
getProductAmountNew
();
52
if
(
$amount
< 0)
53
{
54
$can =
false
;
55
56
$product =
ProductTable::getRowById
($this->productId);
57
if
(
CheckRightsOnDecreaseStoreAmount::isEnabled
())
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
}
66
elseif (
CheckRightsOnDecreaseStoreAmount::isNotUsed
() && $product)
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.
104
$row =
StoreProductTable::getRow
([
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
}
Bitrix\Catalog\Access\AccessController
Definition
AccessController.php:28
Bitrix\Catalog\Access\ActionDictionary
Definition
ActionDictionary.php:17
Bitrix\Catalog\Access\Model\StoreDocument
Definition
StoreDocument.php:9
Bitrix\Catalog\Config\Options\CheckRightsOnDecreaseStoreAmount
Definition
checkrightsondecreasestoreamount.php:15
Bitrix\Catalog\Config\Options\CheckRightsOnDecreaseStoreAmount\isEnabled
static isEnabled()
Definition
checkrightsondecreasestoreamount.php:38
Bitrix\Catalog\Config\Options\CheckRightsOnDecreaseStoreAmount\isNotUsed
static isNotUsed()
Definition
checkrightsondecreasestoreamount.php:28
Bitrix\Catalog\Document\Action\Store\DecreaseStoreQuantityAction
Definition
decreasestorequantityaction.php:25
Bitrix\Catalog\Document\Action\Store\DecreaseStoreQuantityAction\getProductAmountNew
getProductAmountNew()
Definition
decreasestorequantityaction.php:87
Bitrix\Catalog\Document\Action\Store\DecreaseStoreQuantityAction\__construct
__construct(int $storeId, int $productId, float $amount, string $docType)
Definition
decreasestorequantityaction.php:36
Bitrix\Catalog\Document\Action\Store\DecreaseStoreQuantityAction\canExecute
canExecute()
Definition
decreasestorequantityaction.php:47
Bitrix\Catalog\Document\Action\Store\DecreaseStoreQuantityAction\getStoreProductRow
getStoreProductRow()
Definition
decreasestorequantityaction.php:95
Bitrix\Catalog\ProductTable
Definition
product.php:63
Bitrix\Catalog\StoreProductTable
Definition
storeproduct.php:39
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getDocumentRoot
static getDocumentRoot()
Definition
application.php:717
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Definition
datamanager.php:410
Bitrix\Main\ORM\Data\DataManager\getRowById
static getRowById($id)
Definition
datamanager.php:392
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Catalog\Document\Action
Definition
action.php:11
Bitrix\Catalog\Document\Action\Store
Definition
basestorequantityaction.php:3
Bitrix\Catalog\Document\Action\Store\BaseStoreQuantityAction
trait BaseStoreQuantityAction
Definition
basestorequantityaction.php:23
Bitrix\Catalog\Document\Action\Store\$productId
$productId
Definition
basestorequantityaction.php:34
Bitrix\Catalog\Document\Action\Store\$amount
$amount
Definition
basestorequantityaction.php:39
Bitrix\Catalog\Document\Action\Store\$storeId
$storeId
Definition
basestorequantityaction.php:29
Bitrix\Catalog\Document\Action
Bitrix\Catalog\Document\Action\getStoreId
getStoreId()
Definition
productandstoreinfo.php:31
Bitrix\Catalog\Document\Action\getProductId
getProductId()
Definition
productandstoreinfo.php:41
Bitrix\Catalog\Document\Action\getStoreProductAmount
getStoreProductAmount()
Definition
productandstoreinfo.php:119
Bitrix\Catalog\Document\Action\getProductName
getProductName()
Definition
productandstoreinfo.php:139
Bitrix\Catalog\Document\Action\getStoreName
getStoreName()
Definition
productandstoreinfo.php:51
modules
catalog
lib
document
action
store
decreasestorequantityaction.php
Создано системой
1.10.0