Jump to content

[SOLVED] Smarty: How can I pass the value of a variable between two "tpl"?


kinkibcn

Recommended Posts

Hi, I'm using PS 1.6.1.5 and I need help because I've created a variable in a tpl and need to pass its value to other tpl. I searched all over Google and done endless trials without success.

In the template file shopping-cart-product-line.tpl I have created a variable as follows:

{assign var='cajita_regalo' value='no' scope='global'}

{if strstr($product.attributes, 'Cajita regalo y tarjeta con un mensaje : Sí') }
        {assign var='cajita_regalo' value='si' scope='global'}
{/if}

 

The goal is that when the variable {cajita_regalo} has the value "no" the option to add a message is unchecked  in file order-carrier.tpl

The problem is that I can not pass the value of the variable { cajita_regalo} to order-carrier.tpl

Does anyone know how to do it ?

Thanks in advance for your help.

Edited by kinkibcn (see edit history)
Link to comment
Share on other sites

I think you'd be better off assigning the variable in an override instead of creating it in a TPL file and trying to access it in another. For example, assuming you're using one-page-checkout, create override/controllers/front/OrderOpcController.php and override the function that calls order-carrier.tpl. You can use $this->context->cart->getProducts() to get the cart products, then check if the attributes of any of the products is 'Cajita regalo y tarjeta con un mensaje : Sí', then use $this->context->smarty->assign('cajita_regalo', 'no'); if so.

  • Like 1
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...