Jump to content
  • 0
sinedo

[SOLVED] Shipping price on product page

Question

Hi,

 

I want to modify my PS 1.6 to display shipping price (best price) in product page. So I want to add this feature to exsisting product.tpl file. How can I do it?

Share this post


Link to post
Share on other sites

23 answers to this question

Recommended Posts

  • 0

Hi moy,

 

You could do something like this:

 

Edit file (or better, override):

 

controllers/front/ProductController.php:

 

add the following code: (find black code, add red code):

 

$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}
 

 

Result:

post-455771-0-57259200-1428256518_thumb.png

 

 

To modify the decoration of the price or text, you can add some css code to themes/<your theme folder>/css/global.css, like:

 

.estimated_delivery_price {

    font-size: 18px;

}

 

 

 

Hope that does the trick,

pascal.

 

------------

 

P.S. the initial suggestion given above:

    Carrier::getDeliveryPriceByWeight($weight, $id_zone)

 

Doesn't work directly, as the function is not declared 'static', so therefore we first have to create an instance (object) :

   $default_carrier =new Carrier((int)Configuration::get('PS_CARRIER_DEFAULT'));
and then use this instance (i.e. object) to get to the function:

    $default_carrier->getDeliveryPriceByWeight(...)

 

FYI :-)

Share this post


Link to post
Share on other sites
  • 0

Shipping price depends on cart quantity, so it's difficult to show a realistic price if your customer hasn't a cart yet.

If you want nevertheless, you should look at Carrier::getDeliveryPriceByWeight($weight, $id_zone) in classes/Carrier.php or at Cart::getPackageShippingCost($id_carrier, $use_tax, $country, $product_list, $id_zone) filling all that params with data about your customer and his current cart.

If a user isn't logged in, you won't have access to much data about him, so you can do little to show a realistic price.

I suppose the best option in that case is to use Carrier::getDeliveryPriceByWeight(0, your-zone-id).

Share this post


Link to post
Share on other sites
  • 0

Perfect, thanks for the feedback!

 

I'll mark the topic as solved :-)

 

 

Happy selling,

pascal.

Share this post


Link to post
Share on other sites
  • 0

I know this thread is marked as solved but I'm tearing my hair out here  :wacko:

 

I'd like to hide the shipping costs (PS 1.6) until a customer is logged in. I've searched everywhere but haven't found the solution, any ideas gratefully received!!!

Share this post


Link to post
Share on other sites
  • 0

Hi

 

I tried this changes in Prestashop 1.6.0.14 but always I have "not found" info, for every product.

 

I'm not a Prestashop deverloper and I don't know this code and its connections, relationships...

What should I change in above code?

Share this post


Link to post
Share on other sites
  • 0

Hi

 

I tried this changes in Prestashop 1.6.0.14 but always I have "not found" info, for every product.

 

I'm not a Prestashop deverloper and I don't know this code and its connections, relationships...

What should I change in above code?

Hello,

I have the same problem here...

Prestashop 1.6.1.6

Share this post


Link to post
Share on other sites
  • 0

Is it possible to add all delivery costs from every country which is deliverable :

delivery costs :

Austria 150€

Germany 120€

etc..

 

I tried to implement a second variable $delivery_price_de like the first one but no result ....

Share this post


Link to post
Share on other sites
  • 0

Hi,

 

im using 1.6.1.7 <<-- this does not work :/

 

Is it comfortable with this Version?

 

I don't even get a "not found" message, so I guess the var is not forwarding to the template? Is there a way how I can check this?

Edited by electrostuff_de

Share this post


Link to post
Share on other sites
  • 0

Hi moy,

 

You could do something like this:

 

 

 

Hello Pascal!

 

Can You reedit your code to make this works for 1.6.1.2 and above? When I put your code, my product site just dissapear - error 500. More people have this same problem in this topic. Thanks!

Share this post


Link to post
Share on other sites
  • 0
On 10/19/2016 at 7:33 PM, El Patron said:

Hi, I've  solved the inaccurate shipping carrier costs for logged/non-logged.

 

 

 

 

Please see PrestaShop International Shipping Carrier Localization Pro

 

 

 

This module is 'incredible'.  took us 6 months to create / test.  We just suck at marketing it...lol

https://www.prestaheroes.com/en-us/modules/geo-localization/prestashop-shipping-commander

 

rule the pool

 

check it  out!  

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×