1

Searching for all items that are on sale, as of Express Store 2.0.4, is currently MIA, despite the presence of the search:on_sale parameter in the docs. That is, this code...

{exp:store:search channel="products" search:on_sale="yes"}
    {title}
{/exp:store:search}

... returns all items in the products channel, not just products on sale.

You can hack around this by using looping through all products and checking each one using the on_sale conditional:

{exp:channel:entries channel="products" orderby="title" sort="asc" disable="member_data|pagination" limit="99"}
    {exp:store:product entry_id="{entry_id}" disable_form="yes" disable_javascript="yes"}
            {if on_sale}
                {title}
            {/if}
    {/exp:store:product}
{/exp:channel:entries}

But has anyone figured out how to display a Sorry, no items are currently on sale message when no items are on sale? I've tried a PHP (input), PHP (output), and a variety of Stash syntax. Something very strange is happening either with parse order or the way that on_sale works. For example, you would think this would work:

{exp:channel:entries channel="products" orderby="title" sort="asc" disable="member_data|pagination" limit="99"}
    {exp:store:product entry_id="{entry_id}" disable_form="yes" disable_javascript="yes"}

            {if on_sale}
                {exp:stash:set_value name="sale_items_exist" value="true"}
                {title}
            {/if}

    {/exp:store:product}
{/exp:channel:entries}


{if "{exp:stash:get name='sale_items_exist' process='end'}" != "true"}
    <p>Sorry, no items are currently on sale</p>
{/if}

<p>Debug: the stash variable is {exp:stash:get name='sale_items_exist' process='end'}</p>

When I use that code, if there is an item on sale, that last line outputs nothing (and so my "no items on sale" message shows up even though it shouldn't). Somehow Stash is not setting sale_items_exist to true.

Has anyone solved this problem some other way?

2 Answers 2

3

Another wild idea if you can't figure it out with parse order. Use Javascript!

if ($(".product-list-item").size() == 0) {
    $(".product-no-items").show();
}

Not the most elegant solution, but if you're up against a deadline then it will certainly work.

1
  • Good enough for rock and roll / government work. Thanks. Oct 29, 2013 at 0:34
1

This might be overkill (and someone better at parse order than me may have a better solution), but you should be able to put no items bit inside an embed. That's my usual solution to get around parse order problems.

{embed="shared/no_items" items_exist="{exp:stash:get name='sale_items_exist' process='end'}"}

Then in your shared/no_items template:

{if "{embed:items_exist}" != "true"}
    <p>Sorry, no items are currently on sale</p>
{/if}

Like I said, there's probably a cleaner way around this, but I usually find parse order issues like this are just trial and error until you find something that works.

1
  • Makes sense, but unfortunately/amazingly stash is setting sale_items_exist to "true" even though every item in the loop must be be returning false for the on_sale conditional. In other words, if I just put stash is showing {embed:items_exist} inside shared/no_items, it outputs "true" even when I've disabled my sales. Is there possible there's something funky with the on_sale implementation? Oct 29, 2013 at 0:30

Your Answer

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

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