Jump to content

[PS 1.7.7.5] Smarty variable needed to count variation options


Ray UK

Recommended Posts

Hi,

Im trying to find a variable to count the number of different attributes of a product.

(Not the qty of attributes )

i.e.,  if my product had options red, yellow, blue with 10 of each colour in stock, the value I'm after is 3.

This is to add back one of the most basic parts on any ecommerce site, the "Add to cart" button on the product listing.

I need this variable instead of using {if $product.id_product_attribute > 0} because some products will have 1 attribute (i.e. colour) and I need it so that it still filters in the faceted search module.

Also, a qty of the default attribute would be handy to show an "Out of stock" button if the qty is 0

Thanks in advance

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

Ok so I found the variable

{if $product.availability == 'available'}

to be of some use. I have so far got this.

	{if $product.availability == 'available'}
		
		[button - add to cart]
		
		{elseif $product.availability == 'unavailable'}
		
		[button - view options] (available with other attributes)

		{else}		
	
		[button - out of stock]
		{/if}

However, the "available with other attributes" and "out of stock" both show the same "view options" button.

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

I seem to have accomplished this by using the product.availability_message variable.

If anybody needs the code I used, here it is

{if $product.availability_message == 'In Stock.'}
		
		<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
			<input type="hidden" name="token" value="{$static_token}">
			<input type="hidden" name="id_product" value="{$product.id}" id="product_page_product_id">
			<button class="btn btn-block btn-primary add-to-cart {if $product.quantity < 1}out-of-stock{/if}" data-button-action="add-to-cart" type="submit">
				<i class="fal fa-shopping-cart hidden-sm-down"></i>
				{l s='Add to cart' d='Shop.Theme.Actions'}
			</button>
		</form>
		
		{elseif $product.availability_message == 'Product available with different options'}
		<a class="btn btn-block btn-info" href="{$product.url}">View Options</a>
		{else}		
	
		<div class="addtocart">
			<button class="btn btn-block">Out of Stock</button>
		</div>
		{/if}

You can see it working here https://www.nwecigs.co.uk/10-ecigarette-kits?page=2

Edited by MerseyRay (see edit history)
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...