ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Looking for a way to do something like search param for a specific reverse relationship

September 06, 2012 7:15am

Subscribe [2]
  • #1 / Sep 06, 2012 7:15am

    John St-Amand

    865 posts

    I’m a bit stuck.  I have a vendors channel and a products channel.  In the products channel, I have a relationship field for vendor.  Ordinarily, displaying a vendor-specific list of products would be simple - reverse relationship within the vendor loop.  However, I need the search param on the products loop, which reverse relationships do not support.

    So, that leaves me with embedding the product entries loop for a given vendor (and with the embed I can pass the vendor entry id).  The problem I now face is figuring out a way to search through the products and pull out only those products related to that vendor ID.  The vendor ID can’t simply be used in a second search param, since the vendor ID is not actually stored by the relationship field - just the relationship ID is.

    Any of you smart folks have a solution for me?  I mean sure, I could add a display = none to any product that doesn’t have that vendor by doing a conditional inside the loop - but that’s messy and throws off the results count.  I’d rather learn of a way to handle this at the loop level, if you get my drift.

  • #2 / Sep 06, 2012 7:44am

    Boyink!

    5011 posts

    What’s the reason you can’t pull all related products?

    Would a second relationship field be an option?

  • #3 / Sep 06, 2012 7:56am

    John St-Amand

    865 posts

    The “parent” loop for the brand is pretty simple.  The issue arises at the product level, wherein I need a search param on the loop to filter down to only those products with a “yes” in a radio button field which determines whether they are intended to be displayed.

    So ordinarily, I could get away with simply:

    {exp:channel:entries channel="vendors" limit="1" yadayadayada}
    
    {reverse_related_entries channel="products"}
    {title}, etc
    {/reverse_related_entries}
    
    {/exp:channel:entries}

    But, reverse related entries is limited to something like six parameters.  The search param is not among them.  So If i did this, i would get all products for the vendor rather than all products with “yes” in my radio button field.

    So what I’m instead hoping I can find a way to do is this:

    {exp:channel:entries channel="vendors" limit="1" yadayadayada}
    
    {embed="embeds/vendor-specific-products-list" the_vendor="{entry_id}"}
    {/exp:channel:entries}

    And then in the embed:

    {exp:channel:entries channel="products" limit="50" search:products_display_in_site="=Yes" search:products_vendor="={embed:the_vendor_id}" yadayadayada}
    
    {title} etc
    
    {/exp:channel:entries}

    But of course, I can’t do that because the products_vendor field is a relationship and therefore it doesn’t actually store the vendor ID it’s related to.  So I’m struggling with how I can accomplish this one.  If I didn’t absolutely need the search param, a reverse relationship would probably work out just fine.

  • #4 / Sep 06, 2012 8:02am

    Boyink!

    5011 posts

    It’s early yet, but the only two options coming to mind are to use a custom status on products instead of your custom field, or a custom query in place of the reverse_related_entries tag pair.

  • #5 / Sep 06, 2012 8:05am

    John St-Amand

    865 posts

    I’m thinking a custom query is likely going to be where I wind up.  The products are imported from a CSV regularly and importing the value of the yes/no field as a simple field value was far simpler than converting yes/no into a status for that purpose.  So I’ll have to figure out the query end of things - just not my area so I’m hoping someone with strong query-fu will chime in.

  • #6 / Sep 06, 2012 8:07am

    Boyink!

    5011 posts

    Do the products that have “no” in that field get used on the site anywhere else?

  • #7 / Sep 06, 2012 8:09am

    John St-Amand

    865 posts

    No. It’s purely an imported trigger from their point of sale that determines whether the product is visible in the site.  Only a Yes product displays in the site (but no products can still be edited, updated, etc so they can add non-POS fields, like images, for example, before switching the product to the “yes” position).

  • #8 / Sep 06, 2012 8:14am

    Boyink!

    5011 posts

    Ah ok. I was wondering if you could just filter them out on import but sounds like that’s not an option.

  • #9 / Sep 06, 2012 8:16am

    John St-Amand

    865 posts

    No, unfortunately.  It’s kind of a unique setup to make the import process a bit smoother.  The data set was already pretty complicated, so that was one simplification that made things easier. And it works beautifully within the category view, but it does make the vendor view a bit tough.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases