1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
tradebindingentity.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale;
4
5use Bitrix\Main;
6use Bitrix\Sale\TradingPlatform;
7
13{
14 private $tradePlatform = null;
15
19 public static function getRegistryEntity()
20 {
22 }
23
27 public static function getRegistryType()
28 {
30 }
31
35 public static function getAvailableFields()
36 {
37 return [
38 'ORDER_ID', 'EXTERNAL_ORDER_ID',
39 'TRADING_PLATFORM_ID', 'PARAMS', 'XML_ID'
40 ];
41 }
42
46 protected static function getMeaningfulFields()
47 {
48 return array();
49 }
50
54 protected static function getFieldsMap()
55 {
57 }
58
66 public static function create(TradeBindingCollection $collection, TradingPlatform\Platform $platform = null)
67 {
69 $entity = static::createEntityObject();
70
71 $entity->setCollection($collection);
72
73 if ($platform !== null)
74 {
75 $entity->setFieldNoDemand('TRADING_PLATFORM_ID', $platform->getId());
76 $entity->tradePlatform = $platform;
77 }
78
79 $entity->setFieldNoDemand('XML_ID', static::generateXmlId());
80
81 return $entity;
82 }
83
87 protected static function generateXmlId()
88 {
89 return uniqid('bx_');
90 }
91
98 private static function createEntityObject(array $fields = array())
99 {
100 $registry = Registry::getInstance(static::getRegistryType());
101 $entityClassName = $registry->get(Registry::ENTITY_TRADE_BINDING_ENTITY);
102
103 return new $entityClassName($fields);
104 }
105
114 public static function loadForOrder($id)
115 {
116 if (intval($id) <= 0)
117 {
118 throw new Main\ArgumentNullException("id");
119 }
120
121 $registry = Registry::getInstance(static::getRegistryType());
122
124 $tradeBindingCollection = $registry->get(Registry::ENTITY_TRADE_BINDING_COLLECTION);
125 $dbRes = $tradeBindingCollection::getList([
126 'filter' => ['ORDER_ID' => $id]
127 ]);
128
129 $entityList = [];
130 while ($data = $dbRes->fetch())
131 {
132 $entityList[] = static::createEntityObject($data);
133 }
134
135 return $entityList;
136 }
137
142 public function save()
143 {
144 $result = new Result();
145
146 if (!$this->isChanged())
147 {
148 return $result;
149 }
150
151 $id = $this->getId();
152
153 if ($id > 0)
154 {
155 $fields = $this->getFields()->getChangedValues();
156 $r = $this->updateInternal($id, $fields);
157 $result->setId($r->getId());
158 }
159 else
160 {
162 $collection = $this->getCollection();
163
165 $order = $collection->getOrder();
166
167 $this->setFieldNoDemand('ORDER_ID', $order->getId());
168
169 if ((int)$this->getField('EXTERNAL_ORDER_ID') <= 0)
170 {
171 $this->setFieldNoDemand('EXTERNAL_ORDER_ID', $order->getId());
172 }
173
174 $fields = $this->getFields()->getValues();
175 $r = $this->addInternal($fields);
176 if ($r->isSuccess())
177 {
178 $id = $r->getId();
179 $this->setFieldNoDemand('ID', $id);
180 }
181 }
182
183 if (!$r->isSuccess())
184 {
185 $result->addErrors($r->getErrors());
186 return $result;
187 }
188
189 $result->setId($id);
190
191 return $result;
192 }
193
201 public function getTradePlatform()
202 {
203 $tradingPlatformId = (int)$this->getField('TRADING_PLATFORM_ID');
204 if (($this->tradePlatform === null) && $tradingPlatformId > 0)
205 {
206 $this->tradePlatform = TradingPlatform\Manager::getObjectById($tradingPlatformId);
207 }
208
209 return $this->tradePlatform;
210 }
211
218 protected function updateInternal($primary, array $data)
219 {
220 return TradingPlatform\OrderTable::update($primary, $data);
221 }
222
228 protected function addInternal(array $data)
229 {
230 return TradingPlatform\OrderTable::add($data);
231 }
232
238 public static function getEntityEventName()
239 {
240 return 'SaleTradeBindingEntity';
241 }
242
249 public function setFieldNoDemand($name, $value)
250 {
251 parent::setFieldNoDemand($name, $value);
252
253 if ($name === 'TRADING_PLATFORM_ID')
254 {
255 $this->tradePlatform = null;
256 }
257 }
258
259 protected function onFieldModify($name, $oldValue, $value)
260 {
261 $result = parent::onFieldModify($name, $oldValue, $value);
262 if (!$result->isSuccess())
263 {
264 return $result;
265 }
266
267 if ($name === 'TRADING_PLATFORM_ID')
268 {
269 $this->tradePlatform = null;
270 }
271
272 return $result;
273 }
274}
const ENTITY_TRADE_BINDING_COLLECTION
Определения registry.php:55
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
const ENTITY_TRADE_BINDING_ENTITY
Определения registry.php:56
onFieldModify($name, $oldValue, $value)
Определения tradebindingentity.php:259
static getRegistryEntity()
Определения tradebindingentity.php:19
updateInternal($primary, array $data)
Определения tradebindingentity.php:218
static getMeaningfulFields()
Определения tradebindingentity.php:46
static getEntityEventName()
Определения tradebindingentity.php:238
static getAvailableFields()
Определения tradebindingentity.php:35
addInternal(array $data)
Определения tradebindingentity.php:228
setFieldNoDemand($name, $value)
Определения tradebindingentity.php:249
static getObjectById(int $id)
Определения manager.php:30
static getMap()
Определения order.php:49
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$entity
$name
Определения menu_edit.php:35
$platform
Определения settings.php:7
$order
Определения payment.php:8
$dbRes
Определения yandex_detail.php:168
$fields
Определения yandex_run.php:501