/**
  * Check if Cart is Valid for Condition
  *
  * @param Cart $cart
  * @param PriceRule $priceRule
  * @param bool|false $throwException
  * @return bool
  * @throws \Exception
  */
 public function checkCondition(Cart $cart, PriceRule $priceRule, $throwException = false)
 {
     //Check Cart Amount
     if ($this->getMinAmount() > 0) {
         $minAmount = $this->getMinAmount();
         $minAmount = Tool::convertToCurrency($minAmount, $this->getCurrency(), Tool::getCurrency());
         $cartTotal = $cart->getSubtotal();
         if ($minAmount > $cartTotal) {
             if ($throwException) {
                 throw new \Exception("You have not reached the minimum amount required to use this voucher");
             } else {
                 return false;
             }
         }
     }
     return true;
 }
示例#2
0
 /**
  * Calculate discount
  *
  * @param CoreShopCart $cart
  * @return int
  */
 public function getDiscount(CoreShopCart $cart)
 {
     $discount = Tool::convertToCurrency($this->getGift()->getProductPrice(), Tool::getCurrency());
     return $discount;
 }
 /**
  * Calculate discount
  *
  * @param Model\Object\CoreShopCart $cart
  * @return int
  */
 public function getDiscount(Model\Object\CoreShopCart $cart)
 {
     return Tool::convertToCurrency($this->getAmount(), $this->getCurrency(), Tool::getCurrency());
 }
 /**
  * Calculate Product Price
  *
  * @depcreated: Should be replaced with PriceRules
  *
  * @return float|mixed
  * @throws \Exception
  */
 public function getProductPrice()
 {
     $cacheKey = "coreshop_product_price_" . $this->getId();
     if ($price = \Pimcore\Model\Cache::load($cacheKey)) {
         return $price;
     }
     $price = $this->getPrice();
     if (count($this->getSpecificPrice()) > 0) {
         $session = Tool::getSession();
         //Process Specific Prices
         foreach ($this->getSpecificPrice() as $sPrice) {
             $date = \Zend_Date::now();
             $hasCustomer = false;
             $hasCountry = false;
             $hasCurrency = false;
             if ($sPrice->getFrom() instanceof \Zend_Date) {
                 if ($date->get(\Zend_Date::TIMESTAMP) < $sPrice->getFrom()->get(\Zend_Date::TIMESTAMP)) {
                     continue;
                 }
             }
             if ($sPrice->getTo() instanceof \Zend_Date) {
                 if ($date->get(\Zend_Date::TIMESTAMP) > $sPrice->getTo()->get(\Zend_Date::TIMESTAMP)) {
                     continue;
                 }
             }
             if (count($sPrice->getCustomers()) > 0 && $session->user instanceof CoreShopUser) {
                 foreach ($sPrice->getCustomers() as $cust) {
                     if ($cust->getId() == $session->user->getId()) {
                         $hasCustomer = true;
                     }
                 }
             } else {
                 if (count($sPrice->getCustomers()) == 0) {
                     //Non is selected means all Users
                     $hasCustomer = true;
                 }
             }
             if (count($sPrice->getCountries()) > 0 && Tool::objectInList(Tool::getCountry(), $sPrice->getCountries())) {
                 $hasCountry = true;
             } else {
                 if (count($sPrice->getCountries()) == 0) {
                     //Non selected means all
                     $hasCountry = true;
                 }
             }
             if (count($sPrice->getCurrencies()) > 0 && Tool::objectInList(Tool::getCurrency(), $sPrice->getCurrencies())) {
                 $hasCurrency = true;
             } else {
                 if (count($sPrice->getCountries()) == 0) {
                     //Non selected means all
                     $hasCurrency = true;
                 }
             }
             if ($hasCountry && $hasCustomer && $hasCurrency) {
                 $price = $this->applySpecificPrice($sPrice);
                 break;
             }
         }
     }
     return Tool::convertToCurrency($price);
 }