You are here:  » 'Keyword Mapping' - Search 'Product Name' field and write to 'keyword' field

Support Forum



'Keyword Mapping' - Search 'Product Name' field and write to 'keyword' field

Submitted by peterb on Thu, 2012-03-08 17:32 in

Hi David,

I would like to duplicate the 'Category Mapping' feature in my admin and use the same functionality as it does, but apply it to some different fields.

I would like to have a page called 'Keyword Mapping'.
1. CLICK NEW to add a new keyword (to the established 'keyword' field in my database)
2. KEYWORD MAPPING HELPER to search through 'Product Names' (from imported feeds)
3. ALTERNATIVES lists all the matches that the keyword will be applied to.

Any help would be greatly appreciated.

Submitted by support on Fri, 2012-03-09 09:22

Hi Peter,

A generic solution that doesn't involve new admin pages or database tables would be to re-purpose Category Mapping so that the functionality can be applied to any field by using a fieldname/ prefix as the "master" name, for example

category/Red Widgets

...would create a Category Mapping, whereas

keywords/Keyword List

...would create a Keyword Mapping.

To implement this, 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(FALSE)

Next, in includes/admin.php look for the following section beginning at line 233:

    /* apply category mappings */
    if (isset($admin_importCategoryMappings["=".$importRecord["category"]]))
    {
      $importRecord["category"] = $admin_importCategoryMappings["=".$importRecord["category"]];
    }
    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["category"],$word) !== FALSE) $found++;
            }
          }
          if ($found == count($words))
          {
            $importRecord["category"] = $v;
            break;
          }
        }
      }
    }

...and REPLACE with:

    /* apply category mappings */
    global $mappingFields;
    if (!isset($mappingFields))
    {
      $mappingFields = array();
      foreach($admin_importCategoryMappings as $k => $v)
      {
        $parts = explode("/",$v);
        $mappingFields[$parts[0]] = 1;
      }
    }
    foreach($mappingFields as $field => $v)
    {
    if (isset($admin_importCategoryMappings["=".$importRecord[$field]]))
    {
      $parts = explode("/",$admin_importCategoryMappings["=".$importRecord[$field]]);
      if ($parts[0]==$field])
      {
        $importRecord[$field] = $parts[1];
      }
    }
    else
    {
      foreach($admin_importCategoryMappings as $k => $v)
      {
        $parts = explode("/",$v);
        if ($parts[0] != $field) continue;
        $v = $parts[1];
        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