0

I'd like to make an improvement to how I'm displaying related products on a product detail page. Right now, the list of related products will...

  • be limited to the same type and category (Playa relationships)
  • be ordered by dollar value in descending order (numeric field)

Sometimes the price alone can make an item dissimilar; for example a $1.5M gum production machine isn't relevant on the detail page for a $0.75 pack of gum. What I'd like to do is limit my related entries to anything within ${x} of the current item.

Here's the (simplified) related products template, to which I pass the IDs of related category pages:

<h3>Related Products</h3>
<ul>
{exp:playa:parents entry_id="{embed:category_ids}" orderby="product_price" sort="desc"}
     <li><a href="{page_uri}">{title}</a>, ${product_price}</li>
{/exp:playa:parents}
</ul>

If I wanted to limit by date, I could use EE's start_on parameter. If I wanted to match a specific value, I know I could use the search paramater. In this case, I simply want to add WHERE product_price <= x, with x being a dollar amount I've already calculated in PHP to be reasonably close to the currently-viewed product. Is there a way to accomplish this without going straight for the query module?

2 Answers 2

1

Have a look at Low Search -- it can be used as a replacement for the Channel Entries tag, and has a range parameter which might suit your needs.

1
  • Thanks Derek! We're conveniently using Low Search on the site, and I didn't even realize it has a range parameter and can work with native or Playa relationships. Perfect!
    – Matt Stein
    Jun 13, 2013 at 22:50
1

Since I love answering my own questions, here's the template embed I ended up with thanks to Derek's suggestion of using Low Search:

<?php 

$pad = 10; // dollar amount above the current price at which we'll cap results
$price_limit = intval('{embed:current_product_price}')+$pad; 

?>

{exp:low_search:results child:product_categories="{embed:category_ids}" range:product_price=";<?php echo $price_limit; ?>" orderby="product_price" sort="desc" parse="inward"}
    <li><a href="{page_uri}">{title}</a>, ${product_price}</li>
{/exp:low_search:results}

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.