PrestaShop - How to retrieve Carrier ID in Smarty

2019-08-08 03:28发布

问题:

I am using PrestaShop 1.5.3.1 and I want to retrieve the Carrier ID during the Payment step in the checkout process.

In PrestaShop 1.4 I was using {$id_carrier} and it was working just fine, but it is not working in PrestaShop 1.5.x

I want to show one payment method depending on selected carrier.

For example:

{if $id_carrier == 1}
    my content
{/if} 

回答1:

On the payment page, you can retrieve the selected Carrier ID using the following Smarty variable:

{$cart->id_carrier}

This will work anywhere in the Front-end, both on PrestaShop v1.4.x and v1.5.x.

{if isset($cart->id_carrier) && $cart->id_carrier == 1}
   {* Do some stuff here *}
{/if}


回答2:

$carrier = new Carrier($cart->id_carrier); // in payment module page