• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/basketpropertiesitembase.php
  • Класс: BitrixSaleBasketPropertyItemBase
  • Вызов: BasketPropertyItemBase::save
public function save()
{
	$this->checkCallingContext();

	$result = new Result();

	$id = $this->getId();

	$fields = $this->fields->getChangedValues();

	if (!empty($fields) && is_array($fields))
	{
		$map = static::getFieldsMap();
		foreach ($map as $key => $value)
		{
			if ($value instanceof MainEntityStringField)
			{
				$fieldName = $value->getName();
				if (array_key_exists($fieldName, $fields))
				{
					if (!empty($fields[$fieldName]) && mb_strlen($fields[$fieldName]) > $value->getSize())
					{
						$fields[$fieldName] = mb_substr($fields[$fieldName], 0, $value->getSize());
					}
				}
			}
		}
	}

	if ($id > 0)
	{
		if (!empty($fields) && is_array($fields))
		{
			$r = $this->updateInternal($id, $fields);
			if (!$r->isSuccess())
			{
				$result->addErrors($r->getErrors());
				return $result;
			}

			if ($resultData = $r->getData())
			{
				$result->setData($resultData);
			}
		}
	}
	else
	{
		/** @var BasketPropertiesCollectionBase $collection */
		$collection = $this->getCollection();
		$basketItem = $collection->getBasketItem();
		$fields['BASKET_ID'] = ($basketItem) ? $basketItem->getId() : 0;
		$this->setFieldNoDemand('BASKET_ID', $fields['BASKET_ID']);

		$r = $this->addInternal($fields);
		if (!$r->isSuccess())
		{
			$result->addErrors($r->getErrors());
			return $result;
		}

		if ($resultData = $r->getData())
		{
			$result->setData($resultData);
		}

		$id = $r->getId();
		$this->setFieldNoDemand('ID', $id);
	}

	if ($id > 0)
	{
		$result->setId($id);
	}

	return $result;
}