You are here:  » Category Mapping for subcat


Category Mapping for subcat

Submitted by henk on Sun, 2012-11-11 14:17 in

Hi David,

I want to use Category Mapping for subcat mapping is that possible?

Thx
Henk

Submitted by support on Sun, 2012-11-11 15:15

Hi Henk,

Assuming that there is no overlap in values (which I assume there wouldn't be) then the Category Mapping interface can be used; and then Category Mapping modified to apply to your custom subcat field also.

To do this, look for the following comment in includes/admin.php

    /* apply category mappings */

(line 233 in 12/10B distribution)

Then insert above that line the following new section

    /* apply subcat mappings */
    if (isset($admin_importCategoryMappings["=".$importRecord["subcat"]]))
    {
      $importRecord["subcat"] = $admin_importCategoryMappings["=".$importRecord["subcat"]];
    }
    else
    {
      foreach($admin_importCategoryMappings as $k => $v)
      {
        if (substr($k,0,1) !== "=")
        {
          $found = 0;
          $words = explode(" ",$k);
          foreach($words as $word)
          {
            if ($word)
            {
              if (strpos($importRecord["subcat"],$word) !== FALSE) $found++;
            }
          }
          if ($found == count($words))
          {
            $importRecord["subcat"] = $v;
            break;
          }
        }
      }
    }

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Mon, 2012-11-12 09:34

Hi David,

I think there will be overlapping, i want to use the normal category also in subcat:

10 basis categories
then subcat

Thnx
Henk

Submitted by support on Mon, 2012-11-12 14:07

Hi Henk,

You could make a "generic" version whereby your master "Category Mapping" names could be

fieldname:Master Name

e.g.

subcat:Blue Widgets

...and then in the Alternatives box on the configuration page you would list the alternatives for the Blue Widgets subcategory.

Firstly in admin/categories.php look for the following code at line 20:

if(!preg_match("/^[0-9a-zA-Z\. ]{0,255}$/",widget_posted($_POST["name"])))

...and REPLACE with:

if(!preg_match("/^[0-9a-zA-Z:\. ]{0,255}$/",widget_posted($_POST["name"])))

That will let you create a "master" Category Name containing ":".

Then in includes/admin.php look for the following code at line 454:

  $admin_importCategoryMappings[$alternate] = $category["name"];

...and REPLACE with:

  $parts = explode(":",$category["name"]);
  $admin_importCategoryMappings[$parts[0]][$alternate] = $parts[1];

Then REPLACE the entire /* apply category mappings */ section as follows:

  foreach($admin_importCategoryMappings as $field => $alternatives)
  {
    if (isset($alternatives["=".$importRecord[$field]]))
    {
      $importRecord[$field] = $alternatives["=".$importRecord["field"]];
    }
    else
    {
      foreach($alternatives as $k => $v)
      {
        if (substr($k,0,1) !== "=")
        {
          $found = 0;
          $words = explode(" ",$k);
          foreach($words as $word)
          {
            if ($word)
            {
              if (strpos($importRecord[$field],$word) !== FALSE) $found++;
            }
          }
          if ($found == count($words))
          {
            $importRecord[$field] = $v;
            break;
          }
        }
      }
    }
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Mon, 2012-11-12 19:50

Hi David,

I am using subcat as a filter in WP, the easiest way to map ( i think ) is the combination of category mapping:

sportshoes in the xml>

shoes = 1 filter > category
sport = 2 filter > subcat
etc.

Thx
Henk

Submitted by support on Tue, 2012-11-13 09:12

Hi Henk,

Ah - OK how about this for a thought; what you could do is create master category names optionally containing a forward slash to indicate category/subcat. Then, after category mapping has been applied simply check for a "/" character in the category field and split into category / subcat.

To permit "/" in master Category Mapping names, in admin/categories.php look for the following code at line 20:

if(!preg_match("/^[0-9a-zA-Z\. ]{0,255}$/",widget_posted($_POST["name"])))

...and REPLACE with:

if(!preg_match("/^[0-9a-zA-Z\/\. ]{0,255}$/",widget_posted($_POST["name"])))

And then in includes/admin.php look for the following comment at line 266:

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

...and REPLACE with:

  if (strpos($importRecord["category"],"/"))
  {
    $parts = explode("/",$importRecord["category"]);
    $importRecord["category"] = $parts[0];
    $importRecord["subcat"] = $parts[1];
  }
  /* capture original catalogue product name prior to mapping */

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-11-13 10:09

Hi David,

Aah, i have already the > in use so i can use that one?

Thx
Henk

Submitted by support on Tue, 2012-11-13 10:13

Sure - as the replacement in includes/admin.php use:

  if (strpos($importRecord["category"],">"))
  {
    $parts = explode(">",$importRecord["category"]);
    $importRecord["category"] = $parts[0];
    $importRecord["subcat"] = $parts[1];
  }
  /* capture original catalogue product name prior to mapping */

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-11-13 19:43

And if you want a third one you can use /

Like this:

if (strpos($importRecord["category"],">"))
{
$parts = explode(">",$importRecord["category"]);
$importRecord["category"] = $parts[0];
$importRecord["subcat"] = $parts[1];
}
if (strpos($importRecord["category"],"/"))
{
$parts = explode("/",$importRecord["category"]);
$importRecord["category"] = $parts[0];
$importRecord["subcat2"] = $parts[1];
}

or? :)
Thx
Henk

Submitted by support on Tue, 2012-11-13 19:52

Hello Henk,

You can keep using ">", e.g.

category>subcat>subcat2

Using

  if (strpos($importRecord["category"],">"))
  {
    $parts = explode(">",$importRecord["category"]);
    $importRecord["category"] = $parts[0];
    if (isset($parts[1])) $importRecord["subcat"] = $parts[1];
    if (isset($parts[2])) $importRecord["subca2"] = $parts[2];
  }
  /* capture original catalogue product name prior to mapping */

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-11-13 20:23

Hi David,

Great :)

Thx
Henk

Submitted by henk on Sun, 2013-07-21 11:48

Hi David,

I still use this one to split category>subcat>etc..

But when i use a third split this one doesn't work:

Beeld en Geluid>Audiosystemen en componenten>Cassettedeck

not ok

this one

Beeld en Geluid>Audiosystemen en componenten
is ok

Thx
Henk

Submitted by support on Mon, 2013-07-22 08:04

Hi Henk,

I just noticed a typo in my last reply to you above - $subca2 instead of $subcat2 - have a go with:

  if (strpos($importRecord["category"],">"))
  {
    $parts = explode(">",$importRecord["category"]);
    $importRecord["category"] = $parts[0];
    if (isset($parts[1])) $importRecord["subcat"] = $parts[1];
    if (isset($parts[2])) $importRecord["subcat2"] = $parts[2];
  }
  /* capture original catalogue product name prior to mapping */

That should be all it is!

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Wed, 2013-07-24 09:57

Hi David,

i already changed that, but i think its in the product mapping i have categories like 1>2>3 and this one doesn't split in three parts.

Thx
Henk

Submitted by support on Wed, 2013-07-24 15:01

Hello Henk,

Ah - I wonder if, in this particular case, the separator is not actually ">" but the HTML entity for ">" which is >

There is an HTML Entity Decode filter documented in this comment. If you could add that to your html/filter.php, and then add a new HTML Entity Decode filter to the Category field for the feed that is causing this problem then as long as the filters are executed (which are the first thing carried out within the import record handler) before mapping, then that should do the trick...

If still not joy, if you could email me your latest includes/admin.php and if possible let me know the URL of your installation and the filename of the feed containing the above category and I'll check it out further for you..

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Wed, 2013-07-24 18:59

Hi David,

It's not the feed but i have created it in a special version of product mapping "Custom Category:

And this category doesn't split so i have todo it myself:

now custom category is:

Beeld en Geluid>Televisie>Accessoires televisie

later:
category
beeld en geluid
sbu
Televisie
sub2
Accessoires

Thx
Henk

Submitted by support on Wed, 2013-07-24 19:32

Hi Henk,

No problem - if you could email me your latest includes/admin.php I'll check the code out in context for you...

Thanks,
David.
--
PriceTapestry.com