Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
barcode.php
1<?php
2
4
8
9Loc::loadMessages(__FILE__);
10
12{
13 const PERMISSION_READ = 'D';
14
15 public function isBarcodeExistAction(string $barcode, int $basketId, int $orderId, int $storeId)
16 {
17 if(!\Bitrix\Main\Loader::includeModule("sale"))
18 {
19 throw new \Bitrix\Main\SystemException('Module Sale has not installed');
20 }
21
22 if(!$this->checkPermission(self::PERMISSION_READ))
23 {
24 $this->addError(new Error(Loc::getMessage('SALE_CONTROLLER_BARCODE_ACCESS_DENIED')));
25 return false;
26 }
27
28 if($barcode == '')
29 {
30 return false;
31 }
32
33 if((int)$basketId <= 0)
34 {
35 $this->addError(new Error(Loc::getMessage('SALE_CONTROLLER_BARCODE_ERROR_BASKET_ID')));
36 return false;
37 }
38
39 if((int)$orderId <= 0)
40 {
41 $this->addError(new Error(Loc::getMessage('SALE_CONTROLLER_BARCODE_ERROR_ORDER_ID')));
42 return false;
43 }
44
45 $basketItem = null;
46 $result = false;
47
48 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
50 $orderClass = $registry->getOrderClassName();
51
52 $order = $orderClass::load($orderId);
53
54 if ($order)
55 {
56 $basket = $order->getBasket();
57
58 if ($basket)
59 {
60 $basketItem = $basket->getItemById($basketId);
61 }
62 }
63
64 if ($basketItem)
65 {
66 $result = \Bitrix\Sale\Provider::checkProductBarcode(
67 $basketItem,
68 [
69 'BARCODE' => $barcode,
70 'STORE_ID' => $storeId
71 ]);
72 }
73
74 return ['RESULT' => $result];
75 }
76
77 protected function checkPermission($permissionType)
78 {
79 $result = self::getApplication()->GetGroupRight("sale") >= $permissionType;
80
81 if(!$result)
82 {
83 $this->addError(new Error('Access denied'));
84 }
85
86 return $result;
87 }
88
89 protected static function getApplication()
90 {
92 global $APPLICATION;
93
94 return $APPLICATION;
95 }
96}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
checkPermission($permissionType)
Definition barcode.php:77