You are here:  » Understanding the Explode Filter


Understanding the Explode Filter

Submitted by Convergence on Tue, 2012-05-22 18:12 in

v12/10B

Greetings,

It is our understanding that the explode filter takes the following from a merchant's category in their datafeed:

a) cat1>subcat1>subcat2>color
b) cat 1>subcat 1>subcat 2>color

and returns the following based on 'delimiter (Explode Character or String:)', in this case the '>' and the 'Return Index: (zero based)', in this case '-2'

Resulting category would be:

a) subcat2
b) subcat 2

As explained here:
http://www.pricetapestry.com/node/4638

Also, our understanding that if we want to return

a) subcat1
or
b) subcat 1

we would use '>' as the 'Explode Character or String:' and '2' as our 'Return Index'.

However, no matter what we enter into our 'Return Index' neither

a) subcat1
nor
b) subcat 1

are displayed on our /category/ page. In fact, products are in the database and are not associated with ANY category.

Are we missing something or doing something wrong?

Thanks for clarifying the 'Explode' Filter.

Submitted by support on Wed, 2012-05-23 08:13

Hi,

One thing is might be worth doing first is adding some code to the product HTML module to display the category, so you can see exactly what is being imported in the category field for products from that feed. To do this, simply add the following code to the end of html/product.php

Category: [<?php print $mainProduct["category"]; ?>]

That will display the category within [square brackets].

Regarding the explode filter, your understanding is basically correct however positive return index values are zero based (as it is basically just accessing a PHP array), so for example, exploding the string "a,b,c,d" using an Explode Character or String of "," would give:

a b c d
Positive Return Index 0 1 2 3
Negative Return Index -4 -3 -2 -1

So in the above example, -1 would return "d", and 0 would return "a"...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Wed, 2012-05-23 16:02

Hi David,

Yes, we already have "Category" displayed on our website and it works great. That's how come we are confused as to why when using the Explode filter the product is not assigned or in any category.

Realized after I had posted that the Positive Return Index begins with zero, just was too late to edit my example, lol.

What we are experiencing is, there is no "Exploding" going on. Nothing is getting separated.

Cat 1>Cat 2>Cat 3>Cat 4 when using '>' as the 'Explode Character' returns:

Cat 1Cat 2Cat 3Cat 4

Stumped...

Submitted by support on Wed, 2012-05-23 16:07

Hi,

Ah, I see what's going, my apologies I should have spotted this earlier; the > character is stripped from the category value during normalisation; so is not present by the time user filters process the value.

To work-around this, it would be necessary to move normalisation until after user filters have been applied. In includes/admin.php look for the following code at line 189:

$importRecord["category"] = tapestry_normalise($importRecord["category"]);

...CUT that line, and then PASTE it back into the script lower down, immediately before this comment at line 230:

/* drop record if set by user filters filters */

Things should make more sense after that!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Wed, 2012-05-23 16:13

Hi David,

Just:

     $importRecord["category"] = tapestry_normalise($importRecord["category"]);

or:

    if ($importRecord["category"])
    {
      $importRecord["category"] = tapestry_normalise($importRecord["category"]);
    }

Thanks!

Submitted by support on Wed, 2012-05-23 17:00

Hi,

The former...

     $importRecord["category"] = tapestry_normalise($importRecord["category"]);

Don't worry about the IF / braces;

Cheers,
David.
--
PriceTapestry.com