Ray UK Posted January 9 Share Posted January 9 (edited) Hi, Im after the smarty variable to let me know how many different variants a product has. I dont need to know the qty or if they are in stock or not, just if the product has more than 1 option. Its going to be for a "Show Options" for products with options or "Add to cart" button if the product has no options on the product list/category page. So it would be something like this {if $product.variants > 1}<CHOOSE OPTIONS>{else}<ADD TO CART>{/if} Some of my products do have 1 option (so that they filter in the faceted search), ie a colour, so that would need to be <CHOOSE OPTIONS> Thanks Edited January 17 by MerseyRay (see edit history) Link to comment Share on other sites More sharing options...
dinesh badrukhiya Posted January 10 Share Posted January 10 Hello @MerseyRay You can use {if !$product.main_variants} {l s='Add to cart' d='Shop.Theme.Actions'} {else} {l s='Select Option' d='Shop.Theme.Actions'} {/if} Thanks. Link to comment Share on other sites More sharing options...
Ray UK Posted January 10 Author Share Posted January 10 19 minutes ago, dinesh badrukhiya said: Hello @MerseyRay You can use {if !$product.main_variants} {l s='Add to cart' d='Shop.Theme.Actions'} {else} {l s='Select Option' d='Shop.Theme.Actions'} {/if} Thanks. Hi Dinesh, I have already tried that code. I found something like that when I searched. I have just added that code back but if you take a look at this page you will see its not working properly. https://www.northwestecigs.uk/10-ecigarette-kits That looks like its true if the main varient is in stock, and not just if the product has variants. Thanks Link to comment Share on other sites More sharing options...
Ray UK Posted January 10 Author Share Posted January 10 (edited) This variable (8) here would probably do the trick. ie, The total number of combinations a product has Edited January 10 by MerseyRay (see edit history) Link to comment Share on other sites More sharing options...
dinesh badrukhiya Posted January 10 Share Posted January 10 43 minutes ago, MerseyRay said: Hi Dinesh, I have already tried that code. I found something like that when I searched. I have just added that code back but if you take a look at this page you will see its not working properly. https://www.northwestecigs.uk/10-ecigarette-kits That looks like its true if the main varient is in stock, and not just if the product has variants. Thanks {if $product.id_product_attribute > 0} try with this variable it might help. 1 Link to comment Share on other sites More sharing options...
Ray UK Posted January 10 Author Share Posted January 10 11 minutes ago, dinesh badrukhiya said: {if $product.id_product_attribute > 0} try with this variable it might help. Thank you, That is the closest its been. Im guessing that value will only be 1 or 0 to indicate the products has combinations. If this variable is available I think it would be perfect for this job Its just that some products may have 1 colour option (which is needed for faceted search to filter) The above image would then show 0/1 combinations which would have <ADD TO CART> so something like this which counts the number of different combinations would be perfect {if $product.id_product_attribute|@count > 1} If thats not possible then what you have already suggested will do. Thanks Link to comment Share on other sites More sharing options...
Ray UK Posted January 10 Author Share Posted January 10 In the file variant-links.tpl there is $variants and also a span named "js-count" which shows the number of variants. Ive tried ({$variants|@count}) but thats not working. Is it because that array isnt available in the category listing page or am I doing something else wrong. When I use the above my button shows <Choose Option (0)> Thanks Link to comment Share on other sites More sharing options...
dinesh badrukhiya Posted January 10 Share Posted January 10 It’s better to use $product.id_product_attribute == 0 condition. Link to comment Share on other sites More sharing options...
Ray UK Posted January 11 Author Share Posted January 11 Thanks for trying Dinesh, That condition is doing the same as the previous one. It looks like its just a 0 or 1. The number im really after is on the list somewhere as it is used here So the value here is 14. The 5 colours plus the other 9 Thanks Link to comment Share on other sites More sharing options...
Ray UK Posted January 12 Author Share Posted January 12 (edited) Ok so I have got a little further. Ive got this far by doing this: I created a add-to-cart-button.tpl and Inside the miniature/product.tpl i used this {block name='product_variants'} {include file='catalog/_partials/add-to-cart-button.tpl' variants=$product.main_variants} {/block} and then used the condition {if $variants|@count >1} Now this is working, but only for products that have colour attributes. (see pic) So is there another way of calling my add-to-cart-button.tpl that will also include other combinations and not just the colours. (in the example above this would include the paper types) Edited January 12 by MerseyRay (see edit history) Link to comment Share on other sites More sharing options...
Ray UK Posted January 17 Author Share Posted January 17 What im looking to accomplish must be possible because I've seen modules/themes that show size cominations on the productlist. I guess its a case of making a new variable by using an override on a controller.. but I wouldnt have a clue what to put there. Any ideas? Thanks 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