- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/discountbase.php
- Класс: BitrixSaleDiscountBase
- Вызов: DiscountBase::saveFull
protected function saveFull()
{
$result = new Result;
$process = true;
$orderId = $this->getOrder()->getId();
/** @var OrderDiscount $storageClassName */
$storageClassName = $this->getOrderDiscountClassName();
/** @var DiscountCouponsManager $couponClassName */
$couponClassName = $this->getDiscountCouponClassName();
/** @var EntityMarker $entityMarkerClassName */
$entityMarkerClassName = $this->getEntityMarkerClassName();
if (!CompatibleDiscountCompatibility::isUsed() || !CompatibleDiscountCompatibility::isInited())
{
$basketResult = $this->getBasketTables();
if (!$basketResult->isSuccess())
{
$process = false;
$result->addErrors($basketResult->getErrors());
}
}
if ($process)
{
$couponClassName::finalApply();
$couponsResult = $couponClassName::saveApplied();
if (!$couponsResult->isSuccess())
{
$process = false;
$error = new MainError(
$this->prepareCouponsResult($couponsResult)
);
$result->addError($error);
$markerResult = new Result();
$markerResult->addWarning($error);
$markerResult->addWarning(new MainError(
Loc::getMessage('BX_SALE_DISCOUNT_ERR_BAD_PRICES')
));
$entityMarkerClassName::addMarker(
$this->getOrder(),
$this->getOrder(),
$markerResult
);
unset($markerResult, $error);
}
}
if ($process)
{
$couponsResult = $this->saveCoupons();
if (!$couponsResult->isSuccess())
{
$process = false;
$result->addErrors($couponsResult->getErrors());
}
}
if ($process)
{
$storageClassName::deleteByOrder($orderId);
$lastApplyBlockResult = $this->saveLastApplyBlock();
if (!$lastApplyBlockResult->isSuccess())
{
$process = false;
$result->addErrors($lastApplyBlockResult->getErrors());
}
unset($lastApplyBlockResult);
}
if ($process)
{
$config = $this->getOrderConfig();
$dataResult = $storageClassName::saveOrderStoredData(
$orderId,
$storageClassName::STORAGE_TYPE_ORDER_CONFIG,
$config
);
if (!$dataResult->isSuccess())
{
$result->addError(new MainEntityEntityError(
Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
self::ERROR_ID
));
}
unset($dataResult, $config);
$config = array(
'MODE' => $this->roundApplyMode,
'CONFIG' => $this->roundApplyConfig
);
$dataResult = $storageClassName::saveOrderStoredData(
$orderId,
$storageClassName::STORAGE_TYPE_ROUND_CONFIG,
$config,
array('ALLOW_UPDATE' => 'Y')
);
if (!$dataResult->isSuccess())
{
$result->addError(new MainEntityEntityError(
Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
self::ERROR_ID
));
}
unset($dataResult, $config);
if (!empty($this->discountStoredActionData))
{
$dataResult = $storageClassName::saveOrderStoredData(
$orderId,
$storageClassName::STORAGE_TYPE_DISCOUNT_ACTION_DATA,
$this->discountStoredActionData,
array('ALLOW_UPDATE' => 'Y')
);
if (!$dataResult->isSuccess())
{
$result->addError(new MainEntityEntityError(
Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
self::ERROR_ID
));
}
unset($dataResult);
}
$dataResult = $this->saveBasketStoredData($this->getBasketCodes(true));
if (!$dataResult->isSuccess())
{
$result->addErrors($dataResult->getErrors());
}
unset($dataResult);
}
if ($process)
{
if ($couponClassName::usedByManager())
$couponClassName::clear(true);
}
return $result;
}