Nico Ratti Posted May 24, 2016 Share Posted May 24, 2016 (edited) Hi, I developed a module that allow users to ask for a quote of a single product. Now I need to calculate the shipping cost for the product but I can't get the shipping cost of the cart because the user ask for a quote from the product page without add it to the cart. Obviously the customer will put the shipping address before the calculation. Where I can take the shipping cost? Edited May 24, 2016 by Nico Ratti (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted May 25, 2016 Share Posted May 25, 2016 First you will need to know the shopping carrier, and then use the carrier object to get the shipping fee estimation. $carrier->getDeliveryPriceByPrice($order_total, $id_zone, $id_currency) Or $carrier->checkDeliveryPriceByPrice($id_carrier, $order_total, $id_zone, $id_currency) 1 Link to comment Share on other sites More sharing options...
Nico Ratti Posted May 27, 2016 Author Share Posted May 27, 2016 Thank you for the answer. Unfortunately my shop have a few custom carriers module installed. So I write this little script to take the cheapest shipping fees: function getShippingCost($id_product, $total_cost, $quantity, $id_country, $id_state = null, $zipcode = null, $id_lang = 1) { $product = new Product($id_product, true); $volume = $product->width * $product->height * $product->depth * $quantity; $country_iso = Country::getIsoById($id_country); $state_iso = null; if($id_state) { $sql = 'SELECT iso_code FROM '._DB_PREFIX_.'state WHERE id_state = '.$id_state; if ($row = Db::getInstance()->getRow($sql)){ $state_iso = $row['iso_code']; } } //Get all carriersModule $carriers = Carrier::getCarriers($id_lang, true, false, false, null, Carrier::CARRIERS_MODULE); $shipping_cost = false; $available_carriers = array(); foreach ($carriers as $corriere) { $carrier = new Carrier($corriere['id_carrier'], false); //get external shipping cost from module if ($carrier->shipping_external) { $module_name = $carrier->external_module_name; $module = Module::getInstanceByName($module_name); if (Validate::isLoadedObject($module)) { if (array_key_exists('id_carrier', $module)) { $module->id_carrier = $carrier->id; } $shipping_cost = $module->getOrderShippingCost(null, 0, true, $country_iso, $state_iso, $zipcode, $volume, $total_cost); // check if this carrier is available if ($shipping_cost === false) { $shipping_cost = false; } } else { $shipping_cost = false; } } if ($shipping_cost !== false) { $available_carriers[] = array('carrier_name' => '', 'shipping_cost' => Product::convertAndFormatPrice($shipping_cost)); } } // if no carriers available return false if(!sizeof($available_carriers)) return false; $cheapest = false; foreach($available_carriers as $carrier) { if($cheapest === false || $cheapest['shipping_cost'] > $carrier['shipping_cost']) $cheapest = $carrier; } return ($cheapest); } Link to comment Share on other sites More sharing options...
shokinro Posted May 28, 2016 Share Posted May 28, 2016 glad you got a solution, as long as it works. Link to comment Share on other sites More sharing options...
Rynraf Posted December 10, 2016 Share Posted December 10, 2016 Hi. I'm new in developing Prestashop area. I try to implement this code... But I don't know how I should add this function, where and how to use it in product.tpl file. Should I add this code to /classes/Product.php? I'm using Prestashop 1.6 Could you please give me some tips or give some url to any manual? Link to comment Share on other sites More sharing options...
Rynraf Posted January 5, 2017 Share Posted January 5, 2017 Could anyone give me some guides how to implement that? Link to comment Share on other sites More sharing options...
Nico Ratti Posted January 5, 2017 Author Share Posted January 5, 2017 Could anyone give me some guides how to implement that? Hi, sorry for the late reply, I used it inside a php file that trigger a "quote ticket" for the users that ask for it through a form. So I simply call it with ajax. 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