Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
addstorebarcodeaction.php
1
<?php
2
3
namespace
Bitrix\Catalog\Document\Action\Barcode
;
4
5
use
Bitrix\Catalog\Document\Action
;
6
use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
7
use
Bitrix\Catalog\ProductTable
;
8
use
Bitrix\Main\Application
;
9
use
Bitrix\Main\Error
;
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\Result
;
12
use CCatalogStoreBarCode;
13
14
Loc::loadMessages
(
15
Application::getDocumentRoot
() .
'/bitrix/modules/catalog/general/store_docs_type.php'
16
);
17
21
class
AddStoreBarcodeAction
implements
Action
22
{
23
use
ProductAndStoreInfo
;
24
use
BaseStoreBarcodeAction
;
25
29
public
function
canExecute
():
Result
30
{
31
$result =
new
Result
();
32
33
$row = $this->
getBarcodeRow
();
34
if
($row && $this->productId !== (
int
)$row[
'PRODUCT_ID'
])
35
{
36
$message =
Loc::getMessage
(
'CATALOG_STORE_DOCS_ERR_BARCODE_ALREADY_EXIST'
, [
37
'#PRODUCT#'
=> $this->
getProductName
(),
38
'#BARCODE#'
=> $this->barcode,
39
]);
40
$result->addError(
new
Error
($message));
41
}
42
43
return
$result;
44
}
45
51
public
function
execute
():
Result
52
{
53
$result =
new
Result
();
54
55
$row = $this->
getBarcodeRow
();
56
if
($row)
57
{
58
if
($this->storeId === (
int
)$row[
'STORE_ID'
])
59
{
60
// no changes - no action
61
return
$result;
62
}
63
64
$id = CCatalogStoreBarCode::Update($row[
'ID'
], [
65
'STORE_ID'
=> $this->storeId,
66
'MODIFIED_BY'
=> $this->userId,
67
]);
68
}
69
else
70
{
71
$id = CCatalogStoreBarCode::add([
72
'PRODUCT_ID'
=> $this->productId,
73
'STORE_ID'
=> $this->storeId,
74
'BARCODE'
=> $this->barcode,
75
'MODIFIED_BY'
=> $this->userId,
76
'CREATED_BY'
=> $this->userId,
77
]);
78
}
79
80
if
(!$id)
81
{
82
$result->addError(
new
Error
(
'Can\'t save barcode'
));
83
}
84
85
return
$result;
86
}
87
}
Bitrix\Catalog\Document\Action\Barcode\AddStoreBarcodeAction
Definition
addstorebarcodeaction.php:22
Bitrix\Catalog\Document\Action\Barcode\AddStoreBarcodeAction\execute
execute()
Definition
addstorebarcodeaction.php:51
Bitrix\Catalog\Document\Action\Barcode\AddStoreBarcodeAction\canExecute
canExecute()
Definition
addstorebarcodeaction.php:29
Bitrix\Catalog\ProductTable
Definition
product.php:63
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\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Catalog\Document\Action
Definition
action.php:11
Bitrix\Catalog\Document\Action\ProductAndStoreInfo
trait ProductAndStoreInfo
Definition
productandstoreinfo.php:15
Bitrix\Catalog\Document\Action\Barcode
Definition
addstorebarcodeaction.php:3
Bitrix\Catalog\Document\Action\Barcode\getBarcodeRow
getBarcodeRow()
Definition
basestorebarcodeaction.php:56
Bitrix\Catalog\Document\Action\Barcode\BaseStoreBarcodeAction
trait BaseStoreBarcodeAction
Definition
basestorebarcodeaction.php:11
Bitrix\Catalog\Document\Action
Bitrix\Catalog\Document\Action\getProductName
getProductName()
Definition
productandstoreinfo.php:139
modules
catalog
lib
document
action
barcode
addstorebarcodeaction.php
Создано системой
1.10.0