- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/order.php
- Класс: BitrixSaleOrder
- Вызов: Order::onAfterSyncPaid
private function onAfterSyncPaid($oldPaid = null)
{
$result = new Result();
$paymentCollection = $this->getPaymentCollection();
$shipmentCollection = $this->getShipmentCollection();
$orderStatus = null;
$allowSetStatus = false;
if ($oldPaid == "N")
{
if ($this->isPaid())
{
$orderStatus = $this->getStatusOnPaid();
}
elseif ($paymentCollection->hasPaidPayment())
{
$orderStatus = $this->getStatusOnPartialPaid();
}
$allowSetStatus = ($this->getField('STATUS_ID') != static::getFinalStatus());
}
if ($orderStatus !== null && $allowSetStatus)
{
if (strval($orderStatus) != '')
{
$r = $this->setField('STATUS_ID', $orderStatus);
if (!$r->isSuccess())
{
$result->addErrors($r->getErrors());
}
elseif ($r->hasWarnings())
{
$result->addWarnings($r->getWarnings());
$registry = Registry::getInstance(static::getRegistryType());
/** @var EntityMarker $entityMarker */
$entityMarker = $registry->getEntityMarkerClassName();
$entityMarker::addMarker($this, $this, $r);
$this->setField('MARKED', 'Y');
}
}
}
if (Configuration::isEnableAutomaticReservation())
{
$r = null;
if (Configuration::getProductReservationCondition() == ReserveCondition::ON_PAY)
{
if ($paymentCollection->hasPaidPayment())
{
$r = $shipmentCollection->tryReserve();
}
else
{
$r = $shipmentCollection->tryUnreserve();
}
}
elseif (Configuration::getProductReservationCondition() == ReserveCondition::ON_FULL_PAY)
{
if ($oldPaid == "N" && $this->isPaid())
{
$r = $shipmentCollection->tryReserve();
}
elseif ($oldPaid == "Y" && !$this->isPaid())
{
$r = $shipmentCollection->tryUnreserve();
}
}
if ($r !== null)
{
if (!$r->isSuccess())
{
$result->addErrors($r->getErrors());
}
elseif ($r->hasWarnings())
{
$result->addWarnings($r->getWarnings());
}
}
}
$allowDelivery = null;
if (Configuration::getAllowDeliveryOnPayCondition() === Configuration::ALLOW_DELIVERY_ON_PAY)
{
if ($oldPaid == "N" && $paymentCollection->hasPaidPayment())
{
$allowDelivery = true;
}
elseif ($oldPaid == "Y" && !$paymentCollection->hasPaidPayment())
{
$allowDelivery = false;
}
}
elseif(Configuration::getAllowDeliveryOnPayCondition() === Configuration::ALLOW_DELIVERY_ON_FULL_PAY)
{
if ($oldPaid == "N" && $this->isPaid())
{
$allowDelivery = true;
}
elseif ($oldPaid == "Y" && !$this->isPaid())
{
$allowDelivery = false;
}
}
if ($allowDelivery !== null)
{
if ($allowDelivery)
{
$r = $shipmentCollection->allowDelivery();
}
else
{
$r = $shipmentCollection->disallowDelivery();
}
if (!$r->isSuccess())
{
$result->addErrors($r->getErrors());
}
}
return $result;
}