54 private static function createBasketPropertyItemObject(array $fields = [])
57 $basketPropertyItemClassName = $registry->getBasketPropertyItemClassName();
59 return new $basketPropertyItemClassName($fields);
71 $basketPropertyItem = static::createBasketPropertyItemObject();
72 $basketPropertyItem->setCollection($basketPropertiesCollection);
74 $basketPropertyItem->setField(
'XML_ID', static::generateXmlId());
76 return $basketPropertyItem;
95 public function save()
97 $this->checkCallingContext();
101 $id = $this->getId();
103 $fields = $this->fields->getChangedValues();
105 if (!empty($fields) && is_array($fields))
107 $map = static::getFieldsMap();
108 foreach ($map as $key => $value)
112 $fieldName = $value->getName();
113 if (array_key_exists($fieldName, $fields))
115 if (!empty($fields[$fieldName]) && mb_strlen($fields[$fieldName]) > $value->getSize())
117 $fields[$fieldName] = mb_substr($fields[$fieldName], 0, $value->getSize());
126 if (!empty($fields) && is_array($fields))
129 if (!$r->isSuccess())
131 $result->addErrors($r->getErrors());
135 if ($resultData = $r->getData())
137 $result->setData($resultData);
146 $fields[
'BASKET_ID'] = ($basketItem) ? $basketItem->getId() : 0;
147 $this->setFieldNoDemand(
'BASKET_ID', $fields[
'BASKET_ID']);
150 if (!$r->isSuccess())
152 $result->addErrors($r->getErrors());
156 if ($resultData = $r->getData())
158 $result->setData($resultData);
162 $this->setFieldNoDemand(
'ID', $id);
176 private function checkCallingContext()
183 $basket = $basketItem->getBasket();
185 $order = $basket->getOrder();
189 if (!$order->isSaveRunning())
191 trigger_error(
"Incorrect call to the save process. Use method save() on \Bitrix\Sale\Order entity", E_USER_WARNING);
196 if (!$basket->isSaveRunning())
198 trigger_error(
"Incorrect call to the save process. Use method save() on \Bitrix\Sale\Basket entity", E_USER_WARNING);
211 $map = static::getFieldsMap();
213 $fieldValues = $fields = $this->fields->getValues();
215 $propertyName = (!empty($fieldValues[
'NAME'])) ? $fieldValues[
'NAME'] :
"";
216 if ($this->getId() > 0)
218 $fields = $this->fields->getChangedValues();
221 foreach ($map as $key => $value)
225 $fieldName = $value->getName();
226 if (!empty($fields[$fieldName]) && mb_strlen($fields[$fieldName]) > $value->getSize())
228 if ($fieldName ===
'NAME')
230 $propertyName = mb_substr($propertyName, 0, 50).
"...";
236 "SALE_BASKET_ITEM_PROPERTY_MAX_LENGTH_ERROR",
238 "#PROPERTY_NAME#" => $propertyName,
239 "#FIELD_TITLE#" => $fieldName,
240 "#MAX_LENGTH#" => $value->getSize()
243 'SALE_BASKET_ITEM_PROPERTY_MAX_LENGTH_ERROR'
262 if (intval($id) <= 0)
269 $dbRes = static::getList([
270 'filter' => [
"=BASKET_ID" => $id],
271 'order' => [
"SORT" =>
"ASC",
"ID" =>
"ASC"],
274 while ($property = $dbRes->fetch())
276 $result[] = static::createBasketPropertyItemObject($property);
292 $dbRes = static::getList(
294 'filter' => array(
"@BASKET_ID" => $idList),
295 'order' => array(
"SORT" =>
"ASC",
"ID" =>
"ASC"),
299 while ($property = $dbRes->fetch())
301 $result[$property[
'BASKET_ID']][] = static::createBasketPropertyItemObject($property);
326 public static function getList(array $parameters = [])
338 return 'SaleBasketPropertyItem';
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)