Jump to content

Smarty variable needed for combinations on Product-List.tpl


Ray UK

Recommended Posts

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 by MerseyRay (see edit history)
Link to comment
Share on other sites

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

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.

  • Like 1
Link to comment
Share on other sites

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

number_of_combinations.jpg.48943e4f72c25397bd1c90998f37d29d.jpg

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

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

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

Screenshot2024-01-11at16-18-14TestStore.jpg.1cd14c7c2daf36589cb545255cebc6a5.jpg

So the value here is 14. The 5 colours plus the other 9

Thanks

Link to comment
Share on other sites

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)

image.png.c0cda867bc9ba25acb8a5be2d89d37f7.png

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 by MerseyRay (see edit history)
Link to comment
Share on other sites

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

  • Ray UK changed the title to Smarty variable needed for combinations on Product-List.tpl

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...