コード例 #1
0
 /**
  * Return a boolean indicating whether the condition has been met
  *
  * @return bool
  */
 public function met()
 {
     $currency = $this->currencyService->getActiveCurrency();
     $activeCurrencyCode = $currency->getCurrencyCode();
     if (isset($this->amounts[$activeCurrencyCode])) {
         $total = $this->dealHandler->getPurchasablesTotalWithDiscounts($this->purchasableHolder->getPurchasables());
         $amount = \Heystack\Ecommerce\convertStringToMoney($this->amounts[$activeCurrencyCode], $currency);
         return $total->greaterThanOrEqual($amount);
     }
     return false;
 }
 /**
  * @return \SebastianBergmann\Money\Money
  */
 public function getDiscountPrice()
 {
     $currency = $this->getCurrencyService()->getActiveCurrency();
     return \Heystack\Ecommerce\convertStringToMoney($this->{$currency->getCurrencyCode() . 'PriceDiscounted'}, $currency);
 }
コード例 #3
0
 /**
  * @return \SebastianBergmann\Money\Money
  */
 public function getCost()
 {
     $currency = $this->currencyService->getActiveCurrency();
     $currencyCode = $currency->getCurrencyCode();
     if ($this->config && isset($this->config[$currencyCode][self::CONFIG_PRICE_KEY])) {
         return \Heystack\Ecommerce\convertStringToMoney($this->config[$currencyCode][self::CONFIG_PRICE_KEY], $currency);
     } else {
         return $this->currencyService->getZeroMoney();
     }
 }
コード例 #4
0
 /**
  * @param \Heystack\Deals\Interfaces\DealPurchasableInterface $purchasable
  * @return \SebastianBergmann\Money\Money
  */
 protected function getDealDiscountForPurchasable(DealPurchasableInterface $purchasable)
 {
     $purchasableTotal = $purchasable->getTotal();
     $purchasableCurrentDiscount = $purchasable->getDealDiscountWithExclusions([$this->getDealHandler()->getIdentifier()->getFull()]);
     if (is_array($this->discountAmounts) && count($this->discountAmounts)) {
         $currency = $this->currencyService->getActiveCurrency();
         $currencyCode = $currency->getCurrencyCode();
         if ($this->discountAmounts[$currencyCode]) {
             $purchasableDiscount = \Heystack\Ecommerce\convertStringToMoney($this->discountAmounts[$currencyCode], $currency);
             $purchasableDiscount = $purchasableDiscount->multiply($purchasable->getQuantity());
         } else {
             $purchasableDiscount = $this->currencyService->getZeroMoney();
         }
     } elseif ($this->discountPercentage) {
         list($purchasableDiscount, ) = $purchasableTotal->allocateByRatios([$this->discountPercentage, 100 - $this->discountPercentage]);
     } else {
         $purchasableDiscount = $this->currencyService->getZeroMoney();
     }
     if ($purchasableCurrentDiscount->add($purchasableDiscount)->greaterThan($purchasableTotal)) {
         $dealDiscount = $purchasableTotal->subtract($purchasableCurrentDiscount);
     } else {
         $dealDiscount = $purchasableDiscount;
     }
     return $dealDiscount;
 }
コード例 #5
0
 /**
  * @return \SebastianBergmann\Money\Money
  */
 public function getPrice()
 {
     $currency = $this->getCurrencyService()->getActiveCurrency();
     return \Heystack\Ecommerce\convertStringToMoney($this->getField($currency->getCurrencyCode() . 'Price'), $currency);
 }
コード例 #6
0
 /**
  * @return \SebastianBergmann\Money\Money
  */
 protected function getTotal()
 {
     $discount = $this->currencyService->getZeroMoney();
     $total = $this->dealHandler->getPurchasablesTotalWithDiscounts($this->purchasableHolder->getPurchasables());
     if ($this->discountAmounts) {
         $currency = $this->currencyService->getActiveCurrency();
         $currencyCode = $currency->getCurrencyCode();
         if (isset($this->discountAmounts[$currencyCode])) {
             $discount = \Heystack\Ecommerce\convertStringToMoney($this->discountAmounts[$currencyCode], $currency);
         }
         // This ensures that we aren't taking off more than the allowed amount
         if ($discount->greaterThan($total)) {
             $discount = $total;
         }
     }
     if ($this->discountPercentage) {
         list($discount, ) = $total->allocateByRatios([$this->discountPercentage, 100 - $this->discountPercentage]);
     }
     if ($discount instanceof Money) {
         $purchasables = $this->purchasableHolder->getPurchasables();
         $dealIdentifier = $this->getDealHandler()->getIdentifier();
         $dealIdentifierFull = $dealIdentifier->getFull();
         foreach ($purchasables as $purchasable) {
             if ($purchasable instanceof DealPurchasableInterface) {
                 $purchasableAmount = $purchasable->getTotal()->subtract($purchasable->getDealDiscountWithExclusions([$dealIdentifierFull]));
                 $discountRatio = $purchasableAmount->getAmount() / $total->getAmount();
                 list($purchasableDiscount, ) = $discount->allocateByRatios([$discountRatio, 1 - $discountRatio]);
                 $purchasable->setDealDiscount($dealIdentifier, $purchasableDiscount);
             }
         }
         return $discount;
     }
     return $this->currencyService->getZeroMoney();
 }
コード例 #7
0
 /**
  * @return \SebastianBergmann\Money\Money
  */
 protected function getTotal()
 {
     $total = $this->shippingHandler->getTotal();
     if ($this->isFree) {
         return $total;
     }
     if ($this->discountAmounts) {
         $currency = $this->currencyService->getActiveCurrency();
         $currencyCode = $currency->getCurrencyCode();
         if (isset($this->discountAmounts[$currencyCode])) {
             $newTotal = \Heystack\Ecommerce\convertStringToMoney($this->discountAmounts[$currencyCode], $currency);
             if ($newTotal->greaterThan($total)) {
                 return $total;
             } else {
                 return $newTotal;
             }
         } else {
             return $this->currencyService->getZeroMoney();
         }
     }
     if ($this->discountPercentage) {
         list($newTotal, ) = $total->allocateByRatios([$this->discountPercentage, 100 - $this->discountPercentage]);
         return $newTotal;
     }
     return $this->currencyService->getZeroMoney();
 }