Miva 5.5 - filtering by subcategory

455 views Asked by At

The "great" Miva forum banned me for registering and asking this question. Not sure if any here can help me with this...

On the category pages, I need to display the products in columns based on Best Sellers, New Releases, etc. There are categories set up with subcategories. Products are assigned to a category and possibly a subcategory.

Choral

  • Choral Best Sellers
  • Choral New Releases

Vocal

  • Vocal Best Sellers
  • Vocal New Releases

All parent categories' names are one word, with their subcategories adding two words. The category page will show all the products in the parent category, I just want to filter what's in each in column. I was trying to compare the added two words to part of the subcategory name with an expression. That way it wouldn't matter what parent category you were in, the same code could be used for all. Seems like something that's very basic, but isn't working.

Example non-working code:

<div class="row">
<h2>Best Sellers</h2>
<mvt:foreach iterator="product" array="products">
<mvt:if expr="'Best '$'Sellers' IN g.category:name">
product display stuff here
</mvt:if>
</mvt:foreach>
</div>

<div class="row">
<h2>New Releases</h2>
<mvt:foreach iterator="product" array="products">
<mvt:if expr="'New '$'Releases' IN g.category:name">
product display stuff here
</mvt:if>
</mvt:foreach>
</div>
2

There are 2 answers

0
krisfremen On

A little late to the party, but I was just looking into a way to do this and ended up using Emporium Plus Tool Kit.

<mvt:item name="toolkit" param="sassign|bestSellerCategory|best-sellers" />
<mvt:item name="toolkit" param="cxpc|pcount|g.bestSellerCategory" />

Replace best-sellers with your category code. After that you can use a regular foreach to iterate through the products

<mvt:foreach iterator="sub_product" array="sub_products">
<a href="/&mvte:sub_product:code;.html">&mvte:sub_product:name;</a>
</mvt:foreach>

Repeat for as many categories as you need to display on one page.

2
Tango Bravo On

If you haven't already, you might want to pick up the PCI Net Tool Belt. It's written by Ray Yates, and very well documented. It is a Miva Merchant Language Extension module, which will give you wonderful access to Miva Merchant that SMT won't (by default).

The issue that you're running into is that you're looking at a variable which doesn't exist. Your "scope" is off. The variable g.category_code holds the category code in the Global variable context (which is what I think you may be confusing g.category:name with). You need to look in the LOCAL variable context.

Your <mvt:foreach> looks fine.

Try changing your code from:

<mvt:if expr="'Best '$'Sellers' IN g.category:name">

To:

<mvt:if expr="'Best '$'Sellers' IN l.settings:category:name">

Or even:

<mvt:if expr="'Best Sellers' IN l.settings:category:name">

That way you won't have to do the unnecessary concatenation. ;)