• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/tradebindingcollection.php
  • Класс: BitrixSaleTradeBindingCollection
  • Вызов: TradeBindingCollection::save
public function save()
{
	$result = new Result();

	/** @var Order $order */
	if (!$order = $this->getEntityParent())
	{
		throw new MainObjectNotFoundException('Entity "Order" not found');
	}

	if (!$order->isNew())
	{
		$itemsFromDbList = static::getList(
			array(
				"filter" => array("ORDER_ID" => $order->getId())
			)
		);

		while ($item = $itemsFromDbList->fetch())
		{
			if (!$this->getItemById($item['ID']))
			{
				static::deleteInternal($item['ID']);
			}
		}
	}

	/** @var TradeBindingEntity $entity */
	foreach ($this->collection as $entity)
	{
		$r = $entity->save();
		if (!$r->isSuccess())
		{
			$result->addErrors($r->getErrors());
		}
	}

	$this->clearChanged();

	return $result;
}