0

I'm trying to extract from a list of products in the cart the (playa) related entries (i want the entry_id's), put them into stash and then i need to use those id's somewhere else to build a "related products" type thing. But as the products in the cart could have the same related entries, i need to make the list it spits out unique. Oh, and there are two playa fields i need to get data from that both have related products but from two different product channels!

So, first we have the setting of the data:

{!-- Get the current items in the basket --}
{exp:cartthrob:cart_items_info}
{!-- Check the products we're getting the info from are in the channel that actually has the related product fields --}
{if channel_id == 7}
    {!-- Channel entry loop to get the product data out from the id's the cart_items_info has given us --}
    {exp:channel:entries channel="events" entry_id="{entry_id}" dynamic="off"}
    {!-- First playa related products field--}
        {product_sub_product}
    {!-- Stash using unique name the list of entry_id's from playa --}
            {exp:stash:set_list name="sub_prods" parse_tags="yes"}
    {!-- Stash set name as item_id --}
                {stash:item_id}
                    {entry_id}
                {/stash:item_id}
            {/exp:stash:set_list}
        {/product_sub_product}
    {!-- Second playa related products field--}
    {product_related_races}
    {!-- Stash using unique name the list of entry_id's from playa --}
        {exp:stash:set_list name="rel_races" parse_tags="yes"}
    {!-- Stash set name as item_id --}
            {stash:item_id}
                {entry_id}
            {/stash:item_id}
        {/exp:stash:set_list}
    {/product_related_races}
{/exp:channel:entries}
{/if}
{/exp:cartthrob:cart_items_info}
{!-- End of current items in the basket --}

And then we have the getting of the data:

{!-- Get the data out from both sets --}
{exp:stash:get_list name="sub_prods" unique="yes"}
    prods - {item_id}<br />
{/exp:stash:get_list}

{exp:stash:get_list name="rel_races" unique="yes"}
    races - {item_id}<br />
{/exp:stash:get_list}

What's odd, is that i can see the data in the database so it is all working as expected. But stash get_list is not outputting the data.

1 Answer 1

1

Grab the related entry ids in one go like this:

{!-- Get the current items in the basket --}
{exp:cartthrob:cart_items_info}
{!-- Check the products we're getting the info from are in the channel that actually has the related product fields --}
{if channel_id == 7}
    {!-- Channel entry loop to get the product data out from the id's the cart_items_info has given us --}
    {exp:channel:entries channel="events" entry_id="{entry_id}" dynamic="off"}

        {!-- Capture a list of entry_ids from the various playa fields --}
        {exp:stash:set_list name="related_prods" parse_tags="yes"}

            {!-- First playa related products field--}
            {product_sub_product}
                {stash:item_id}{entry_id}{/stash:item_id}
                {stash:item_type}sub{/stash:item_type}
            {/product_sub_product}

            {!-- Second playa related products field--}
            {product_related_races}
                {stash:item_id}{entry_id}{/stash:item_id}
                {stash:item_type}related{/stash:item_type}   
            {/product_related_races}

        {/exp:stash:set_list}

    {/exp:channel:entries}
{/if}
{/exp:cartthrob:cart_items_info}
{!-- End of current items in the basket --}

Use like this to get only unique entries:

{exp:stash:get_list name="related_prods" unique="yes"}
    {item_id}<br />
{/exp:stash:get_list}

Or just the 'sub' type of entry ids:

{exp:stash:get_list name="related_prods" match="#^sub$#" against="item_type"}
    {item_id}<br />
{/exp:stash:get_list}
3
  • Thanks Mark! About a second before i saw this, i added process="end" to the get_list tag and it output the data. Not really sure why inline didn't work? Thanks for the reply!! Commented Feb 26, 2013 at 13:50
  • 1
    As ever, it's a parse order thing. Module tags are parsed outwards > inwards; the get_list is on the outermost layer and so parsed before the set_list :) Commented Feb 26, 2013 at 13:53
  • DAMN YOU PARSE ORDER! DAMN YOUUUUUUU!! Thanks again!! Commented Feb 26, 2013 at 13:58

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.