Dev Franco Posted May 29, 2015 Share Posted May 29, 2015 Hi, I am trying to group the products in cart summary page by suppliers. Within the {foreach $products as $product}{} loop, I am trying to assign a product value to a smarty variable. But when I am printing the value inside the loop, it is showing the default value which I have set before the loop. Please see the example below: {assign var='sellerid' value=55} {foreach $products as $product} {$sellerid|@print_r} {assign var='sellerid' value= $product.sellerid} {/foreach } It prints 55 1 55 1 55 1 55 1 55 1 I don't know from where this 1 comes. But the 55 is not changing. What is wrong here. Please help me. Link to comment Share on other sites More sharing options...
szkrin Posted May 29, 2015 Share Posted May 29, 2015 I would try something like this: {$sellerid = 55} {foreach $products as $product} {$sellerid = $product['id_supplier']} {$sellerid} {/foreach } If you want to assign other value than id_supplier use {$product|@print_r} and look for needed value. And I guess that you should do something like this in controllers and module php files. In tpl files you're only displaying content. Link to comment Share on other sites More sharing options...
Dev Franco Posted May 29, 2015 Author Share Posted May 29, 2015 HI Szkrin, Thanks for the response. I have tried as you suggested. {$sellerid = 55} {foreach $products as $product} {$sellerid = $product['id_supplier']} {$sellerid} {/foreach } But still the result is same. Unfortuantely, I have to do it in the tpl file. I think it should be possible to do something like this in template files also. Do you have nay suggestion? Link to comment Share on other sites More sharing options...
szkrin Posted May 29, 2015 Share Posted May 29, 2015 Are you sure that you have assigned different suppliers to products? Also you can check which is set as default (only default is showing here) Link to comment Share on other sites More sharing options...
Dev Franco Posted May 29, 2015 Author Share Posted May 29, 2015 (edited) Hi Szkrin, I have checked with different supplier products. No change. What happening is, {$var = 0} {foreach $products as $product} {$var} // prints 0 always {$var = 1} // prints 1 {/foreach} On each iteration, the value of $var is assigned as 0(default value set outside the loop). This is really weird. . Do you have any idea? Edited May 29, 2015 by Dev Franco (see edit history) Link to comment Share on other sites More sharing options...
szkrin Posted May 29, 2015 Share Posted May 29, 2015 I added 3 products to cart, pasted your code into shopping-cart.tpl and it prints 0 1 1 so your code is working Sadly I have no other idea why you're reciving 0 on each iteration. You can try to force compile and clear cache but I don't think that it will help. Maybe somebody else will find solution for you. Link to comment Share on other sites More sharing options...
shokinro Posted June 4, 2015 Share Posted June 4, 2015 This does not seem like a good way to assign Smarty variable {$sellerid = 55} have you tried this way {assign var=sellerid value=55} 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