public function applyRule(ISC_QUOTE $quote) { if (!customerIsSignedIn()) { return null; } $customerId = getClass('ISC_CUSTOMER')->getCustomerId(); $query = " SELECT COUNT(*) FROM [|PREFIX|]orders WHERE ordcustid='".$customerId."' AND ordstatus > 0 AND deleted = 0 LIMIT 1 "; $orderCount = $GLOBALS['ISC_CLASS_DB']->fetchOne($query); // Discount does not apply if($orderCount <= $this->orders) { return false; } $items = $quote->getItems(); $totalDiscount = 0; // The discount needs to come off each item, so that tax is also affected. foreach($items as $item) { $discountAmount = $item->getDiscountedBaseTotal() * ($this->amount / 100); $item->addDiscount($this->getDbId(), $discountAmount); $totalDiscount += $discountAmount; } $quote->addDiscount($this->getDbId(), $totalDiscount); $this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $this->amount); return true; }
/** * 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; }
public function applyRule(ISC_QUOTE $quote) { $customerId = getClass('ISC_CUSTOMER')->getCustomerId(); $query = " SELECT COUNT(*) FROM [|PREFIX|]orders WHERE ordcustid='".$customerId."' AND ordstatus > 0 AND deleted = 0 LIMIT 1 "; $orderCount = $GLOBALS['ISC_CLASS_DB']->fetchOne($query); // Discount does not apply if($orderCount <= $this->orders) { return false; } $runningTotal = $this->amount; $appliedAmount = 0; $items = $quote->getItems(); foreach ($items as $item) { $discountedBase = $item->getDiscountedBaseTotal(); if($discountedBase - $runningTotal < 0) { $item->addDiscount($this->getDbId(), $discountedBase); $appliedAmount += $discountedBase; $runningTotal -= $discountedBase; } else { $item->addDiscount($this->getDbId(), $runningTotal); $appliedAmount += $runningTotal; $runningTotal -= $runningTotal; } if($runningTotal <= 0) { break; } } $quote->addDiscount($this->getDbId(), $appliedAmount); $amount = currencyConvertFormatPrice($appliedAmount); $this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $amount); return true; }
protected function generateBillingDetailsSummary(ISC_QUOTE $quote) { return $this->template->render('order.form.summary.billing.tpl', array( 'address' => $quote->getBillingAddress(), )); }
public function renderMultiShippingTable(ISC_QUOTE $quote) { if (!$quote->getIsSplitShipping()) { return false; } $unallocatedItems = array(); $allocatedItems = array(); foreach ($quote->getItems(PT_PHYSICAL) as $item) { if($item->getAddressId() == ISC_QUOTE_ADDRESS::ID_UNALLOCATED) { $unallocatedItems[] = $item; } else { $allocatedItems[] = $item; } } $context = array( 'allocatedItems' => $allocatedItems, 'unallocatedItems' => $unallocatedItems, 'shippingAddresses' => $quote->getShippingAddresses(), ); return $this->template->render('order.form.multishippingtable.tpl', $GLOBALS + $context); }
public function haltReset(ISC_QUOTE $quote) { $items = $quote->getItems(); foreach($items as $item) { if($item->getParentId() || $item->getProductId() != $this->prodids) { continue; } foreach($items as $subItem) { if($subItem->getParentId() == $item->getId()) { $quote->removeItem($subItem->getId()); } } } }
/** * This function will check against the rules if there is any related purchase can be made 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($this->prodids == $item->getProductId() && $item->getQuantity() < $this->amount) { $remainingQty = $this->amount - $item->getQuantity(); $productName = $item->getName(); $placeHolders = array( '%%PRODUCT_NAME%%' => $productName, '%%REMAINING_QUANTITY%%' => $remainingQty, '%%TOTAL_QUANTITY%%' => $this->amount, '%%CART_QUANTITY%%' => $item->getQuantity(), '%%REMAINING_AMOUNT%%' => '', '%%TOTAL_AMOUNT%%' => '', '%%CART_AMOUNT%%' => '', ); $this->freeShippingEligibilityData = array( 'productId' => (int)$this->prodids, 'message' => str_replace(array_keys($placeHolders), array_values($placeHolders), $this->freeShippingMessage), 'location' => $this->freeShippingMessageLocation, 'name' => $this->getName(), ); return true; } } return false; }
public static function getQuoteTotalRows(ISC_QUOTE $quote, $displayIncTax = null, $expandShipping = true) { if($displayIncTax === null) { $displayIncTax = false; if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) { $displayIncTax = true; } } $totalRows = array(); // Subtotal $totalRows['subtotal'] = array( 'label' => getLang('Subtotal'), 'value' => $quote->getSubTotal($displayIncTax) ); // Gift Wrapping $wrappingCost = $quote->getWrappingCost($displayIncTax); if($wrappingCost > 0) { $totalRows['giftWrapping'] = array( 'label' => getLang('GiftWrapping'), 'value' => $wrappingCost ); } // Coupon codes $quote->reapplyCoupons(); $coupons = $quote->getAppliedCoupons(); $freeShippingCoupons = array(); foreach($coupons as $coupon) { // Discard the coupon if it's already expired. if (isset ($coupon['expiresDate']) && $quote->isCouponExpired($coupon['expiresDate'])) { $quote->removeCoupon($coupon['code']); continue; } $couponRow = array( 'type' => 'coupon', 'label' => getLang('Coupon').' ('.$coupon['code'].')', 'value' => $coupon['totalDiscount'] * -1, 'id' => $coupon['id'], ); if (getclass('ISC_COUPON')->isFreeShippingCoupon($coupon['discountType'])) { $freeShippingCoupons['coupon-'.$coupon['id']] = $couponRow; continue; } $totalRows['coupon-'.$coupon['id']] = $couponRow; } // Discount Amount $discountAmount = $quote->getDiscountAmount(); if($discountAmount > 0){ $totalRows['discount'] = array( 'label' => getLang('Discount'), 'value' => $discountAmount * -1, ); } // Shipping & handling if(!$quote->isDigital()) { // show each shipping quote separately? if ($expandShipping) { $shippingAddresses = $quote->getShippingAddresses(); foreach($shippingAddresses as $address) { if(!$address->hasShippingMethod()) { continue; } $totalRows['shipping-'.$address->getId()] = array( 'label' => getLang('Shipping').' ('.$address->getShippingProvider().')', 'value' => $address->getNonDiscountedShippingCost($displayIncTax) ); } } else { $totalRows['shipping'] = array( 'label' => getLang('Shipping'), 'value' => $quote->getNonDiscountedShippingCost($displayIncTax), ); } // Added the free shipping coupon display below shipping cost // Only if we have free shipping coupon applied if (!empty ($freeShippingCoupons)) { foreach ($freeShippingCoupons as $key=>$val) { $totalRows[$key] = $val; } } } $handlingCost = $quote->getHandlingCost($displayIncTax); if($handlingCost > 0) { $totalRows['handling'] = array( 'label' => getLang('Handling'), 'value' => $handlingCost ); } // Taxes $taxes = array(); $includedTaxes = array(); $taxTotal = $quote->getTaxTotal(); if($taxTotal) { $taxAppend = ''; if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) { $taxAppend = ' '.getLang('IncludedInTotal'); } // Show a single summary of applied tax if(getConfig('taxChargesInCartBreakdown') == TAX_BREAKDOWN_SUMMARY) { $taxes[] = array( 'name' => getConfig('taxLabel').$taxAppend, 'total' => $taxTotal, ); } else { $taxSummary = $quote->getTaxRateSummary(); foreach($taxSummary as $taxRateName => $taxRateAmount) { if($taxRateAmount == 0) { continue; } $taxes[] = array( 'name' => $taxRateName.$taxAppend, 'total' => $taxRateAmount, ); } } if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) { $includedTaxes = $taxes; $taxes = array(); } } foreach($taxes as $id => $taxRate) { $totalRows['tax-'.$id] = array( 'label' => $taxRate['name'], 'value' => $taxRate['total'], ); } // Gift Certificates $giftCertificates = $quote->getAppliedGiftCertificates(); foreach($giftCertificates as $giftCertificate) { $totalRows['giftcertificate-'.$giftCertificate['id']] = array( 'type' => 'giftCertificate', 'label' => getLang('GiftCertificate').' ('.$giftCertificate['code'].')', 'value' => $giftCertificate['used'] * -1, 'id' => $giftCertificate['id'], ); } $totalRows['total'] = array( 'label' => getLang('GrandTotal'), 'value' => $quote->getGrandTotal($displayIncTax), ); // Included taxes foreach($includedTaxes as $id => $taxRate) { $totalRows['tax-'.$id] = array( 'label' => $taxRate['name'], 'value' => $taxRate['total'], ); } return $totalRows; }
public function applyRule(ISC_QUOTE $quote) { $found = false; $items = $quote->getItems(); $ruleCats = explode(',', $this->catids); // The discount needs to come off each item, so that tax is also affected. $totalDiscount = 0; foreach($items as $item) { $apply = false; if($item instanceof ISC_QUOTE_ITEM_GIFTCERTIFICATE) { continue; } $categoryIds = $item->getCategoryIds(); foreach($ruleCats as $categoryId) { if(!in_array($categoryId, $categoryIds) && $categoryId != 0) { continue; } $apply = true; $found[] = $categoryId; } if(!$apply) { continue; } $discountAmount = $item->getBaseTotal() * ($this->amount / 100); $discountAmount = round($discountAmount, getConfig('DecimalPlaces')); if($item->getBaseTotal() - $discountAmount < 0) { $discountAmount = 0; } $item->addDiscount($this->getDbId(), $discountAmount); $totalDiscount += $discountAmount; } if (!empty($found)) { $quote->addDiscount($this->getDbId(), $totalDiscount); $catname = ''; $catids = implode(',', $found); $query = " SELECT catname FROM [|PREFIX|]categories WHERE categoryid IN ($catids) "; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($var = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $catname[] = $var['catname']; } if (isset($catname{1})) { $this->banners[] = sprintf(GetLang($this->getName().'DiscountMessagePlural'), $this->amount, implode(' and ',$catname)); } else { $this->banners[] = sprintf(GetLang($this->getName().'DiscountMessage'), $this->amount, implode(' and ',$catname)); } return true; } return false; }
/** * Given an order ID, load the order and convert it in to a quote based off * the ISC_QUOTE class. * * @param int $orderId The order ID to load in to a quote. * @return ISC_QUOTE Quote object for the order. */ public function convertOrderToQuote($orderId, $enableDiscounts = true) { $order = GetOrder($orderId, null, null, true); if(!$order) { return false; } $quote = new ISC_QUOTE; $quote ->setDiscountsEnabled($enableDiscounts) ->setOrderId($orderId) ->setCustomerId($order['ordcustid']) ->setAppliedStoreCredit($order['ordstorecreditamount']) ->setCustomerMessage($order['ordcustmessage']) ->setStaffNotes($order['ordnotes']) ->setOrderStatus($order['ordstatus']); $billingCustomFields = array(); if($order['ordformsessionid']) { $billingCustomFields = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData( $order['ordformsessionid'], array(), FORMFIELDS_FORM_BILLING, true ); } $quote->getBillingAddress() ->setFirstName($order['ordbillfirstname']) ->setLastName($order['ordbilllastname']) ->setCompany($order['ordbillcompany']) ->setEmail($order['ordbillemail']) ->setPhone($order['ordbillphone']) ->setAddress1($order['ordbillstreet1']) ->setAddress2($order['ordbillstreet2']) ->setCity($order['ordbillsuburb']) ->setZip($order['ordbillzip']) ->setCountryByName($order['ordbillcountry']) ->setStateByName($order['ordbillstate']) ->setCustomFields($billingCustomFields); if($order['shipping_address_count'] > 1) { $quote->setIsSplitShipping(true); } // Set the shipping addresses on the quote $query = " SELECT * FROM [|PREFIX|]order_addresses a LEFT JOIN [|PREFIX|]order_shipping s ON (s.order_address_id = a.id) WHERE a.order_id='".$order['orderid']."' "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($address = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $shippingCustomFields = array(); if($address['form_session_id']) { $shippingCustomFields = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData( $address['form_session_id'], array(), FORMFIELDS_FORM_SHIPPING, true ); } $quoteAddress = new ISC_QUOTE_ADDRESS_SHIPPING; $quoteAddress ->setQuote($quote) ->setId($address['order_address_id']) ->setFirstName($address['first_name']) ->setLastName($address['last_name']) ->setCompany($address['company']) ->setEmail($address['email']) ->setPhone($address['phone']) ->setAddress1($address['address_1']) ->setAddress2($address['address_2']) ->setCity($address['city']) ->setZip($address['zip']) ->setCountryByName($address['country']) ->setStateByName($address['state']) ->setCustomFields($shippingCustomFields) ->setShippingMethod($address['base_cost'], $address['method'], $address['module'], true) ->setHandlingCost($address['base_handling_cost'], true); $quote->addShippingAddress($quoteAddress); } // Load any configurable fields for items on this order $configurableFields = array(); $query = " SELECT * FROM [|PREFIX|]order_configurable_fields WHERE orderid='".$order['orderid']."' "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($configurableField = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $quoteField = array( 'name' => $configurableField['fieldname'], 'type' => $configurableField['fieldtype'], 'fileType' => $configurableField['filetype'], 'fileOriginalName' => $configurableField['originalfilename'], 'value' => $configurableField['textcontents'] ); if($quoteField['type'] == 'file') { $quoteField['value'] = $configurableField['filename']; $quoteField['isExistingFile'] = true; } $configurableFields[$configurableField['ordprodid']][$configurableField['fieldid']] = $quoteField; } // Loop through all of the items and add them to the quote $query = " SELECT * FROM [|PREFIX|]order_products WHERE orderorderid='".$order['orderid']."' "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($product = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $variationOptions = array(); if($product['ordprodoptions']) { $variationOptions = unserialize($product['ordprodoptions']); } $configuration = array(); if(isset($configurableFields[$product['orderprodid']])) { $configuration = $configurableFields[$product['orderprodid']]; } $itemClass = 'ISC_QUOTE_ITEM'; $type = PT_PHYSICAL; if($product['ordprodtype'] == 'digital') { $type = PT_DIGITAL; } else if($product['ordprodtype'] == 'giftcertificate') { $type = PT_GIFTCERTIFICATE; $itemClass = 'ISC_QUOTE_ITEM_GIFTCERTIFICATE'; } else if (!$product['ordprodid']) { $type = PT_VIRTUAL; } $quoteItem = new $itemClass; $quoteItem ->setQuote($quote) ->setName($product['ordprodname']) ->setSku($product['ordprodsku']) ->setId($product['orderprodid']) ->setProductId($product['ordprodid']) ->setQuantity($product['ordprodqty'], false) ->setOriginalOrderQuantity($product['ordprodqty']) ->setConfiguration($configuration) ->setVariationId($product['ordprodvariationid']) ->setVariationOptions($variationOptions) ->setType($type) ->setEventName($product['ordprodeventname']) ->setAddressId($product['order_address_id']) ->setBasePrice($product['base_price'], true) ->setFixedShippingCost($product['ordprodfixedshippingcost']) ->setWeight($product['ordprodweight']) ->setInventoryCheckingEnabled(false); if ($product['applied_discounts']) { $appliedDiscounts = unserialize($product['applied_discounts']); if (!empty($appliedDiscounts)) { foreach ($appliedDiscounts as $discountId => $discountValue) { $quoteItem->addDiscount($discountId, $discountValue); } } } if($product['ordprodwrapid']) { $quoteItem->setGiftWrapping( $product['ordprodwrapid'], $product['base_wrapping_cost'], $product['ordprodwrapname'], $product['ordprodwrapmessage'] ); } if($product['ordprodeventdate']) { list($day, $month, $year) = explode('-', isc_date('d-m-Y', $product['ordprodeventdate'])); $quoteItem->setEventDate($month, $day, $year); } $quote->addItem($quoteItem, false); $quoteItem->setInventoryCheckingEnabled(true); } // Add any applied coupon codes $query = " SELECT * FROM [|PREFIX|]order_coupons WHERE ordcouporderid='".$order['orderid']."' "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($coupon = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $quoteCoupon = array( 'id' => 0, 'code' => $coupon['ordcouponcode'], 'discountType' => $coupon['ordcoupontype'], 'discountAmount' => $coupon['ordcouponamount'], 'totalDiscount' => $coupon['applied_discount'], ); $quote->addCoupon($quoteCoupon); } // Add any applied gift certificates $query = " SELECT h.*, g.giftcertcode FROM [|PREFIX|]gift_certificate_history h LEFT JOIN [|PREFIX|]gift_certificates g ON (g.giftcertid = h.histgiftcertid) WHERE historderid='".$order['orderid']."' "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($giftCertificate = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $quoteGiftCertificate = array( 'code' => $giftCertificate['giftcertcode'], 'id' => 0, 'amount' => $giftCertificate['histbalanceused'] ); $quote->addGiftCertificate($quoteGiftCertificate); } if($order['orddiscountamount'] > 0) { $quote->addDiscount('existing-discount', $order['orddiscountamount']); } return $quote; }
/** * Tests if a code is a gift certificate code. * * @param string the code to be tested * * @return array The gift certificate row data, or false on failure. */ private function isGiftCertificateCode($code) { return ISC_QUOTE::fetchGiftCertificate($code); }