Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
basestorequantityaction.php
1
<?php
2
3
namespace
Bitrix\Catalog\Document\Action\Store
;
4
5
use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
6
use
Bitrix\Catalog\StoreProductTable
;
7
use
Bitrix\Main\Application
;
8
use
Bitrix\Main\Error
;
9
use
Bitrix\Main\Localization\Loc
;
10
use
Bitrix\Main\ORM\Fields\ExpressionField
;
11
use
Bitrix\Main\Result
;
12
use CCatalogProduct;
13
use CCatalogStoreProduct;
14
15
Loc::loadMessages
(
16
Application::getDocumentRoot
() .
'/bitrix/modules/catalog/general/store_docs_type.php'
17
);
18
22
trait
BaseStoreQuantityAction
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
{
60
$row =
StoreProductTable::getRow
([
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
}
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\Result
Definition
result.php:16
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Catalog\Document\Action\Store
Definition
basestorequantityaction.php:3
Bitrix\Catalog\Document\Action\Store\execute
execute()
Definition
basestorequantityaction.php:95
Bitrix\Catalog\Document\Action\Store\getProductAmountNew
getProductAmountNew()
Bitrix\Catalog\Document\Action\Store\__construct
__construct(int $storeId, int $productId, float $amount)
Definition
basestorequantityaction.php:46
Bitrix\Catalog\Document\Action\Store\updateProductQuantity
updateProductQuantity()
Definition
basestorequantityaction.php:58
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\getProductTotalReservedQuantity
getProductTotalReservedQuantity()
Definition
productandstoreinfo.php:211
modules
catalog
lib
document
action
store
basestorequantityaction.php
Создано системой
1.10.0