moy2010 Posted April 5, 2015 Share Posted April 5, 2015 (edited) Hi, Prestashop community. I'm trying to preview the product shipping cost from the default shipping carrier. So far, I've been able to find these 2 solutions, but none of them work in prestashop 1.6: 1.- add this code to product.php: $carrier = new Carrier(33, intval($cookie->id_lang)); $shippingCost = $carrier->getDeliveryPriceByWeight($product->weight, 7); $smarty->assign('shippingCost', $shippingCost); and then this to product.tpl: {convertPrice price=$shippingCost} 2.- add this code to productcontroller.php: $id_carrier = Configuration::get('PS_CARRIER_DEFAULT'); $carrier = new Carrier((int)($id_carrier), Configuration::get('PS_LANG_DEFAULT')); $carrierTax = Tax::getCarrierTaxRate((int)$carrier->id, (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); $id_zone = (int)$defaultCountry->id_zone; $portes = $carrier->getDeliveryPriceByWeight($this->product->weight, $id_zone)*1; $portes = $portes *(1+ $carrierTax/100); self::$smarty->assign(array( 'portes' => $portes )); and then this to product.tpl: {$portes} The problem seems to be which smarty variables are been called for this. Hopefully someone else has a clue so this can be achieved. Thanks in advance. Edited April 6, 2015 by moy2010 (see edit history) Link to comment Share on other sites More sharing options...
moy2010 Posted April 6, 2015 Author Share Posted April 6, 2015 Solution provided by PascalVG (Thanks, pal!): $default_carrier =new Carrier((int)Configuration::get('PS_CARRIER_DEFAULT')); $carrier_zones = $default_carrier->getZones(); if (isset($carrier_zones) && !empty($carrier_zones)) { $first_carrier_zone = $carrier_zones[0]['id_zone']; $delivery_price = $default_carrier->getDeliveryPriceByWeight($this->product->weight, $first_carrier_zone); } else $delivery_price = 'not found'; $this->context->smarty->assign(array( 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => ($this->product->customizable) ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int)$this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => (($this->product->cache_has_attachments) ? $this->product->getAttachments($this->context->language->id) : array()), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int)$this->product->out_of_stock), 'last_qties' => (int)Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'display_qties' => (int)Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK') , // <- add comma here! 'delivery_price' => $delivery_price )); Then, in themes/<your theme folder>product.tpl, add this code wherever you need it: {if $delivery_price} <div class = "estimated_delivery_price"> {l s='Initial delivery costs estimate :'}{convertPrice price=$delivery_price} </div> {/if} 1 Link to comment Share on other sites More sharing options...
Money_Maker Posted July 31, 2015 Share Posted July 31, 2015 Solution provided by PascalVG (Thanks, pal!): $default_carrier =new Carrier((int)Configuration::get('PS_CARRIER_DEFAULT')); $carrier_zones = $default_carrier->getZones(); if (isset($carrier_zones) && !empty($carrier_zones)) { $first_carrier_zone = $carrier_zones[0]['id_zone']; $delivery_price = $default_carrier->getDeliveryPriceByWeight($this->product->weight, $first_carrier_zone); } else $delivery_price = 'not found'; $this->context->smarty->assign(array( 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => ($this->product->customizable) ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int)$this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => (($this->product->cache_has_attachments) ? $this->product->getAttachments($this->context->language->id) : array()), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int)$this->product->out_of_stock), 'last_qties' => (int)Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'display_qties' => (int)Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK') , // <- add comma here! 'delivery_price' => $delivery_price )); Then, in themes/<your theme folder>product.tpl, add this code wherever you need it: {if $delivery_price} <div class = "estimated_delivery_price"> {l s='Initial delivery costs estimate :'}{convertPrice price=$delivery_price} </div> {/if} Where does the first part needs to be added? Link to comment Share on other sites More sharing options...
joe ramires Posted January 17, 2016 Share Posted January 17, 2016 (edited) this solution has an output Initial delivery costs estimate :not found on ps 1.6.14 I need a working solution in order to show on product page a banner FREE DELIVERY Edited January 18, 2016 by joe ramires (see edit history) Link to comment Share on other sites More sharing options...
hakeryk2 Posted March 22, 2016 Share Posted March 22, 2016 this solution has an output Initial delivery costs estimate :not found on ps 1.6.14 I need a working solution in order to show on product page a banner FREE DELIVERY Same here. 1.6.1.4 1 Link to comment Share on other sites More sharing options...
StefArts Posted December 2, 2016 Share Posted December 2, 2016 this solution has an output Initial delivery costs estimate :not found on ps 1.6.14 Hello Same here 1.6.1.6 Link to comment Share on other sites More sharing options...
learner88 Posted April 19, 2017 Share Posted April 19, 2017 I want to add a specific line (i.e free delivery) on some products on product page, how can i do that?? please help me out. Link to comment Share on other sites More sharing options...
Alain D. Posted June 21, 2019 Share Posted June 21, 2019 On 4/19/2017 at 7:52 AM, learner88 said: I want to add a specific line (i.e free delivery) on some products on product page, how can i do that?? please help me out. Hi if you want to display a banner on a product page depending of the product price, you can add code in header.tpl or product.tpl (depending where you want to display the banner) with a : {if $productPrice > 600} <div id="my-banner">Free delivery !</div> {/if} Link to comment Share on other sites More sharing options...
pixelbee Posted April 23, 2020 Share Posted April 23, 2020 On 4/6/2015 at 9:08 AM, moy2010 said: Solution provided by PascalVG (Thanks, pal!): $default_carrier =new Carrier((int)Configuration::get('PS_CARRIER_DEFAULT')); $carrier_zones = $default_carrier->getZones(); if (isset($carrier_zones) && !empty($carrier_zones)) { $first_carrier_zone = $carrier_zones[0]['id_zone']; $delivery_price = $default_carrier->getDeliveryPriceByWeight($this->product->weight, $first_carrier_zone); } else $delivery_price = 'not found'; $this->context->smarty->assign(array( 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => ($this->product->customizable) ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int)$this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => (($this->product->cache_has_attachments) ? $this->product->getAttachments($this->context->language->id) : array()), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int)$this->product->out_of_stock), 'last_qties' => (int)Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'display_qties' => (int)Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK') , // <- add comma here! 'delivery_price' => $delivery_price )); Then, in themes/<your theme folder>product.tpl, add this code wherever you need it: {if $delivery_price} <div class = "estimated_delivery_price"> {l s='Initial delivery costs estimate :'}{convertPrice price=$delivery_price} </div> {/if} My product have attribute with impact on weight, how to calcute the shipping price based also on attribute weight? 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