0

I have a product listing page which displays product title and product image as well product price. Part of the code related to product price looks like:

{if status == "retail"}
    {exp:store:product entry_id="{entry_id}" disable_form="yes"}
        <span class="store_product_price">{price}</span>
        {if total_stock == 0}<br /><span class="store_product_out_of_stock">Sold Out</span>{/if}
    {/exp:store:product}
{/if}

and it works for product without modifiers.

My question is how can I display product price which is stored as modifiers as product price range, something like $200-$400 (lowers - highest price)? I have try to use price_inc_mod within {modifier_options} and store all prices as an array, but somehow that last step wasn't working for me.

Thanks

2 Answers 2

0

Got this to work. Below code example

{exp:store:product entry_id="{entry_id}" disable_form="yes"}

<?php  $prices = array(); ?>
{modifiers}
{modifier_options}
    <?php $prices[] = str_replace('$', '', str_replace(' ', '', str_replace(',', '','{price_inc_mod}'))) ;?>
{/modifier_options}
{/modifiers}
<?php 
sort($prices);
?>
<span class="store_product_price"><?php echo $prices[0]; ?></span>
{/exp:store:product}
1
  • 1
    You should be able to do it without php in your templates. Dec 19, 2014 at 20:00
0

If you wanted to do it without using PHP in your template you would be able to use the {modifier_option} tag pair along with some conditionals to get the price to display properly.

{if status == "retail"}
    {exp:store:product entry_id="{entry_id}" disable_form="yes"}
        <span class="store_product_price">
          {modifiers}
            {if modifier_options} 
                {modifier_options}
                    {!-- 
                     --- use price_inc_mod if your items dont have tax
                     --- use price_inc_mod_inc_tax if you have tax inclusive pricing
                    --}
                    {if option_first}{price_inc_mod}{/if}{if option_last} - {price_inc_mod}{/if}
                {/modifier_options}
              {/modifiers}
            {else}
                {price}
            {/if}
            </span>
        {if total_stock == 0}<br /><span class="store_product_out_of_stock">Sold Out</span>{/if}
    {/exp:store:product}
{/if}

That should get it sorted out for you as long as the first and last modifiers have the the lowest and highest prices respectively.

2
  • Well, that code is not accurate and depends on how store owner will add modifier options (in this case first price must be always lowest one and last one higher). Also {modifier_options} must be wrapped with {modifiers} other way it is not working at all. Dec 22, 2014 at 18:26
  • I have updated my code to include the modifiers tag pair Dec 22, 2014 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.