greko_1905 Posted April 14, 2021 Share Posted April 14, 2021 Hello, Using Prestashop 1.7.6.7 In my shop, no matter how many items are in the shopping cart, only the largest weight should be selected --> so that you just pay the delivery for the largest product. I found the calculation of the shipping costs in the file classes/cart.php. I changed SELECT SUM((p.`weight` + pa.`weight`) * cp.`quantity`) as nb --> to --> SELECT MAX(p.`weight`) as nb Also rewrote the public function getTotalWeight($products = null) The most time it works that the largest weight is selected, but for certain products it crash and the wrong shipping category will selected. I hope someone can help me and sorry for my english. Here you can see the rewrited code of the cart.php at row 3678. Quote public function getTotalWeight($products = null) { if (null !== $products) { $total_weight = 0; foreach ($products as $product) { if (!isset($product['weight_attribute']) || null === $product['weight_attribute']) { $total_weight += $product['weight']; } else { $total_weight = $product['weight_attribute']; } } return $total_weight; } if (!isset(self::$_totalWeight[$this->id])) { $this->updateProductWeight($this->id); } return self::$_totalWeight[(int) $this->id]; } /** * @param int $productId */ protected function updateProductWeight($productId) { $productId = (int) $productId; if (Combination::isFeatureActive()) { $weight_product_with_attribute = Db::getInstance()->getValue(' SELECT MAX(p.`weight`) 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` = ' . $productId); } else { $weight_product_with_attribute = 0; } $weight_product_without_attribute = Db::getInstance()->getValue(' SELECT MAX(p.`weight`) 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` = ' . $productId); $weight_cart_customizations = Db::getInstance()->getValue(' SELECT MAX(cd.`weight`) FROM `' . _DB_PREFIX_ . 'customization` c LEFT JOIN `' . _DB_PREFIX_ . 'customized_data` cd ON (c.`id_customization` = cd.`id_customization`) WHERE c.`in_cart` = 1 AND c.`id_cart` = ' . $productId); self::$_totalWeight[$productId] = round( (float) $weight_product_with_attribute + (float) $weight_product_without_attribute + (float) $weight_cart_customizations, 6 ); } Link to comment Share on other sites More sharing options...
greko_1905 Posted April 15, 2021 Author Share Posted April 15, 2021 Hello Noboby here who know whats wrong is? 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