/** * This method Check method is applicable or not (Min & max amount) etc.. * * @param object $vars gives billing, shipping, item_id, methodId(unique plug shipping method id) etc. * * @since 2.2 * @return Shipping charges. */ function getApplicableShipMethRateDetail($vars, $shipMethDetail) { // Get zone id from address $shipMethId = $vars->shipMethId; $shipping_address = $vars->shipping_address; // Get item cart detail $cartItemDetail = $vars->cartItemDetail; $currency = $cartItemDetail['currency']; $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('mr.id AS rateId'); $query->from('#__kart_zonerules AS zr'); $query->join('LEFT', '#__kart_zoneShipMethodRates AS mr ON mr.zone_id = zr.zone_id'); $query->where('mr.methodId=' . $shipMethId); $applicable = 0; if (!empty($shipMethDetail)) { if ($shipMethDetail['shipping_type'] == 1) { // Check wether quantity is within rage if ($shipMethDetail['min_value'] <= $cartItemDetail['qty'] && ((int) $shipMethDetail['max_value'] == -1 || $cartItemDetail['qty'] <= $shipMethDetail['max_value'])) { $applicable = 1; } $query->where('mr.rangeFrom <=' . $cartItemDetail['qty']); $query->where('mr.rangeTo >=' . $cartItemDetail['qty']); } elseif ($shipMethDetail['shipping_type'] == 2) { // ship method type= weight $qtcshiphelper = new qtcshiphelper(); $productDetail = $vars->productDetail; // Get product wt and weight class id $itemWt = $productDetail['item_weight']; $itemWt = $itemWt * $cartItemDetail['qty']; $fromWtClass = $productDetail['item_weight_class_id']; // get KG weiht class id $toWtClassid = $qtcshiphelper->getWeightDetailFromUnite('kg'); // Convert item weight $newItemWt = (double) $qtcshiphelper->convertWeight($itemWt, $fromWtClass, $toWtClassid['id']); // Check whether mehod if ((double) $shipMethDetail['min_value'] <= $newItemWt && ((int) $shipMethDetail['max_value'] == -1 || $newItemWt <= (double) $shipMethDetail['max_value'])) { $applicable = 1; } $query->where('mr.rangeFrom <=' . $newItemWt); $query->where('mr.rangeTo >=' . $newItemWt); // Get applicable rate } else { // For flat rate pers store method. Get methods price rel things $methDetail = $this->getPriceRelMethDetail($shipMethId, $currency); // For flat rate per store item price. if ($methDetail['min_value'] <= $cartItemDetail['tamt'] && ((int) $methDetail['max_value'] == -1 || $cartItemDetail['tamt'] <= $methDetail['max_value'])) { $applicable = 1; } // Range field are not present for flat rate per store method } } // If method is not applicable if ($applicable == 0) { return false; } $query->where('zr.country_id=' . (int) $shipping_address['country']); $query->where("( zr.region_id = 0 OR zr.region_id = " . (int) $shipping_address['state'] . ')'); $db->setQuery($query); $rateId = $db->loadResult(); // If rate is not i.e not applicable if (empty($rateId)) { return false; } // Get method rate details; return $shipMethRateDetail = $this->getShipMethRateDetail($rateId, $currency); }