</li> </ul> </form> <?php } else { ?> <p style='color: red;'><?php _e('You must have entered at least one shipping method before you can configure these settings.', 'cart66'); ?> </p> <?php } ?> <?php $rules = $rule->getModels(null, 'order by min_amount'); if (count($rules)) { ?> <table class="widefat" style='width: auto;'> <thead> <tr> <th><?php _e('Minimum cart amount', 'cart66'); ?> </th> <th><?php _e('Shipping method', 'cart66'); ?> </th> <th><?php _e('Shipping cost', 'cart66');
public function getShippingCost($methodId = null) { $setting = new Cart66Setting(); $shipping = null; if (!$this->requireShipping()) { $shipping = 0; } elseif (Cart66Session::get('Cart66LiveRates') && get_class(Cart66Session::get('Cart66LiveRates')) == 'Cart66LiveRates' && Cart66Setting::getValue('use_live_rates')) { $liveRate = Cart66Session::get('Cart66LiveRates')->getSelected(); if (is_numeric($liveRate->rate)) { $r = $liveRate->rate; return number_format($r, 2, '.', ''); } } else { if ($methodId > 0) { $this->_shippingMethodId = $methodId; } if ($this->_shippingMethodId < 1) { $this->_setDefaultShippingMethodId(); } else { // make sure shipping method exists otherwise reset to the default shipping method $method = new Cart66ShippingMethod(); if (!$method->load($this->_shippingMethodId) || !empty($method->code)) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Resetting the default shipping method id"); $this->_setDefaultShippingMethodId(); } } $methodId = $this->_shippingMethodId; // Check for shipping rules first $shipping = 0; $isRuleSet = false; $rule = new Cart66ShippingRule(); if (isset($methodId) && is_numeric($methodId)) { $rules = $rule->getModels("where shipping_method_id = {$methodId}", 'order by min_amount desc'); if (count($rules)) { $cartTotal = $this->getSubTotal(); foreach ($rules as $rule) { if ($cartTotal > $rule->minAmount) { $shipping = $rule->shippingCost; $isRuleSet = true; break; } } } } if (!$isRuleSet) { $product = new Cart66Product(); $shipping = 0; $highestShipping = 0; $bundleShipping = 0; $highestId = 0; foreach ($this->_items as $item) { $product->load($item->getProductId()); if ($highestId < 1) { $highestId = $product->id; } if ($product->isShipped()) { $shippingPrice = $product->getShippingPrice($methodId); $bundleShippingPrice = $product->getBundleShippingPrice($methodId); if ($shippingPrice > $highestShipping) { $highestShipping = $shippingPrice; $highestId = $product->id; } $bundleShipping += $bundleShippingPrice * $item->getQuantity(); } } if ($highestId > 0) { $product->load($highestId); $shippingPrice = $product->getShippingPrice($methodId); $bundleShippingPrice = $product->getBundleShippingPrice($methodId); $shipping = $shippingPrice + ($bundleShipping - $bundleShippingPrice); } } } $shipping = $shipping < 0 ? 0 : $shipping; return number_format($shipping, 2, '.', ''); }