Bitrix-D7 22.2
Загрузка...
Поиск...
Не найдено
Класс Product
+ Граф наследования:Product:

Открытые члены

 fetch (Main\Text\Converter $converter=null)
 

Открытые статические члены

static getTabletClassName ()
 
static delete ($id)
 
static getEntity ()
 
static getList (array $parameters)
 
static getRow (array $parameters)
 
static clearCache ()
 
static add (array $data)
 
static update ($id, array $data)
 
static setCacheItem ($id, array $row)
 
static getCacheItem ($id, bool $load=false)
 
static clearCacheItem ($id)
 
static getTabletFieldNames (int $fields=self::FIELDS_MAIN)
 
static getCachedFieldList ()
 
static getCallbackRestEvent ()
 
static clearSettings ()
 

Поля данных

const PREFIX_OLD = 'OLD_'
 
const EVENT_ON_BUILD_CACHED_FIELD_LIST = 'OnBuildCachedFieldList'
 
const FIELDS_MAIN = 0x0001
 
const FIELDS_UF = 0x0002
 
const FIELDS_ALL = self::FIELDS_MAIN|self::FIELDS_UF
 

Защищенные члены

 getTablet ()
 

Защищенные статические члены

static getDefaultCachedFieldList ()
 
static prepareForAdd (ORM\Data\AddResult $result, $id, array &$data)
 
static prepareForUpdate (ORM\Data\UpdateResult $result, $id, array &$data)
 
static runAddExternalActions ($id, array $data)
 
static runUpdateExternalActions ($id, array $data)
 
static runDeleteExternalActions ($id)
 
static deleteNoDemands ($id)
 
static normalize (array &$data)
 
static prepareFloatValue ($value)
 
static prepareIntValue ($value)
 
static prepareStringValue ($value)
 

Защищенные данные

const ACTION_CHANGE_PARENT_AVAILABLE = 'SKU_AVAILABLE'
 
const ACTION_SEND_NOTIFICATIONS = 'SUBSCRIPTION'
 

Подробное описание

См. определение в файле product.php строка 15

Методы

◆ add()

static add ( array  $data)
staticinherited

Add entity item. Use instead of DataManager method.

Аргументы
array$data
Возвращает
ORM\Data\AddResult

См. определение в файле entity.php строка 150

150 : ORM\Data\AddResult
151 {
152 $result = new ORM\Data\AddResult();
153
154 $entity = static::getEntity();
155
156 static::normalize($data);
157
158 if (Event::existEventHandlers($entity, ORM\Data\DataManager::EVENT_ON_BEFORE_ADD))
159 {
160 $event = new Event(
161 $entity,
162 ORM\Data\DataManager::EVENT_ON_BEFORE_ADD,
163 $data
164 );
165 $event->send();
166
167 $event->mergeData($data);
168 if ($event->getErrors($result))
169 return $result;
170 }
171
172 static::prepareForAdd($result, null, $data);
173 if (!$result->isSuccess())
174 return $result;
175 unset($result);
176
177 if (Event::existEventHandlers($entity, ORM\Data\DataManager::EVENT_ON_ADD))
178 {
179 $event = new Event(
180 $entity,
181 ORM\Data\DataManager::EVENT_ON_ADD,
182 $data
183 );
184 $event->send();
185 unset($event);
186 }
187
188 $result = $entity->getTablet()->add($data['fields']);
189 $success = $result->isSuccess();
190 if ($success)
191 {
192 $data['fields'] = $result->getData();
193 if ($entity->fieldsCount > 0)
194 $entity->setEntityCacheItem((int)$result->getId(), $result->getData(), false);
195 }
196
197 if (Event::existEventHandlers($entity, ORM\Data\DataManager::EVENT_ON_AFTER_ADD))
198 {
199 $event = new Event(
200 $entity,
201 ORM\Data\DataManager::EVENT_ON_AFTER_ADD,
202 [
203 'id' => $result->getId(),
204 'fields' => $data['fields'],
205 'external_fields' => $data['external_fields'],
206 'actions' => $data['actions'],
207 'success' => $success
208 ]
209 );
210 $event->send();
211 unset($event);
212 }
213
214 if ($success && !empty($data['actions']))
215 static::runAddExternalActions($result->getId(), $data);
216
217 unset($success, $entity);
218
219 return $result;
220 }

◆ clearCache()

static clearCache ( )
staticinherited

Clear all cache for entity.

Возвращает
void

См. определение в файле entity.php строка 139

139 : void
140 {
141 static::getEntity()->clearEntityCache();
142 }

◆ clearCacheItem()

static clearCacheItem (   $id)
staticinherited

Clear item cache. Do not use without good reason.

Аргументы
int$id
Возвращает
void @noinspection PhpUnused

См. определение в файле entity.php строка 411

411 : void
412 {
413 $id = (int)$id;
414 if ($id <= 0)
415 return;
416 static::getEntity()->clearEntityCacheItem($id);
417 }

◆ clearSettings()

static clearSettings ( )
staticinherited

Переопределяется в Price.

См. определение в файле entity.php строка 970

970: void {}

◆ delete()

static delete (   $id)
static

Delete product item. Use instead of DataManager method.

Аргументы
int$id
Возвращает
ORM\Data\DeleteResult

Переопределяет метод предка Entity.

См. определение в файле product.php строка 63

63 : ORM\Data\DeleteResult
64 {
65 return parent::deleteNoDemands($id);
66 }

◆ deleteNoDemands()

static deleteNoDemands (   $id)
staticprotectedinherited

Delete entity item without entity events (tablet events only).

Аргументы
int$id
Возвращает
ORM\Data\DeleteResult
Исключения
Main

ObjectNotFoundException

См. определение в файле entity.php строка 534

534 : ORM\Data\DeleteResult
535 {
536 $entity = static::getEntity();
537
538 if ($entity->fieldsCount > 0 && !isset($entity->cache[$id]))
539 $entity->loadEntityCacheItem($id);
540
541 $result = $entity->getTablet()->delete($id);
542 if ($result->isSuccess())
543 {
544 if ($entity->fieldsCount > 0)
545 $entity->expireEntityCacheItem((int)$id);
546 static::runDeleteExternalActions($id);
547 }
548
549 unset($entity);
550
551 return $result;
552 }

◆ fetch()

fetch ( Main\Text\Converter  $converter = null)
inherited

Entity fetch. Work with entity change cache.

Аргументы
Main\Text\Converter | null$converter
Возвращает
array|false

См. определение в файле entity.php строка 112

113 {
114 if ($this->result === null)
115 return false;
116 $row = $this->result->fetch($converter);
117 if (!$row)
118 {
119 $this->result = null;
120 $this->fetchCutMask = [];
121 return false;
122 }
123 if (empty($this->fields))
124 return $row;
125 if (!isset($row['ID']))
126 return $row;
127
128 $this->setEntityCacheItem((int)$row['ID'], $row, true);
129 if (!empty($this->fetchCutMask))
130 $row = array_diff_key($row, $this->fetchCutMask);
131 return $row;
132 }

◆ getCachedFieldList()

static getCachedFieldList ( )
staticinherited

Returns fields list in cache.

Возвращает
array

См. определение в файле entity.php строка 465

465 : array
466 {
467 $entity = static::getEntity();
468 return $entity->fields;
469 }

◆ getCacheItem()

static getCacheItem (   $id,
bool  $load = false 
)
staticinherited

Returns item cache.

Аргументы
int$id
bool$load
Возвращает
array|null

См. определение в файле entity.php строка 396

396 : ?array
397 {
398 $id = (int)$id;
399 if ($id <= 0)
400 return null;
401 return static::getEntity()->getEntityCacheItem($id, $load);
402 }

◆ getCallbackRestEvent()

static getCallbackRestEvent ( )
staticinherited

См. определение в файле entity.php строка 822

822 : array
823 {
824 return [Main\Rest\Event::class, 'processItemEvent'];
825 }

◆ getDefaultCachedFieldList()

static getDefaultCachedFieldList ( )
staticprotected

Returns product default fields list for caching.

Возвращает
array

Переопределяет метод предка Entity.

См. определение в файле product.php строка 44

44 : array
45 {
46 return [
47 'ID',
48 'TYPE',
49 'AVAILABLE',
50 'QUANTITY',
51 'QUANTITY_TRACE' => 'QUANTITY_TRACE_ORIG',
52 'CAN_BUY_ZERO' => 'CAN_BUY_ZERO_ORIG',
53 'SUBSCRIBE' => 'SUBSCRIBE_ORIG'
54 ];
55 }

◆ getEntity()

static getEntity ( )
staticinherited

Returns entity class.

Возвращает
Entity

См. определение в файле entity.php строка 56

56 : Entity
57 {
58 $className = get_called_class();
59 if (empty(self::$entity[$className]))
60 {
61 $entity = new static;
62 self::$entity[$className] = $entity;
63 }
64
65 return self::$entity[$className];
66 }

◆ getList()

static getList ( array  $parameters)
staticinherited

Entity getList with change cache. Need for use before add/update/delete entity row.

Аргументы
array$parameters
Возвращает
Entity
Исключения
Main

ArgumentException

Исключения
Main

ObjectNotFoundException

Исключения
Main

ObjectPropertyException

Исключения
Main

SystemException

Переопределяется в Shipment, ShipmentItem, BasketPropertyItem, BasketPropertyItemBase, EntityPropertyValue, Payment, Order, OrderBase и ShipmentItemStore.

См. определение в файле entity.php строка 78

78 : Entity
79 {
80 $entity = static::getEntity();
81 $parameters = $entity->prepareTabletQueryParameters($parameters);
82 $entity->result = $entity->getTablet()->getList($parameters);
83
84 return $entity;
85 }

◆ getRow()

static getRow ( array  $parameters)
staticinherited

Entity getRow with change cache. Wrapper for entity getList.

Аргументы
array$parameters
Возвращает
array|null
Исключения
Main

ArgumentException

Исключения
Main

ObjectNotFoundException

Исключения
Main

ObjectPropertyException

Исключения
Main

SystemException

См. определение в файле entity.php строка 97

97 : ?array
98 {
99 $parameters['limit'] = 1;
100 $result = static::getList($parameters);
101 $row = $result->fetch();
102
103 return (is_array($row) ? $row : null);
104 }

◆ getTablet()

getTablet ( )
protectedinherited

Returns entity table object.

Возвращает
ORM\Data\DataManager
Исключения
Main

ObjectNotFoundException

См. определение в файле entity.php строка 477

477 : ORM\Data\DataManager
478 {
479 if (!($this->tablet instanceof ORM\Data\DataManager))
480 throw new Main\ObjectNotFoundException(sprintf(
481 'Tablet not found in entity `%s`',
482 get_class($this)
483 ));
484 return $this->tablet;
485 }

◆ getTabletClassName()

static getTabletClassName ( )
static

Returns product tablet name.

Возвращает
string

Переопределяет метод предка Entity.

См. определение в файле product.php строка 34

34 : string
35 {
36 return '\Bitrix\Catalog\ProductTable';
37 }

◆ getTabletFieldNames()

static getTabletFieldNames ( int  $fields = self::FIELDS_MAIN)
staticinherited

Returns list of tablet field names, include user fields.

Аргументы
int$fields
Возвращает
array

См. определение в файле entity.php строка 435

435 : array
436 {
437 $result = [];
438 $entity = static::getEntity();
439 if ($fields & self::FIELDS_MAIN)
440 {
441 $result = array_keys($entity->tabletFields);
442 }
443 if ($fields & self::FIELDS_UF)
444 {
445 $list = array_keys($entity->tabletUserFields);
446 if (!empty($list))
447 {
448 $result = (empty($result)
449 ? $list
450 : array_merge($result, $list)
451 );
452 }
453 unset($list);
454 }
455
456 unset($entity);
457 return $result;
458 }

◆ normalize()

static normalize ( array &  $data)
staticprotectedinherited

Normalize data before prepare. Convert fields list into complex structure.

Аргументы
array&$data
Возвращает
void

См. определение в файле entity.php строка 560

560 : void
561 {
562 $result = [
563 'fields' => [],
564 'external_fields' => [],
565 'actions' => []
566 ];
567
568 if (isset($data['fields']) && is_array($data['fields']))
569 {
570 $result['fields'] = $data['fields'];
571 if (isset($data['external_fields']) && is_array($data['external_fields']))
572 $result['external_fields'] = $data['external_fields'];
573 if (isset($data['actions']) && is_array($data['actions']))
574 $result['actions'] = $data['actions'];
575 }
576 else
577 {
578 $result['fields'] = $data;
579 }
580
581 $data = $result;
582 unset($result);
583 }

◆ prepareFloatValue()

static prepareFloatValue (   $value)
staticprotectedinherited

См. определение в файле entity.php строка 974

974 : ?float
975 {
976 if ($value === null)
977 {
978 return null;
979 }
980
981 $result = null;
982 if (is_string($value))
983 {
984 if ($value !== '' && is_numeric($value))
985 {
986 $value = (float)$value;
987 if (is_finite($value))
988 {
989 $result = $value;
990 }
991 }
992 }
993 else
994 {
995 if (is_int($value))
996 {
997 $value = (float)$value;
998 }
999 if (
1000 is_float($value) && is_finite($value)
1001 )
1002 {
1003 $result = $value;
1004 }
1005 }
1006
1007 return $result;
1008 }

◆ prepareForAdd()

static prepareForAdd ( ORM\Data\AddResult  $result,
  $id,
array &  $data 
)
staticprotected

Check and modify fields before add product. Need for product automation.

Аргументы
ORM\Data\AddResult$result
int | null$id
array&$data
Возвращает
void

Переопределяет метод предка Entity.

См. определение в файле product.php строка 76

76 : void
77 {
78 if (isset($data['fields']['ID']))
79 $id = $data['fields']['ID'];
80 $id = (int)$id;
81 if ($id <= 0)
82 {
83 $result->addError(new ORM\EntityError(
84 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_WRONG_PRODUCT_ID')
85 ));
86 return;
87 }
88
89 $iblockId = 0;
90 if (isset($data['external_fields']['IBLOCK_ID']))
91 $iblockId = (int)$data['external_fields']['IBLOCK_ID'];
92 if ($iblockId <= 0)
93 $iblockId = \CIBlockElement::GetIBlockByID($id);
94 if (empty($iblockId))
95 {
96 $result->addError(new ORM\EntityError(
97 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_ELEMENT_NOT_EXISTS')
98 ));
99 return;
100 }
101 $iblockData = \CCatalogSku::GetInfoByIBlock($iblockId);
102 if (empty($iblockData))
103 {
104 $result->addError(new ORM\EntityError(
105 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_SIMPLE_IBLOCK')
106 ));
107 return;
108 }
109 $data['external_fields']['IBLOCK_ID'] = $iblockId;
110
111 $defaultType = self::getDefaultProductType($iblockData['CATALOG_TYPE']);
112 $allowedTypes = self::getProductTypes($iblockData['CATALOG_TYPE']);
113
114 $fields = $data['fields'];
115 parent::prepareForAdd($result, $id, $fields);
116 if (!$result->isSuccess())
117 return;
118
119 if (self::$separateSkuMode === null)
120 {
121 self::$separateSkuMode = Main\Config\Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y';
122 }
123
124 static $defaultValues = null,
125 $blackList = null,
126 $paymentPeriods = null,
127 $tripleFields = null,
128 $booleanFields = null,
129 $nullFields = null,
130 $sizeFields = null;
131 if ($defaultValues === null)
132 {
133 $defaultValues = [
134 'QUANTITY' => 0,
135 'QUANTITY_RESERVED' => 0,
136 'QUANTITY_TRACE' => Catalog\ProductTable::STATUS_DEFAULT,
137 'CAN_BUY_ZERO' => Catalog\ProductTable::STATUS_DEFAULT,
138 'WEIGHT' => 0,
139 'PRICE_TYPE' => Catalog\ProductTable::PAYMENT_TYPE_SINGLE,
140 'RECUR_SCHEME_LENGTH' => null,
141 'RECUR_SCHEME_TYPE' => Catalog\ProductTable::PAYMENT_PERIOD_DAY,
142 'TRIAL_PRICE_ID' => null,
143 'WITHOUT_ORDER' => Catalog\ProductTable::STATUS_NO,
144 'SELECT_BEST_PRICE' => Catalog\ProductTable::STATUS_NO,
145 'VAT_ID' => null,
146 'VAT_INCLUDED' => Catalog\ProductTable::STATUS_NO,
147 'BARCODE_MULTI' => Catalog\ProductTable::STATUS_NO,
148 'SUBSCRIBE' => Catalog\ProductTable::STATUS_DEFAULT,
149 'BUNDLE' => Catalog\ProductTable::STATUS_NO,
150 'PURCHASING_PRICE' => null,
151 'PURCHASING_CURRENCY' => null,
152 'TMP_ID' => null
153 ];
154
155 $blackList = [
156 'NEGATIVE_AMOUNT_TRACE' => true
157 ];
158
159 $paymentPeriods = Catalog\ProductTable::getPaymentPeriods(false);
160 $tripleFields = ['QUANTITY_TRACE', 'CAN_BUY_ZERO', 'SUBSCRIBE'];
161 $booleanFields = ['WITHOUT_ORDER', 'SELECT_BEST_PRICE', 'VAT_INCLUDED', 'BARCODE_MULTI', 'BUNDLE'];
162 $nullFields = ['MEASURE', 'TRIAL_PRICE_ID', 'VAT_ID', 'RECUR_SCHEME_LENGTH'];
163 $sizeFields = ['WIDTH', 'LENGTH', 'HEIGHT'];
164 }
165 $defaultValues['TYPE'] = $defaultType;
166
167 $fields = array_merge($defaultValues, array_diff_key($fields, $blackList));
168
169 $fields['TYPE'] = (int)$fields['TYPE'];
170 if (!isset($allowedTypes[$fields['TYPE']]))
171 {
172 $result->addError(new ORM\EntityError(
173 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_BAD_PRODUCT_TYPE')
174 ));
175 return;
176 }
177
178 if (is_string($fields['QUANTITY']) && !is_numeric($fields['QUANTITY']))
179 {
180 $result->addError(new ORM\EntityError(
182 'BX_CATALOG_MODEL_PRODUCT_ERR_BAD_NUMERIC_FIELD',
183 ['#FIELD#' => 'QUANTITY']
184 )
185 ));
186 }
187 $fields['QUANTITY'] = (float)$fields['QUANTITY'];
188
189 if (is_string($fields['QUANTITY_RESERVED']) && !is_numeric($fields['QUANTITY_RESERVED']))
190 {
191 $result->addError(new ORM\EntityError(
193 'BX_CATALOG_MODEL_PRODUCT_ERR_BAD_NUMERIC_FIELD',
194 ['#FIELD#' => 'QUANTITY_RESERVED']
195 )
196 ));
197 }
198 $fields['QUANTITY_RESERVED'] = (float)$fields['QUANTITY_RESERVED'];
199
200 foreach ($tripleFields as $fieldName)
201 {
202 if (
203 $fields[$fieldName] != Catalog\ProductTable::STATUS_NO
204 && $fields[$fieldName] != Catalog\ProductTable::STATUS_YES
205 )
206 $fields[$fieldName] = $defaultValues[$fieldName];
207 }
208 foreach ($booleanFields as $fieldName)
209 {
210 if ($fields[$fieldName] != Catalog\ProductTable::STATUS_YES)
211 $fields[$fieldName] = $defaultValues[$fieldName];
212 }
213 foreach ($nullFields as $fieldName)
214 {
215 if ($fields[$fieldName] !== null)
216 {
217 $fields[$fieldName] = (int)$fields[$fieldName];
218 if ($fields[$fieldName] <= 0)
219 $fields[$fieldName] = null;
220 }
221 }
222 foreach ($sizeFields as $fieldName)
223 {
224 if ($fields[$fieldName] !== null)
225 {
226 $fields[$fieldName] = (float)$fields[$fieldName];
227 if ($fields[$fieldName] <= 0)
228 $fields[$fieldName] = null;
229 }
230 }
231 unset($fieldName);
232
233 if (
234 $fields['PRICE_TYPE'] != Catalog\ProductTable::PAYMENT_TYPE_REGULAR
235 && $fields['PRICE_TYPE'] != Catalog\ProductTable::PAYMENT_TYPE_TRIAL
236 )
237 $fields['PRICE_TYPE'] = $defaultValues['PRICE_TYPE'];
238 if (!in_array($fields['RECUR_SCHEME_TYPE'], $paymentPeriods, true))
239 $fields['RECUR_SCHEME_TYPE'] = $defaultValues['RECUR_SCHEME_TYPE'];
240
241 if (is_string($fields['WEIGHT']) && !is_numeric($fields['WEIGHT']))
242 {
243 $result->addError(new ORM\EntityError(
245 'BX_CATALOG_MODEL_PRODUCT_ERR_BAD_NUMERIC_FIELD',
246 ['#FIELD#' => 'WEIGHT']
247 )
248 ));
249 }
250 $fields['WEIGHT'] = (float)$fields['WEIGHT'];
251 if ($fields['TMP_ID'] !== null)
252 $fields['TMP_ID'] = mb_substr($fields['TMP_ID'], 0, 40);
253
254 /* purchasing price */
255 $purchasingCurrency = null;
256 $purchasingPrice = static::checkPriceValue($fields['PURCHASING_PRICE']);
257 if ($purchasingPrice !== null)
258 {
259 $purchasingCurrency = static::checkPriceCurrency($fields['PURCHASING_CURRENCY']);
260 if ($purchasingCurrency === null)
261 {
262 $result->addError(new ORM\EntityError(
263 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_WRONG_PURCHASING_CURRENCY')
264 ));
265 $purchasingPrice = null;
266 }
267 }
268 $fields['PURCHASING_PRICE'] = $purchasingPrice;
269 $fields['PURCHASING_CURRENCY'] = $purchasingCurrency;
270 unset($purchasingCurrency, $purchasingPrice);
271 /* purchasing price end */
272
273 if (array_key_exists('AVAILABLE', $fields))
274 {
275 if (
276 $fields['AVAILABLE'] != Catalog\ProductTable::STATUS_YES
277 && $fields['AVAILABLE'] != Catalog\ProductTable::STATUS_NO
278 )
279 {
280 unset($fields['AVAILABLE']);
281 }
282 else
283 {
284 $data['actions'][self::ACTION_CHANGE_PARENT_AVAILABLE] = true;
285 }
286 }
287
288 if ($result->isSuccess())
289 {
290 $fields['ID'] = $id;
291 $fields['NEGATIVE_AMOUNT_TRACE'] = $fields['CAN_BUY_ZERO'];
292 $fields['TIMESTAMP_X'] = new Main\Type\DateTime();
293
294 if (!isset($fields['AVAILABLE']))
295 {
296 self::calculateAvailable($fields, $data['actions']);
297 if ($fields['AVAILABLE'] === null)
298 $fields['AVAILABLE'] = Catalog\ProductTable::STATUS_NO;
299 }
300 if ($fields['TYPE'] === Catalog\ProductTable::TYPE_OFFER)
301 $data['actions']['PARENT_TYPE'] = true;
302 }
303
304 if ($result->isSuccess())
305 $data['fields'] = $fields;
306 unset($fields);
307 }
static getMessage($code, $replace=null, $language=null)
Definition: loc.php:29

◆ prepareForUpdate()

static prepareForUpdate ( ORM\Data\UpdateResult  $result,
  $id,
array &  $data 
)
staticprotected

Check and modify fields before update product. Need for product automation.

Аргументы
ORM\Data\UpdateResult$result
int$id
array&$data
Возвращает
void

Переопределяет метод предка Entity.

См. определение в файле product.php строка 317

317 : void
318 {
319 $id = (int)$id;
320 if ($id <= 0)
321 {
322 $result->addError(new ORM\EntityError(
323 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_WRONG_PRODUCT_ID')
324 ));
325 return;
326 }
327
328 $iblockId = 0;
329 if (isset($data['external_fields']['IBLOCK_ID']))
330 $iblockId = (int)$data['external_fields']['IBLOCK_ID'];
331 if ($iblockId <= 0)
332 $iblockId = \CIBlockElement::GetIBlockByID($id);
333 if (empty($iblockId))
334 {
335 $result->addError(new ORM\EntityError(
336 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_ELEMENT_NOT_EXISTS')
337 ));
338 return;
339 }
340 $iblockData = \CCatalogSku::GetInfoByIBlock($iblockId);
341 if (empty($iblockData))
342 {
343 $result->addError(new ORM\EntityError(
344 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_SIMPLE_IBLOCK')
345 ));
346 return;
347 }
348 $data['external_fields']['IBLOCK_ID'] = $iblockId;
349
350 $fields = $data['fields'];
351 parent::prepareForUpdate($result, $id, $fields);
352 if (!$result->isSuccess())
353 return;
354
355 if (self::$separateSkuMode === null)
356 {
357 self::$separateSkuMode = Main\Config\Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y';
358 }
359
360 static $quantityFields = null,
361 $paymentPeriods = null,
362 $tripleFields = null,
363 $booleanFields = null,
364 $nullFields = null,
365 $sizeFields = null,
366 $blackList = null;
367
368 if ($quantityFields === null)
369 {
370 $quantityFields = ['QUANTITY', 'QUANTITY_RESERVED'];
371 $paymentPeriods = Catalog\ProductTable::getPaymentPeriods(false);
372 $tripleFields = ['QUANTITY_TRACE', 'CAN_BUY_ZERO', 'SUBSCRIBE'];
373 $booleanFields = ['WITHOUT_ORDER', 'SELECT_BEST_PRICE', 'VAT_INCLUDED', 'BARCODE_MULTI', 'BUNDLE', 'AVAILABLE'];
374 $nullFields = ['MEASURE', 'TRIAL_PRICE_ID', 'VAT_ID', 'RECUR_SCHEME_LENGTH'];
375 $sizeFields = ['WIDTH', 'LENGTH', 'HEIGHT'];
376
377 $blackList = [
378 'ID' => true,
379 'NEGATIVE_AMOUNT_TRACE' => true
380 ];
381 }
382 $fields = array_diff_key($fields, $blackList);
383
384 $allowedTypes = self::getProductTypes($iblockData['CATALOG_TYPE']);
385
386 if (array_key_exists('TYPE', $fields))
387 {
388 $fields['TYPE'] = (int)$fields['TYPE'];
389 if (!isset($allowedTypes[$fields['TYPE']]))
390 {
391 $result->addError(new ORM\EntityError(
392 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_BAD_PRODUCT_TYPE')
393 ));
394 return;
395 }
396 }
397
398 foreach ($quantityFields as $fieldName)
399 {
400 if (array_key_exists($fieldName, $fields))
401 {
402 if ($fields[$fieldName] === null)
403 unset($fields[$fieldName]);
404 else
405 $fields[$fieldName] = (float)$fields[$fieldName];
406 }
407 }
408 foreach ($tripleFields as $fieldName)
409 {
410 if (array_key_exists($fieldName, $fields))
411 {
412 if (
413 $fields[$fieldName] != Catalog\ProductTable::STATUS_NO
414 && $fields[$fieldName] != Catalog\ProductTable::STATUS_YES
415 && $fields[$fieldName] != Catalog\ProductTable::STATUS_DEFAULT
416 )
417 unset($fields[$fieldName]);
418 }
419 }
420 if (isset($fields['SUBSCRIBE']))
421 $data['actions'][self::ACTION_SEND_NOTIFICATIONS] = true;
422 foreach ($booleanFields as $fieldName)
423 {
424 if (array_key_exists($fieldName, $fields))
425 {
426 if (
427 $fields[$fieldName] != Catalog\ProductTable::STATUS_NO
428 && $fields[$fieldName] != Catalog\ProductTable::STATUS_YES
429 )
430 unset($fields[$fieldName]);
431 }
432 }
433 foreach ($nullFields as $fieldName)
434 {
435 if (array_key_exists($fieldName, $fields))
436 {
437 if ($fields[$fieldName] !== null)
438 {
439 $fields[$fieldName] = (int)$fields[$fieldName];
440 if ($fields[$fieldName] <= 0)
441 $fields[$fieldName] = null;
442 }
443 }
444 }
445 foreach ($sizeFields as $fieldName)
446 {
447 if ($fields[$fieldName] !== null)
448 {
449 $fields[$fieldName] = (float)$fields[$fieldName];
450 if ($fields[$fieldName] <= 0)
451 $fields[$fieldName] = null;
452 }
453 }
454 unset($fieldName);
455
456 if (array_key_exists('PRICE_TYPE', $fields))
457 {
458 if (
459 $fields['PRICE_TYPE'] != Catalog\ProductTable::PAYMENT_TYPE_REGULAR
460 && $fields['PRICE_TYPE'] != Catalog\ProductTable::PAYMENT_TYPE_TRIAL
461 && $fields['PRICE_TYPE'] != Catalog\ProductTable::PAYMENT_TYPE_SINGLE
462 )
463 unset($fields['PRICE_TYPE']);
464 }
465 if (array_key_exists('RECUR_SCHEME_TYPE', $fields))
466 {
467 if (!in_array($fields['RECUR_SCHEME_TYPE'], $paymentPeriods, true))
468 unset($fields['RECUR_SCHEME_TYPE']);
469 }
470
471 if (array_key_exists('WEIGHT', $fields))
472 {
473 if ($fields['WEIGHT'] === null)
474 {
475 unset($fields['WEIGHT']);
476 }
477 else
478 {
479 $fields['WEIGHT'] = (float)$fields['WEIGHT'];
480 $data['actions']['SETS'] = true;
481 }
482 }
483 if (isset($fields['TMP_ID']))
484 $fields['TMP_ID'] = mb_substr($fields['TMP_ID'], 0, 40);
485
486 /* purchasing price */
487 $existPurchasingPrice = array_key_exists('PURCHASING_PRICE', $fields);
488 $existPurchasingCurrency = array_key_exists('PURCHASING_CURRENCY', $fields);
489 if ($existPurchasingPrice)
490 {
491 $fields['PURCHASING_PRICE'] = static::checkPriceValue($fields['PURCHASING_PRICE']);
492 if ($fields['PURCHASING_PRICE'] === null)
493 {
494 $fields['PURCHASING_CURRENCY'] = null;
495 $existPurchasingCurrency = false;
496 }
497 }
498 if ($existPurchasingCurrency)
499 {
500 $fields['PURCHASING_CURRENCY'] = static::checkPriceCurrency($fields['PURCHASING_CURRENCY']);
501 if ($fields['PURCHASING_CURRENCY'] === null)
502 {
503 $result->addError(new ORM\EntityError(
504 Loc::getMessage('BX_CATALOG_MODEL_PRODUCT_ERR_WRONG_PURCHASING_CURRENCY')
505 ));
506 }
507 }
508 /* purchasing price end */
509
510 if ($result->isSuccess())
511 {
512 if (isset($fields['CAN_BUY_ZERO']))
513 $fields['NEGATIVE_AMOUNT_TRACE'] = $fields['CAN_BUY_ZERO'];
514 $fields['TIMESTAMP_X'] = new Main\Type\DateTime();
515
516 if (isset($fields['AVAILABLE']))
517 {
518 $data['actions'][self::ACTION_CHANGE_PARENT_AVAILABLE] = true;
519 $data['actions']['SETS'] = true;
520 $data['actions'][self::ACTION_SEND_NOTIFICATIONS] = true;
521 }
522 else
523 {
524 $needCalculateAvailable = (isset($fields['TYPE'])
525 || isset($fields['QUANTITY'])
526 || isset($fields['QUANTITY_TRACE'])
527 || isset($fields['CAN_BUY_ZERO'])
528 );
529 if ($needCalculateAvailable)
530 {
531 $needCache = (!isset($fields['TYPE'])
532 || !isset($fields['QUANTITY'])
533 || !isset($fields['QUANTITY_TRACE'])
534 || !isset($fields['CAN_BUY_ZERO'])
535 );
536 $copyFields = (
537 $needCache
538 ? array_merge(static::getCacheItem($id, true), $fields)
539 : $fields
540 );
541
542 self::calculateAvailable($copyFields, $data['actions']);
543 if ($copyFields['AVAILABLE'] !== null)
544 $fields['AVAILABLE'] = $copyFields['AVAILABLE'];
545 unset($copyFields, $needCache);
546 }
547 unset($needCalculateAvailable);
548 }
549 $data['fields'] = $fields;
550 }
551
552 unset($fields);
553 }

◆ prepareIntValue()

static prepareIntValue (   $value)
staticprotectedinherited

См. определение в файле entity.php строка 1010

1010 : ?int
1011 {
1012 if ($value === null)
1013 {
1014 return null;
1015 }
1016
1017 $result = null;
1018 if (is_string($value))
1019 {
1020 if ($value !== '' && is_numeric($value))
1021 {
1022 $result = (int)$value;
1023 }
1024 }
1025 elseif (is_int($value))
1026 {
1027 $result = $value;
1028 }
1029
1030 return $result;
1031 }

◆ prepareStringValue()

static prepareStringValue (   $value)
staticprotectedinherited

См. определение в файле entity.php строка 1033

1033 : ?string
1034 {
1035 if (is_string($value))
1036 {
1037 return trim($value) ?: null;
1038 }
1039
1040 return null;
1041 }

◆ runAddExternalActions()

static runAddExternalActions (   $id,
array  $data 
)
staticprotected

Run core automation after add product.

Аргументы
int$id
array$data
Возвращает
void

Переопределяет метод предка Entity.

См. определение в файле product.php строка 562

562 : void
563 {
564 switch ($data['fields']['TYPE'])
565 {
566 case Catalog\ProductTable::TYPE_OFFER:
567 if (
568 isset($data['actions'][self::ACTION_CHANGE_PARENT_AVAILABLE])
569 || isset($data['actions']['PARENT_TYPE'])
570 )
571 {
572 Catalog\Product\Sku::calculateComplete(
573 $id,
574 $data['external_fields']['IBLOCK_ID'],
576 );
577 }
578 break;
579 case Catalog\ProductTable::TYPE_SKU:
580 if (isset($data['actions'][self::ACTION_CHANGE_PARENT_AVAILABLE]))
581 {
582 Catalog\Product\Sku::calculateComplete(
583 $id,
584 $data['external_fields']['IBLOCK_ID'],
586 );
587 }
588 break;
589 }
590 }

◆ runDeleteExternalActions()

static runDeleteExternalActions (   $id)
staticprotected

Run core automation after delete product.

Аргументы
int$id
Возвращает
void

Переопределяет метод предка Entity.

См. определение в файле product.php строка 695

695 : void
696 {
697 Catalog\PriceTable::deleteByProduct($id);
698 Catalog\MeasureRatioTable::deleteByProduct($id);
699 Catalog\ProductGroupAccessTable::deleteByProduct($id);
700 Catalog\StoreProductTable::deleteByProduct($id);
701 Catalog\SubscribeTable::onIblockElementDelete($id);
703 //TODO: replace this code
704 $conn = Main\Application::getConnection();
705 $helper = $conn->getSqlHelper();
706 $conn->queryExecute(
707 'delete from '.$helper->quote('b_catalog_product_sets').
708 ' where '.$helper->quote('ITEM_ID').' = '.$id.' or '.$helper->quote('OWNER_ID').' = '.$id
709 );
710 unset($helper, $conn);
711 }

◆ runUpdateExternalActions()

static runUpdateExternalActions (   $id,
array  $data 
)
staticprotected

Run core automation after update product.

Аргументы
int$id
array$data
Возвращает
void

Переопределяет метод предка Entity.

См. определение в файле product.php строка 599

599 : void
600 {
601 $product = self::getCacheItem($id);
602 if (isset($data['actions'][self::ACTION_CHANGE_PARENT_AVAILABLE]))
603 {
604 switch ($product['TYPE'])
605 {
606 case Catalog\ProductTable::TYPE_OFFER:
607 if (isset($data['actions']['SKU_AVAILABLE']))
608 {
609 Catalog\Product\Sku::calculateComplete(
610 $id,
611 $data['external_fields']['IBLOCK_ID'],
613 );
614 }
615 self::updateElementModificationTime($id);
616 break;
617 case Catalog\ProductTable::TYPE_SKU:
618 if (isset($data['actions']['SKU_AVAILABLE']))
619 {
620 Catalog\Product\Sku::calculateComplete(
621 $id,
622 $data['external_fields']['IBLOCK_ID'],
624 );
625 }
626 break;
627 case Catalog\ProductTable::TYPE_PRODUCT:
628 case Catalog\ProductTable::TYPE_SET:
629 self::updateElementModificationTime($id);
630 break;
631 }
632 }
633 if (isset($data['actions'][self::ACTION_SEND_NOTIFICATIONS]))
634 self::checkSubscription($id, $product);
635 if (isset($data['actions']['SETS']))
636 \CCatalogProductSet::recalculateSetsByProduct($id);
637
638 $changeAvailable = (
639 isset($product['AVAILABLE'])
640 && isset($product[self::PREFIX_OLD.'AVAILABLE'])
641 && $product[self::PREFIX_OLD.'AVAILABLE'] != $product['AVAILABLE']
642 );
643 if ($changeAvailable)
644 {
645 // clear public components cache
646 \CIBlock::clearIblockTagCache($data['external_fields']['IBLOCK_ID']);
647 // send old event
648 $eventId = 'OnProductQuantityTrace';
649 if (
650 Main\Config\Option::get('catalog', 'enable_processing_deprecated_events') === 'Y'
651 && Event::existEventHandlersById($eventId)
652 )
653 {
654 $description = [
655 'ID' => $product['ID'],
656 'ELEMENT_IBLOCK_ID' => $data['external_fields']['IBLOCK_ID'],
657 'IBLOCK_ID' => $data['external_fields']['IBLOCK_ID'],
658 'TYPE' => $product['TYPE'],
659 'AVAILABLE' => $product['AVAILABLE'],
660 'CAN_BUY_ZERO' => $product['CAN_BUY_ZERO'],
661 'NEGATIVE_AMOUNT_TRACE' => $product['CAN_BUY_ZERO'],
662 'QUANTITY_TRACE' => $product['QUANTITY_TRACE'],
663 'QUANTITY' => $product['QUANTITY'],
664 'OLD_QUANTITY' => $product[self::PREFIX_OLD.'QUANTITY'] ?? $product['QUANTITY'],
665 ];
666 $description['DELTA'] = $description['QUANTITY'] - $description['OLD_QUANTITY'];
667 $handlerData = [
668 $product['ID'],
669 $description,
670 ];
671 unset($description);
672
673 $eventManager = Main\EventManager::getInstance();
674 $handlerList = $eventManager->findEventHandlers('catalog', $eventId);
675 foreach ($handlerList as $handler)
676 {
677 $handler['FROM_MODULE_ID'] = 'catalog';
678 $handler['MESSAGE_ID'] = $eventId;
679 ExecuteModuleEventEx($handler, $handlerData);
680 }
681 unset($handler, $handlerList);
682 unset($handlerData);
683 }
684 }
685
686 unset($product);
687 }

◆ setCacheItem()

static setCacheItem (   $id,
array  $row 
)
staticinherited

Fill item cache data. Do not use without good reason.

Аргументы
int$id
array$row
Возвращает
void

См. определение в файле entity.php строка 381

381 : void
382 {
383 $id = (int)$id;
384 if ($id <= 0 || empty($row))
385 return;
386 static::getEntity()->setEntityCacheItem($id, $row, false);
387 }

◆ update()

static update (   $id,
array  $data 
)
staticinherited

Update entity item. Use instead of DataManager method.

Аргументы
int$id
array$data
Возвращает
ORM\Data\UpdateResult

См. определение в файле entity.php строка 229

229 : ORM\Data\UpdateResult
230 {
231 $result = new ORM\Data\UpdateResult();
232
233 $entity = static::getEntity();
234
235 static::normalize($data);
236
237 if (Event::existEventHandlers($entity, ORM\Data\DataManager::EVENT_ON_BEFORE_UPDATE))
238 {
239 $event = new Event(
240 $entity,
241 ORM\Data\DataManager::EVENT_ON_BEFORE_UPDATE,
242 [
243 'id' => $id,
244 'fields' => $data['fields'],
245 'external_fields' => $data['external_fields'],
246 'actions' => $data['actions']
247 ]
248 );
249 $event->send();
250
251 $event->mergeData($data);
252 if ($event->getErrors($result))
253 return $result;
254 }
255
256 static::prepareForUpdate($result, $id, $data);
257 if (!$result->isSuccess())
258 return $result;
259 unset($result);
260
261 if (Event::existEventHandlers($entity, ORM\Data\DataManager::EVENT_ON_UPDATE))
262 {
263 $event = new Event(
264 $entity,
265 ORM\Data\DataManager::EVENT_ON_UPDATE,
266 [
267 'id' => $id,
268 'fields' => $data['fields'],
269 'external_fields' => $data['external_fields'],
270 'actions' => $data['actions']
271 ]
272 );
273 $event->send();
274 unset($event);
275 }
276
277 $result = $entity->getTablet()->update($id, $data['fields']);
278 $success = $result->isSuccess();
279 if ($success)
280 {
281 $data['fields'] = $result->getData();
282 if ($entity->fieldsCount > 0)
283 $entity->modifyEntityCacheItem($id, $data['fields']);
284 }
285
286 if (Event::existEventHandlers($entity, ORM\Data\DataManager::EVENT_ON_AFTER_UPDATE))
287 {
288 $event = new Event(
289 $entity,
290 ORM\Data\DataManager::EVENT_ON_AFTER_UPDATE,
291 [
292 'id' => $id,
293 'fields' => $data['fields'],
294 'external_fields' => $data['external_fields'],
295 'actions' => $data['actions'],
296 'success' => $success
297 ]
298 );
299 $event->send();
300 unset($event);
301 }
302
303 if ($success && !empty($data['actions']))
304 static::runUpdateExternalActions($id, $data);
305
306 unset($success, $entity);
307
308 return $result;
309 }

Поля

◆ ACTION_CHANGE_PARENT_AVAILABLE

const ACTION_CHANGE_PARENT_AVAILABLE = 'SKU_AVAILABLE'
protected

См. определение в файле product.php строка 18

◆ ACTION_SEND_NOTIFICATIONS

const ACTION_SEND_NOTIFICATIONS = 'SUBSCRIPTION'
protected

См. определение в файле product.php строка 20

◆ EVENT_ON_BUILD_CACHED_FIELD_LIST

const EVENT_ON_BUILD_CACHED_FIELD_LIST = 'OnBuildCachedFieldList'
inherited

См. определение в файле entity.php строка 15

◆ FIELDS_ALL

const FIELDS_ALL = self::FIELDS_MAIN|self::FIELDS_UF
inherited

См. определение в файле entity.php строка 19

◆ FIELDS_MAIN

const FIELDS_MAIN = 0x0001
inherited

См. определение в файле entity.php строка 17

◆ FIELDS_UF

const FIELDS_UF = 0x0002
inherited

См. определение в файле entity.php строка 18

◆ PREFIX_OLD

const PREFIX_OLD = 'OLD_'
inherited

См. определение в файле entity.php строка 13


Объявления и описания членов класса находятся в файле: