unionroom Posted October 27, 2010 Share Posted October 27, 2010 Hi.One of our clients has requested that the shipping cost of each order to just be the cost of shipping for the most expensive item.Eg: If the cost of shipping for item 1 is £5, Item 2 is £2 and item 3 is £1, the actual cost of shipping would be £5 (the most expensive shipping cost) rather than £8 (the cumulative shipping cost).Does anyone know of a module that exists or a modification I can make to my code to achieve this?Any other suggestions welcome.Thanks. Link to comment Share on other sites More sharing options...
unionroom Posted October 27, 2010 Author Share Posted October 27, 2010 I think I've just solved my own problem by changing 6 characters of code :coolsmile: In classes >> Cart.php around line 791 I just changed the query to find the max weight rather than the sum and from this it just uses the top most shipping weight. I'm not sure if this will be any use to anyone else as it's a fairly obscure way of calculating shipping but here's the code: public function getTotalWeight() { if (!$this->id) return 0; if ($this->_totalWeight) return $this->_totalWeight; $result = Db::getInstance()->getRow(' SELECT MAX((p.`weight` + pa.`weight`) * cp.`quantity`) as nb FROM `'._DB_PREFIX_.'cart_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON cp.`id_product_attribute` = pa.`id_product_attribute` WHERE (cp.`id_product_attribute` IS NOT NULL AND cp.`id_product_attribute` != 0) AND cp.`id_cart` = '.intval($this->id)); $result2 = Db::getInstance()->getRow(' SELECT MAX(p.`weight` * cp.`quantity`) as nb FROM `'._DB_PREFIX_.'cart_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` WHERE (cp.`id_product_attribute` IS NULL OR cp.`id_product_attribute` = 0) AND cp.`id_cart` = '.intval($this->id)); $this->_totalWeight = round(floatval($result['nb']) + floatval($result2['nb']), 3); return $this->_totalWeight; } All that's changed is that SUM in the first line of both queries has changed to MAX.This is using version 1.2.5 by the way. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now