Jump to content

[SOLVED] Shipping price on product page


sinedo

Recommended Posts

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).

Link to comment
Share on other sites

  • 4 weeks later...

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 :-)

  • Like 6
Link to comment
Share on other sites

  • 1 month later...

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!!!

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 4 months later...
  • 4 months later...
  • 1 month later...
  • 1 month later...

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
  • 2 months later...

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!

Link to comment
Share on other sites

  • 7 months later...
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!  

Link to comment
Share on other sites

  • 3 years later...
  • 7 months later...
On 5/27/2022 at 3:34 AM, sebsimappus said:

Hello,

Many thanks for the information for prestashop 1.6.
Is it possible to update the tutorial for prestashop 1.7 and 1.8

A big thank you to you

you should upgrade your ps to stay current, 1.6 is no longer supported....we seldom see them in the wild anymore...

Link to comment
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
×
×
  • Create New...