You are here:  » Category Mapping Wild Card


Category Mapping Wild Card

Submitted by clare on Tue, 2008-02-19 13:19 in

Is it possible to use a wild card in mapping categories,

So if a feed has categories that many start with say
Office furniture / chairs
Office furniture /tables

That in mapping I could use a wild card for anything after
Office furniture *

To be mapped into a defined category?

Submitted by support on Tue, 2008-02-19 13:45

Hello Clare,

This could be made more comprehensive, but here is a quick solution that will support matching anything up to the * (in other words, the part you match has to be at the beginning).

In includes/admin.php, look for the following code (search for "apply category mappings"):

    /* apply category mappings */
    if (isset($admin_importCategoryMappings[$category]))
    {
      $category = $admin_importCategoryMappings[$category];
    }

Replace this with the following code:

    /* apply category mappings */
    if (isset($admin_importCategoryMappings[$category]))
    {
      $category = $admin_importCategoryMappings[$category];
    }
    else
    {
      foreach($admin_importCategoryMappings as $k => $v)
      {
        if ($x = strpos($k,"*"))
        {
          $a = substr($k,0,$x);
          $b = substr($category,0,$x);
          if ($a == $b)
          {
            $category = $v;
          }
        }
      }
    }

For performance reasons, this will apply the normal, full match mapping first (if it exists), and then go on to try the wildcard matches if there is no normal match.

Hope this helps!
Cheers,
David.

Submitted by clare on Tue, 2008-02-19 13:50

Thanks that is really useful for some of the feeds with particularly detailed category fields.

Submitted by bem on Sat, 2013-04-06 20:06

Hi David ,

Will something like this work in the new PT update? One of my merchants lists their products like this:
BOOKS Science Nature
BOOKS Science Fiction Fantasy
BOOKS Fiction Science Fiction Fa
BOOKS Horror

But that's not my problem, there's just so many and I just have them product mapped as Books.

They keep adding a few different ones, listing categories slightly differently when adding new books. Some category names are really long as well, and as I can't see what the full category name is it won't map - like "BOOKS Fiction Science Fiction Fa". If I change it to "BOOKS Fiction Science Fiction Fantasy" though it does. But that relies on me being able to guess what the word is.

I have one category called "Gadgets Memorabilia Television H". No idea what the H stands for (the feed is just over 500mb, so can't really search it every time a new one is added).

I was hoping that wildcards could still be used to help out with this. Or if there's a way to do it already within PT?

Submitted by support on Sun, 2013-04-07 08:48

Hello bem,

To accommodate the new indexes in 13/03A the `category` field was shortened to 32 characters which is why you are seeing truncated values, however there is actually scope to increase it to around 200 but since the storage requires of DECIMAL fields varies by MySQL build / platform (which is also part of the same index) it's probably best to go not quite as much as that.

The following dbmod.php script will adjust the `category` field to 150 characters, which should then make your mapping easier and work as before:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            CHANGE `category` `category` VARCHAR(150) NOT NULL default ''"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Cheers,
David.
--
PriceTapestry.com