Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bytradebinding.php
1<?php
3
7
8Loc::loadMessages(__FILE__);
9
14class ByTradeBinding extends Base
15{
19 public static function getClassTitle()
20 {
21 return Loc::getMessage('SALE_SRV_RSTR_BY_TRADE_BINDING_NAME');
22 }
23
27 public static function getClassDescription()
28 {
29 return Loc::getMessage('SALE_SRV_RSTR_BY_TRADE_BINDING_DESC');
30 }
31
41 public static function getParamsStructure($entityId = 0)
42 {
43 $result = array(
44 "TRADE_BINDING" => array(
45 "TYPE" => "ENUM",
46 'MULTIPLE' => 'Y',
47 "LABEL" => Loc::getMessage("SALE_SRV_RSTR_BY_TRADE_BINDING_LIST"),
48 "OPTIONS" => self::getTradePlatformList()
49 )
50 );
51
52 return $result;
53 }
54
61 protected static function getTradePlatformList()
62 {
63 $result = [];
64
65 $dbRes = Sale\TradingPlatformTable::getList(['select' => ['CODE', 'CLASS']]);
66 while ($data = $dbRes->fetch())
67 {
69 $platformClassName = $data['CLASS'];
70
71 if (!empty($platformClassName) && class_exists($platformClassName))
72 {
73 $platform = $platformClassName::getInstanceByCode($data['CODE']);
74 if ($platform
75 && $platform instanceof Sale\TradingPlatform\Landing\Landing
76 )
77 {
78 $result[$platform->getId()] = $platform->getRealName();
79 }
80 }
81 }
82
83 return $result;
84 }
85
95 protected static function extractParams(Sale\Internals\Entity $entity)
96 {
97 $result = [];
98
99 $order = static::getOrder($entity);
100
101 if ($order === null)
102 {
103 return $result;
104 }
105
106 $collection = $order->getTradeBindingCollection();
107
109 foreach ($collection as $entity)
110 {
111 $tradeBinding = $entity->getTradePlatform();
112 if (
113 $tradeBinding
114 && !in_array($tradeBinding->getId(), $result)
115 )
116 {
117 $result[] = $tradeBinding->getId();
118 }
119 }
120
121 return $result;
122 }
123
128 protected static function getOrder(Sale\Internals\Entity $entity)
129 {
130 if ($entity instanceof Sale\Shipment)
131 {
133 $collection = $entity->getCollection();
134
136 return $collection->getOrder();
137 }
138 elseif ($entity instanceof Sale\Order)
139 {
141 return $entity;
142 }
143
144 return null;
145 }
146
153 public static function check($params, array $restrictionParams, $serviceId = 0)
154 {
155 if (is_array($restrictionParams) && isset($restrictionParams['TRADE_BINDING']))
156 {
157 $diff = array_diff($params, $restrictionParams['TRADE_BINDING']);
158 return empty($diff);
159 }
160
161 return true;
162 }
163
172 public static function isAvailable()
173 {
174 return count(static::getTradePlatformList()) > 0;
175 }
176
177}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static check($params, array $restrictionParams, $serviceId=0)