- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/shipment.php
- Класс: BitrixSaleShipment
- Вызов: Shipment::onBasketModify
public function onBasketModify($action, BasketItem $basketItem, $name = null, $oldValue = null, $value = null)
{
$result = new Result();
if ($action === EventActions::ADD)
{
if (!$this->isSystem())
{
return $result;
}
return $this->getShipmentItemCollection()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
}
elseif ($action === EventActions::UPDATE)
{
if ($name === "QUANTITY")
{
if ($this->isSystem())
{
return $this->syncQuantityAfterModify($basketItem, $value, $oldValue);
}
/** @var ShipmentItemCollection $shipmentItemCollection */
$shipmentItemCollection = $this->getShipmentItemCollection();
$r = $shipmentItemCollection->onBasketModify($action, $basketItem, $name, $oldValue, $value);
if ($r->isSuccess())
{
if (!$this->isCustomPrice())
{
$deliveryCalculate = $this->calculateDelivery();
if ($deliveryCalculate->isSuccess())
{
$this->setField('BASE_PRICE_DELIVERY', $deliveryCalculate->getPrice());
}
else
{
$result->addWarnings($deliveryCalculate->getErrors());
}
}
}
else
{
$result->addErrors($r->getErrors());
}
}
elseif ($name === 'WEIGHT')
{
if (!$this->isMarkedFieldCustom('WEIGHT'))
{
if ($this->getShipmentItemCollection()->isExistBasketItem($basketItem))
{
$this->setField('WEIGHT', $this->getShipmentItemCollection()->getWeight());
}
}
}
elseif ($name === 'PRICE')
{
if (!$this->isCustomPrice())
{
if ($this->getShipmentItemCollection()->isExistBasketItem($basketItem))
{
$r = $this->calculateDelivery();
if ($r->isSuccess())
{
$this->setField('BASE_PRICE_DELIVERY', $r->getPrice());
}
else
{
$result->addErrors($r->getErrors());
}
}
}
}
}
return $result;
}