Lucagiaicheca Posted July 15, 2014 Share Posted July 15, 2014 Hi, I'm new to smarty so here's my question. In the cart I need to check if each product category equals a certain product category, and if it does then increment +1 a variable. here's my shopping-cart.tpl. My var is called "pippo" {assign var='pippo' value=0} {foreach $products as $product} {assign var='productId' value=$product.id_product} {assign var='productAttributeId' value=$product.id_product_attribute} {assign var='quantityDisplayed' value=0} {assign var='odd' value=$product@iteration%2} {assign var='ignoreProductLast' value=isset($customizedDatas.$productId.$productAttributeId) || count($gift_products)} {* Display the product line *} {include file="./shopping-cart-product-line.tpl" productLast=$product@last productFirst=$product@first} {* Then the customized datas ones*} {if isset($customizedDatas.$productId.$productAttributeId)} {foreach $customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] as $id_customization=>$customization} As you can see the shopping-cart.tpl includes shopping-cart-product-line.tpl, where each product get read and displayed. Inside shopping-cart-product-line.tpl I put my increment (I get product category and if it equals to the one I'm interested to, I want to add 1 to $pippo (thanks to Mr. Milosz for his tutorial on how to add product category in cart) {foreach from=Product::getProductCategoriesFull($product.id_product) item=cat} {/foreach} {if $cat.id_category==437} {math equation='x+1' x=$pippo assign="pippo"} {/if} The loop works a charme, and it actually increments by 1 $pippo if $cat.id_category==437. But the next line $pippo=0 once again. $pippo seems to reset on each loop. Why? My var is assigned=0 outside the {foreach} cycle, so $pippo should increment by one, and then keep the new value, not the old one... HELP PLEASE :-) Link to comment Share on other sites More sharing options...
tomerg3 Posted July 15, 2014 Share Posted July 15, 2014 Forget about math, try using {assign var='pippo' value=$pippo+1} 1 Link to comment Share on other sites More sharing options...
Lucagiaicheca Posted July 16, 2014 Author Share Posted July 16, 2014 Dear Tomerg3, thank you so much for help. I actually checked my smarty version is 3, so you are right. The variable keeps on getting zero. In the image of my cart, close to the product image I put {$pippo} to let me see if it increments. As you can see, on the products there's 1 instead of 0, this means that {if} works and recognizes the category and adds 1 to $pippo. But the next line $pippo is 1 again, even if I have 2 products with the right product category. Above all, when I go back to shopping-cart.tpl and I make it print {$pippo}, it always equals 0 (you can see at the bottom of the page). Sob. Any idea? Thank you so much. :-) Link to comment Share on other sites More sharing options...
tomerg3 Posted July 16, 2014 Share Posted July 16, 2014 Maybe try another variable name, in case it is clashing with something else. The code seems to be correct. 1 Link to comment Share on other sites More sharing options...
Lucagiaicheca Posted July 18, 2014 Author Share Posted July 18, 2014 I tried, but with no success I really don't know whom I could ask for help... Tomerg do you know somebody who knows prestashop and smarty (paying) that could help me pass through this issue? It's really weird, isn't it? Thank you tomerg3 for your time and help... Link to comment Share on other sites More sharing options...
tomerg3 Posted July 18, 2014 Share Posted July 18, 2014 It is odd, but generally odd problems have obvious solutions. You can try posting here http://www.prestashop.com/forums/forum/235-job-offers/ Link to comment Share on other sites More sharing options...
Dev Franco Posted May 29, 2015 Share Posted May 29, 2015 Hi, I am facing the same problem. . Did you get a solution?? 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