private function _calculate($set_shipping = true, $generate_id = true) { global $lC_Currencies, $lC_Tax, $lC_Weight, $lC_Shipping, $lC_Database, $lC_OrderTotal, $lC_Services, $lC_Coupons, $lC_Vqmod, $lC_Customer; $this->_sub_total = 0; $this->_total = 0; $this->_weight = 0; $this->_tax = 0; $this->_tax_groups = array(); $this->_shipping_boxes_weight = 0; $this->_shipping_boxes = 0; $this->_shipping_quotes = array(); $this->_order_totals = array(); if ($generate_id) { $_SESSION['cartID'] = $this->generateCartID(); } if ($this->hasContents()) { foreach ($this->_contents as $data) { $products_weight = $lC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT); $this->_weight += $products_weight * $data['quantity']; if ($lC_Customer->isLoggedOn()) { $tax = $lC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id')); $tax_description = $lC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id')); } $shown_price = $lC_Currencies->addTaxRateToPrice($data['price'], $tax, $data['quantity']); $this->_sub_total += $shown_price; $this->_total += $shown_price; if (DISPLAY_PRICE_WITH_TAX == '1' || $_SESSION['localization']['show_tax'] == 1) { $tax_amount = $shown_price - $shown_price / ($tax < 10 ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax)); } else { $tax_amount = $tax / 100 * $shown_price; $this->_total += $tax_amount; } $this->_tax += $tax_amount; if (isset($this->_tax_groups[$tax_description])) { $this->_tax_groups[$tax_description] += $tax_amount; } else { $this->_tax_groups[$tax_description] = $tax_amount; } } // coupons if (defined('MODULE_SERVICES_INSTALLED') && in_array('coupons', explode(';', MODULE_SERVICES_INSTALLED)) && isset($lC_Coupons)) { if ($lC_Coupons->hasContents()) { $discount = $lC_Coupons->getTotalDiscount(); $this->_total -= $discount; } } $this->_shipping_boxes_weight = $this->_weight; $this->_shipping_boxes = 1; if (SHIPPING_BOX_WEIGHT >= $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100) { $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT; } else { $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100; } if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT); $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes; } if ($set_shipping === true) { if (!class_exists('lC_Shipping')) { include $lC_Vqmod->modCheck('includes/classes/shipping.php'); } if (!$this->hasShippingMethod() || $this->getShippingMethod('is_cheapest') === true) { $lC_Shipping = new lC_Shipping(); $this->setShippingMethod($lC_Shipping->getCheapestQuote(), false); } else { $lC_Shipping = new lC_Shipping($this->getShippingMethod('id')); $this->setShippingMethod($lC_Shipping->getQuote(), false); } } if (!class_exists('lC_OrderTotal')) { include $lC_Vqmod->modCheck('includes/classes/order_total.php'); } $lC_OrderTotal = new lC_OrderTotal(); $this->_order_totals = $lC_OrderTotal->getResult(); // sanity recalc total $tkey = ''; $ot_total = 0; foreach ($this->_order_totals as $key => $ot) { if ($ot['code'] != 'total') { $ot_total = $ot_total + $ot['value']; $_SESSION['lC_ShoppingCart_data']['order_totals'][$key]['text'] = $lC_Currencies->format($ot['value']); } else { $tkey = $key; } } $_SESSION['lC_ShoppingCart_data']['order_totals'][$tkey]['text'] = $lC_Currencies->format($ot_total); $_SESSION['lC_ShoppingCart_data']['order_totals'][$tkey]['value'] = $ot_total; // coupons if (defined('MODULE_SERVICES_INSTALLED') && in_array('coupons', explode(';', MODULE_SERVICES_INSTALLED)) && isset($lC_Coupons)) { $lC_Coupons->displayCouponInOrderTotal(); } } }
public function lC_Checkout_Shipping() { global $lC_Database, $lC_ShoppingCart, $lC_Customer, $lC_Services, $lC_Language, $lC_NavigationHistory, $lC_Breadcrumb, $lC_Shipping, $lC_MessageStack, $lC_Vqmod; require_once $lC_Vqmod->modCheck('includes/classes/address_book.php'); /*VQMOD-002*/ if ($lC_Customer->isLoggedOn() === false) { $lC_NavigationHistory->setSnapshot(); lc_redirect(lc_href_link(FILENAME_ACCOUNT, 'login', 'SSL')); } if ($lC_ShoppingCart->hasContents() === false) { lc_redirect(lc_href_link(FILENAME_CHECKOUT, null, 'SSL')); } // if the order contains only virtual products, forward the customer to the billing page as a shipping address is not needed if ($lC_ShoppingCart->getContentType() == 'virtual' || defined('SKIP_CHECKOUT_SHIPPING_PAGE') && SKIP_CHECKOUT_SHIPPING_PAGE == '1') { lc_redirect(lc_href_link(FILENAME_CHECKOUT, 'payment', 'SSL')); } $this->_page_title = $lC_Language->get('shipping_method_heading'); if ($lC_Services->isStarted('breadcrumb')) { $lC_Breadcrumb->add($lC_Language->get('breadcrumb_checkout_shipping'), lc_href_link(FILENAME_CHECKOUT, $this->_module, 'SSL')); } if ($lC_Customer->hasDefaultAddress() === false) { if (isset($_GET['account_created'])) { lc_redirect(lc_href_link(FILENAME_CHECKOUT, 'shipping_address&account_created=true', 'SSL')); } else { lc_redirect(lc_href_link(FILENAME_CHECKOUT, 'shipping_address', 'SSL')); } } else { if (file_exists('templates/' . $this->getCode() . '/javascript/shipping.js.php')) { $this->addJavascriptPhpFilename('templates/' . $this->getCode() . '/javascript/shipping.js.php'); } // if no shipping destination address was selected, use the customers own address as default if ($lC_ShoppingCart->hasShippingAddress() === false) { $lC_ShoppingCart->setShippingAddress($lC_Customer->getDefaultAddressID()); } else { // verify the selected shipping address $Qcheck = $lC_Database->query('select address_book_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id limit 1'); $Qcheck->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); $Qcheck->bindInt(':address_book_id', $lC_ShoppingCart->getShippingAddress('id')); $Qcheck->bindInt(':customers_id', $lC_Customer->getID()); $Qcheck->execute(); if ($Qcheck->numberOfRows() !== 1) { $lC_ShoppingCart->setShippingAddress($lC_Customer->getDefaultAddressID()); } } // load all enabled shipping modules if (class_exists('lC_Shipping') === false) { include $lC_Vqmod->modCheck('includes/classes/shipping.php'); } $lC_Shipping = new lC_Shipping(); // if no shipping method has been selected, automatically select the cheapest method. if ($lC_ShoppingCart->hasShippingMethod() === false) { if ($lC_Shipping->numberOfQuotes() === 1) { $lC_ShoppingCart->setShippingMethod($lC_Shipping->getFirstQuote(), false); } else { $lC_ShoppingCart->setShippingMethod($lC_Shipping->getCheapestQuote()); } } } if ($_GET[$this->_module] == 'process') { $this->_process(); } }