You are here:  » only list own categories on the category page and in the category filter


only list own categories on the category page and in the category filter

Submitted by gunarbod on Fri, 2011-07-15 13:55 in

Hi David,

I have a question regarding the categories: after importing the first feed and matching the category column, these are displayed on the category page as well. How can I just display the categories I have created myself via the Price Tapestry Backend on the category page and in the category filter?

Otherwise I would have to stick with hundreds of stupid categories like:

Wohnen Lifestyle Bad
Wohnen Lifestyle Bad Relaxen
Wohnen Lifestyle Bad Relaxen Badhaken
Wohnen Lifestyle Bad Relaxen Duschablagen
Wohnen Lifestyle Bad Relaxen Erste Hilfe Schrank

Again, thanks a lot,
Gunar

Submitted by support on Fri, 2011-07-15 14:18

Hi Gunar,

A "global" solution to this would be to unset the category if it is not the result of a mapping. To do this, in includes/admin.php, look for the following comment at line 266:

    /* capture original catalogue product name prior to mapping */

...and REPLACE with:

    if (!in_array($importRecord["category"],$admin_importCategoryMappings))
    {
      $importRecord["category"] = "";
    }
    /* capture original catalogue product name prior to mapping */

Don't forget to re-import all feeds after making changes as mapping is only applied at import time...

Cheers,
David.
--
PriceTapestry.com

Submitted by gunarbod on Fri, 2011-07-15 20:36

Hi David,

unfortunately, this solution didn't work. I now get the following error when importing the feed.

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /www/htdocs/w00e2c85/includes/admin.php on line 266

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/w00e2c85/includes/admin.php:266) in /www/htdocs/w00e2c85/admin/feeds_import.php on line 31

Any ideas?

Thanks,
Gunar

Submitted by support on Sat, 2011-07-16 07:46

Sorry Gunar,

The parameters were the wrong way round in this line:

  if (!in_array($admin_importCategoryMappings,$importRecord["category"]))

...which should be:

  if (!in_array($importRecord["category"],$admin_importCategoryMappings))

...corrected above also...

Cheers,
David.
--
PriceTapestry.com

Submitted by gunarbod on Mon, 2011-07-18 12:55

All the merchants categories ar gone now as expected, but now it seems like category mapping for my custom categories doesn't work anymore. Could you please explain, what exactly is done when mapping categories? I think I have a totaly wrong understanding of how PiceTapestry handles categories.

What I thought was, that PriceTapestry would search the products database for my custom categories (title, description, category breadcrumbs) and write the category name into the category row for the products found. Lets say I have three categories "chair", "red chair" and "white chair" and two products "red chair" and "white chair". After import, there should be two products assigned to "chair" and one product assigned to "red chair" and one assigned to "white chair".

Cheers,
Gunar

Submitted by support on Mon, 2011-07-18 13:09

Hello Gunar,

Apologies for the confusion; a product can only be in 1 category - the value of its category field when it is imported.

This will either have come from the value of the field that you registered as the category for the feed that the product comes from; or the manually entered category if you want all products from a feed to be in the same category. Both of these are part of Feed Registration Step 2.

Category Mapping is intended to match together categories between merchants where they use slightly different names for the same category. For example if one merchant uses the category name "Televisions", and another uses "TVs", but you want both of these to be "TV", then you can create a new Category Mapping called "TV" and enter =Televisions and =TVs as exact match alternatives. Then, during import, any category that is either of the exact match alternatives will be imported with the category "TV".

Keyword matching still only applies to the category name, but just looks for the keywords anywhere in the category name rather than being an exact match.

Hope this helps, let me know if you're still not sure or would like to do something slightly different...
Cheers,
David.
--
PriceTapestry.com

Submitted by gunarbod on Mon, 2011-07-18 13:53

Hi David,

thanks for making that clear. Now I've got it. ;)

As I'm not focusing on individual products but longtail category keywords (e.g. casual brown boots, elegant red boots) the category handling is most important to me. What I would like to achieve is the following:

1. Enter my custom category names (and alternatives) in category mapper.

2. On feed-import find all products that match these category names or alternatives (either in title, description or category) and write all matching category names for a product to its category column or better to a new column that would have to be created for that purpose (lets say a "keywords" column).

3. In the user frontend list all my custom categories under /category/.

4. In the specific category (e.g. /category/casual+brown+boots/) list all products that got exactly this category name written in its keyword column in step 2.

Basically its a full text search done when importing the products instead when loading the category pages. So when a user enters a category page, only the category column needs to be searched for that particular category name, resulting in much faster page load times compared to a full text search each time a category is entered by a user. However, if a user uses the search form, then a real time full text search needs be done.

Is there a way to achieve that? I think I know how to handle all aspects on the category pages in the user frontend. But which changes would have to be applied to the category mapping to achieve what I want?

Would be great If you could help me out, although it's some bigger changes.

Cheers,
Gunar

Submitted by support on Mon, 2011-07-18 13:58

Hello Gunar,

It's an easy mod to make the keyword matching apply to name + description + category! In includes/admin.php look for this code at line 252:

  if (strpos($importRecord["category"],$word) !== FALSE) $found++;

...and REPLACE with:

  if (
     (strpos($importRecord["category"],$word) !== FALSE)
     ||
     (strpos($importRecord["name"],$word) !== FALSE)
     ||
     (strpos($importRecord["description"],$word) !== FALSE)
     )
    $found++;

(note if you want to make it case-insensitive, replace strpos with stripos in each case)

All other category behaviour should then work as you describe!

Cheers,
David.
--
PriceTapestry.com

Submitted by lisbali12 on Wed, 2012-10-03 12:57

Hi David,

This is really helpful as my merchants' categories are all over the place - some being perfect matches for those that I would like on my site, and others containing a mixture of products from more than one of my categories, making it impossible to map them in the normal way.

I wonder though whether it's possible to take the keyword matching a bit further and use some Boolean logic style search operators to further refine the way products are assigned to categories?

So that you could map a product to a category if it contained for example:

keyword A OR keyword B OR keyword C

AND

keyword D OR keyword E OR keyword F

and even better to be able to exclude products on the basis of keyword too, like

AND NOT keyword X OR keyword Y OR keyword Z

so that products not exactly fitting a category would not be assigned to it (say you had a category for Blue Widgets and wanted a seperate one for Blue Widget Cases for example, you would otherwise get both sets of products in one category - but if you could exclude cases using a NOT operator from the blue widgets, then you could seperate them).

Does that make sense?

I think it's been posted about before here http://www.pricetapestry.com/node/4186

Is this kind of approach possible? It would be amazing if it was!

Many thanks in advance,

Lis

Submitted by support on Wed, 2012-10-03 15:04

Hello Lis,

One option would be create a match operator that lets you string together one or more regular expressions using a logical AND. Category Mapping already supports "=" as an exact match; so to support "?" as a regexp match; look for the following code at line 242 of includes/admin.php:

        if (substr($k,0,1) !== "=")

...and REPLACE with:

        if (substr($k,0,1) == "?")
        {
          $regexp = substr($k,1);
          $matched = TRUE;
          $exps = explode("&",$regexp);
          foreach($exps as $exp)
          {
            $exp = trim($exp);
            if (!preg_match($exp,$text))
            {
              $matched = FALSE;
              break;
            }
          }
          if ($matched)
          {
            $importRecord["category"] = $v;
            break;
          }
        }
        elseif (substr($k,0,1) !== "=")

With that in place, a single expression using logical OR would be

?(keyword1|keyword2|keyword3)

To logical AND together 2 keyword lists, use:

?(keyword1|keyword2|keyword3)&(keyword4|keyword5|keyword6)

And to exclude keywords, use ^ infront, e.g.

?(keyword1|keyword2|keyword3)&(keyword4|keyword5|keyword6)&(^keyword7)

So in the last example, to match the category would have to contain 1 of keyword1, keyword2 or keyword3, AND one of keyword4, keyword5 or keyword6 AND not contain keyword7

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by lisbali12 on Thu, 2012-10-04 09:50

That's brilliant, thank you so much David!

Submitted by smartprice24 on Thu, 2017-10-26 15:51

Hi David.

Is possible use this interesting function to mapping for hierarchy categories.

Many thanks for support and your time.
Giuseppe

Submitted by support on Fri, 2017-10-27 08:41

Hello Giuseppe,

Sure - to add regexp match option for Category Hierarchy Mapping, edit includes/admin,php and look for the following code at line 424:

        if (substr($k,0,1) !== "=")

...and REPLACE with:

        if (substr($k,0,1) == "?")
        {
          $regexp = substr($k,1);
          $matched = TRUE;
          $exps = explode("&",$regexp);
          foreach($exps as $exp)
          {
            $exp = trim($exp);
            if (!preg_match($exp,$importRecord["category"]))
            {
              $matched = FALSE;
              break;
            }
          }
          if ($matched)
          {
            $importRecord["categoryid"] = $v;
            break;
          }
        }
        elseif (substr($k,0,1) !== "=")

If you wanted to test against more than just the feed category name, e.g. product name also, then in place of this line:

  if (!preg_match($exp,$importRecord["category"]))

...you could use:

  if (!preg_match($exp,$importRecord["category"]." ".$importRecord["name"]))

Cheers,
David.
--
PriceTapestry.com

Submitted by smartprice24 on Fri, 2017-10-27 17:29

Thank you very much, David.
This mod works perfectly in hierarchy categories.
Always kind.

Giuseppe