Skip to content

Instantly share code, notes, and snippets.

@philcon93
Last active November 8, 2016 03:28
Show Gist options
  • Save philcon93/4d790ae8dea710e65e31 to your computer and use it in GitHub Desktop.
Save philcon93/4d790ae8dea710e65e31 to your computer and use it in GitHub Desktop.
Product Variations Highest and Lowest

Product Variations Highest and Lowest

B@se

[@lowest_price@]to [@highest_price@]

[%set [@lowest_price@]%]99999[%/set%]
[%set [@highest_price@]%]0[%/set%]
[%list_item_variations id:'[@current_sku@]'%]
[%param *variation_body%]
[%product sku:'[@variation_sku@]'%]
[%param *body%]
[%if [@price@] < [@^^lowest_price@]%]
[%set [@^^lowest_price@] %][@price@][%/set%]
[%/if%]
[%if [@price@] > [@^^highest_price@]%]
[%set [@^^highest_price@] %][@price@][%/set%]
[%/if%]
[%/param%]
[%/product%]
[%/param%]
[%/list_item_variations%]
<span class="text"><b>
[%if [@lowest_price@] eq [@highest_price@] %]
[%FORMAT type:'currency'%][@lowest_price@][%/FORMAT%]
[%else%]
From [%FORMAT type:'currency'%][@lowest_price@][%/FORMAT%] - [%FORMAT type:'currency'%][@highest_price@][%/FORMAT%]
[%/if%]
</b></span>
@philcon93
Copy link
Author

This doesn't work with different user group, work around with display_child_products:

            [%display_child_products id:'[@sku@]'%]
                [%param *body%]
                    [%if [@store_price@] < [@^lowest_price@]%]
                        [%set [@^lowest_price@] %][@store_price@][%/set%]
                    [%/if%]
                    [%if [@store_price@] > [@^highest_price@]%]
                        [%set [@^highest_price@] %][@store_price@][%/set%]
                    [%/if%]
                [%/param%]
            [%/display_child_products%]

@philcon93
Copy link
Author

Full version if used on the product thumbnail:

[%set [@lowest_price@]%]99999[%/set%]
[%set [@highest_price@]%]0[%/set%]

[%display_child_products id:'[@sku@]'%]
    [%param *body%]
    	[%if [@inpromo@]%]
            [%if [@promo_price@] < [@^lowest_price@]%]
                [%set [@^lowest_price@] %][@promo_price@][%/set%]
            [%/if%]
            [%if [@promo_price@] > [@^highest_price@]%]
                [%set [@^highest_price@] %][@promo_price@][%/set%]
            [%/if%]
        [%else%]
            [%if [@store_price@] < [@^lowest_price@]%]
                [%set [@^lowest_price@] %][@store_price@][%/set%]
            [%/if%]
            [%if [@store_price@] > [@^highest_price@]%]
                [%set [@^highest_price@] %][@store_price@][%/set%]
            [%/if%]	                
        [%/if%]
    [%/param%]
[%/display_child_products%]      

[%if [@has_child@] || [@has_variation@] %]
	<span itemprop="price" content="[@highest_price@]">[%format type:'currency'%][@highest_price@][%/format%]</span>
[%else%]
	[%if [@inpromo@]%]
		Now&nbsp;
		<meta itemprop="priceValidUntil" content="[%format type:'date' format:'#Y-#M-#d'%][@promo_end@][%END format%]"/>
		<span itemprop="price" content="[@promo_price@]">[%format type:'currency'%][@promo_price@][%/format%]</span>
	[%else%]
		<span itemprop="price" content="[@store_price@]">[%format type:'currency'%][@store_price@][%/format%]</span>
	[%/if%]
[%/if%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment