/** * This function will check against the rules if there is any remaining amount to the cart, in order to get the free shipping. * @param ISC_QUOTE $quote The quote object that used to check the free shipping eligibility * @return boolean Return true if there is we found free shipping eligibility. Otherwise, return false */ public function checkFreeShippingEligibility(ISC_QUOTE $quote) { foreach($quote->getItems() as $item) { if($quote->getBaseSubTotal() < $this->amount) { $remainingAmount = $this->amount - $quote->getBaseSubTotal(); $productName = $item->getName(); $placeHolders = array( '%%PRODUCT_NAME%%' => $productName, '%%REMAINING_QUANTITY%%' => '', '%%TOTAL_QUANTITY%%' => $this->amount, '%%CART_QUANTITY%%' => $item->getQuantity(), '%%REMAINING_AMOUNT%%' => CurrencyConvertFormatPrice($remainingAmount), '%%TOTAL_AMOUNT%%' => CurrencyConvertFormatPrice($this->amount), '%%CART_AMOUNT%%' => CurrencyConvertFormatPrice($quote->getBaseSubTotal()), ); $this->freeShippingEligibilityData = array( 'message' => str_replace(array_keys($placeHolders), array_values($placeHolders), $this->freeShippingMessage), 'location' => $this->freeShippingMessageLocation, 'name' => $this->getName(), ); return true; } } return false; }
public function applyRule(ISC_QUOTE $quote) { if($quote->getBaseSubTotal() < $this->amount) { return false; } $runningTotal = $this->amount_off; $items = $quote->getItems(); foreach ($items as $item) { $discountedBase = $item->getDiscountedBaseTotal(); if($discountedBase - $runningTotal < 0) { $item->addDiscount($this->getDbId(), $discountedBase); $runningTotal -= $discountedBase; } else { $item->addDiscount($this->getDbId(), $runningTotal); $runningTotal -= $runningTotal; } if($runningTotal <= 0) { break; } } $quote->addDiscount($this->getDbId(), $this->amount_off); $amountOff = currencyConvertFormatPrice($this->amount_off); $amount = currencyConvertFormatPrice($this->amount); $this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $amountOff, $amount); return true; }