Exemple #1
0
 /**
  * Save discount result.
  *
  * @return Result
  * @throws Main\ArgumentNullException
  */
 public function save()
 {
     $process = true;
     $result = new Result();
     $order = $this->getOrder();
     if ($order === null) {
         throw new Main\ArgumentNullException('order');
     }
     if (Compatible\DiscountCompatibility::isInited()) {
         $basket = $order->getBasket();
         if (!count($basket)) {
             return $result;
         }
         unset($basket);
         if (Compatible\DiscountCompatibility::isSaved()) {
             return $result;
         }
         $compatibleResult = Compatible\DiscountCompatibility::getResult();
         if ($compatibleResult === false) {
             return $result;
         }
         if (empty($compatibleResult)) {
             return $result;
         }
         $this->setUseMode($compatibleResult['CALCULATE']['USE_MODE']);
         $this->newOrder = $compatibleResult['CALCULATE']['NEW_ORDER'];
         $this->basketBasePrice = $compatibleResult['BASE_PRICE'];
         $this->discountsCache = $compatibleResult['DISCOUNT_LIST'];
         $this->couponsCache = $compatibleResult['COUPONS_LIST'];
         $this->discountResult = $compatibleResult['DISCOUNT_RESULT'];
         if ($this->newOrder) {
             $shipmentResult = $this->loadShipment();
             if (!$shipmentResult->isSuccess()) {
             }
             unset($shipmentResult);
             $this->fillShipmentData();
         }
         unset($compatibleResult);
     }
     if ($this->newOrder === null) {
         $process = false;
         $result->addError(new Main\Entity\EntityError(Loc::getMessage('BX_SALE_DISCOUNT_ERR_NEW_ORDER_IS_NULL'), self::ERROR_ID));
     }
     if ($this->getUseMode() === null) {
         return $result;
     }
     if ($process) {
         switch ($this->getUseMode()) {
             case self::USE_MODE_FULL:
                 $saveResult = $this->saveFull();
                 break;
             case self::USE_MODE_APPLY:
                 $saveResult = $this->saveApply();
                 break;
             case self::USE_MODE_MIXED:
                 $saveResult = $this->saveMixed();
                 break;
             default:
                 $saveResult = new Result();
                 $saveResult->addError(new Main\Entity\EntityError(Loc::getMessage('BX_SALE_DISCOUNT_ERR_BAD_USE_MODE'), self::ERROR_ID));
         }
         if (!$saveResult->isSuccess()) {
             $result->addErrors($saveResult->getErrors());
         }
         unset($saveResult);
     }
     if (Compatible\DiscountCompatibility::isInited()) {
         if ($result->isSuccess()) {
             Compatible\DiscountCompatibility::setSaved(true);
         }
     }
     return $result;
 }