コード例 #1
0
ファイル: Cart.php プロジェクト: haegyung/xe-module-shop
 /**
  * @param null $forceDiscountType Forces a specific discount type
  *
  * @return Discount|null
  * @throws Exception
  */
 public function getDiscount()
 {
     if ($this->discount) {
         return $this->discount;
     }
     require_once __DIR__ . '/../classes/Discount.php';
     $shop = new ShopInfo($this->module_srl);
     $cartValue = $this->getTotalBeforeDiscount(true);
     $discountAmount = $shop->getShopDiscountAmount();
     $discountBeforeVAT = $shop->getShopDiscountTaxPhase() == 'pre_taxes' ? true : false;
     $discountMinAmount = $shop->getShopDiscountMinAmount();
     $discountType = $shop->getShopDiscountType();
     $vat = $shop->getVAT();
     $currency = $shop->getCurrencySymbol();
     if ($discountAmount && $discountType && $discountMinAmount <= $cartValue) {
         if ($discountType == Discount::DISCOUNT_TYPE_FIXED_AMOUNT) {
             $discount = new FixedAmountDiscount($cartValue, $discountAmount, $discountMinAmount, $vat, $discountBeforeVAT, $currency);
         } elseif ($discountType == Discount::DISCOUNT_TYPE_PERCENTAGE) {
             $discount = new PercentageDiscount($cartValue, $discountAmount, $discountMinAmount, $vat, $discountBeforeVAT, $currency);
         } else {
             throw new ShopException("Unknown discount type {$discountType}");
         }
         return $this->discount = $discount;
     }
     return null;
 }