51 private static function createBasketPropertiesCollectionObject()
54 $basketPropertiesCollectionClassName = $registry->getBasketPropertiesCollectionClassName();
56 return new $basketPropertiesCollectionClassName();
68 public static function load(BasketItemBase
$basketItem)
70 $basketPropertyCollection = static::createBasketPropertiesCollectionObject();
71 $basketPropertyCollection->setBasketItem(
$basketItem);
72 $basketItem->setPropertyCollection($basketPropertyCollection);
79 $basketPropertyItemClass = $registry->getBasketPropertyItemClassName();
81 $propertyList = $basketPropertyItemClass::loadForBasketItem(
$basketItem->getId());
83 foreach ($propertyList as $property)
85 $property->setCollection($basketPropertyCollection);
86 $basketPropertyCollection->addItem($property);
98 protected static function getBasketIdList(BasketItemCollection $basket)
100 $resultList = array();
122 public static function loadByCollection(BasketItemCollection
$collection)
126 $basketIdList = static::getBasketIdList(
$collection);
128 if (!empty($basketIdList))
133 $basketPropertyItemClass = $registry->getBasketPropertyItemClassName();
135 $propertyList = $basketPropertyItemClass::loadForBasket($basketIdList);
146 $basketPropertyCollection = static::createBasketPropertiesCollectionObject();
147 $basketPropertyCollection->setBasketItem(
$basketItem);
152 foreach ($propertyList[
$basketItem->getId()] as $property)
154 $property->setCollection($basketPropertyCollection);
155 $basketPropertyCollection->addItem($property);
159 $basketItem->setPropertyCollection($basketPropertyCollection);
170 public function createItem()
175 $basketPropertyItemClassName = $registry->getBasketPropertyItemClassName();
177 $basketPropertyItem = $basketPropertyItemClassName::create($this);
178 $this->addItem($basketPropertyItem);
180 return $basketPropertyItem;
187 private function getPropertyCode(BasketPropertyItemBase $property)
189 return $property->getField(
'NAME').
"|".$property->getField(
"CODE");
202 public function redefine(array $properties)
204 $indexList = array();
207 foreach($this->collection as $propertyItem)
209 $code = $this->getPropertyCode($propertyItem);
210 $indexList[$code] = $propertyItem->getId();
213 foreach ($properties as $value)
215 if (!is_array($value) || empty($value))
220 if (isset($value[
'ID']) && intval($value[
'ID']) > 0)
226 $propertyItem = $this->getPropertyItemByValue($value);
231 $propertyItem = $this->createItem();
235 $code = $this->getPropertyCode($propertyItem);
236 if (isset($indexList[$code]))
238 unset($indexList[$code]);
242 $availableFields = $propertyItem::getAvailableFields();
245 foreach ($value as $k => $v)
247 if (isset($availableFields[$k]))
253 $propertyItem->setFields($fields);
256 if (!empty($indexList))
258 foreach($indexList as $code => $id)
265 if ($propertyItem->getField(
'CODE') ==
"CATALOG.XML_ID"
266 || $propertyItem->getField(
'CODE') ==
"PRODUCT.XML_ID"
272 $propertyItem->delete();
278 foreach ($this->collection as $propertyItem)
280 if ($propertyItem->getField(
'CODE') ==
"CATALOG.XML_ID"
281 || $propertyItem->getField(
'CODE') ==
"PRODUCT.XML_ID"
287 $propertyCode = $this->getPropertyCode($propertyItem);
288 if ($propertyCode == $code)
290 $propertyItem->delete();
304 public function save()
306 $result =
new Sale\Result();
314 $itemsFromDbList = static::getList(
321 while ($itemsFromDbItem = $itemsFromDbList->fetch())
323 $itemsFromDb[$itemsFromDbItem[
"ID"]] =
true;
328 foreach ($this->collection as $basketProperty)
330 $r = $basketProperty->save();
331 if (!$r->isSuccess())
333 $result->addErrors($r->getErrors());
336 unset($itemsFromDb[$basketProperty->getId()]);
339 foreach ($itemsFromDb as $basketPropertyId => $value)
341 static::delete($basketPropertyId);
358 if (!($propertyValues = $this->getPropertyValues()))
363 $requestValues = array();
364 foreach ($values as $value)
366 if (!($propertyValue = static::bringingPropertyValue($value)))
371 $requestValues[$propertyValue[
'CODE']] = $propertyValue[
"VALUE"];
374 if (
count($requestValues) !==
count($propertyValues))
380 foreach($requestValues as $key => $val)
382 if (!array_key_exists($key, $propertyValues) || (array_key_exists($key, $propertyValues) && $propertyValues[$key][
'VALUE'] != $val))
396 public function getPropertyItemByValue(array $value)
398 if (!($propertyValue = static::bringingPropertyValue($value)))
404 foreach ($this->collection as $propertyItem)
406 $propertyItemValues = $propertyItem->getFieldValues();
408 if (!($propertyItemValue = static::bringingPropertyValue($propertyItemValues)))
414 if ($propertyItemValue[
'CODE'] == $propertyValue[
'CODE'])
416 return $propertyItem;
426 public function getPropertyValues()
431 foreach($this->collection as $property)
433 $value = $property->getFieldValues();
434 $propertyValue = static::bringingPropertyValue($value);
440 $result[$propertyValue[
'CODE']] = $propertyValue;
451 private static function bringingPropertyValue(array $value)
454 if (array_key_exists(
'VALUE', $value))
457 if (array_key_exists(
'CODE', $value) && (
string)$value[
"CODE"] !==
'')
459 $propID = $value[
"CODE"];
461 elseif (array_key_exists(
'NAME', $value) && (
string)$value[
"NAME"] !==
'')
463 $propID = $value[
"NAME"];
466 $propID = (string)$propID;
471 'VALUE' => $value[
'VALUE'],
472 'NAME' => $value[
'NAME'] ??
null,
473 'SORT' => $value[
'SORT'] ??
null,
474 'ID' => $value[
'ID'] ??
null,
495 public function createClone(\SplObjectStorage $cloneEntity)
498 $basketPropertiesCollectionClone = parent::createClone($cloneEntity);
510 $basketPropertiesCollectionClone->basketItem = $cloneEntity[
$basketItem];
514 return $basketPropertiesCollectionClone;
523 $result =
new Result();
526 foreach ($this->collection as $basketPropertyItem)
528 $r = $basketPropertyItem->verify();
529 if (!$r->isSuccess())
531 $result->addErrors($r->getErrors());
543 public static function getList(array $parameters = array())
554 protected static function delete($primary)
573 $this->redefine($values);