Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
addstorebarcodeaction.php
1<?php
2
4
6use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
12use CCatalogStoreBarCode;
13
15 Application::getDocumentRoot() .'/bitrix/modules/catalog/general/store_docs_type.php'
16);
17
22{
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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29