You are here:  » Product mapping and WP

Support Forum



Product mapping and WP

Submitted by henk on Mon, 2012-11-19 20:15 in

Hi David,

Is it possible to add custom field in productmapping, and does WP filters are going to be updated.

Or is it possible to make a master merchant ( call it henk.csv or xml :) import this file and use it as products basis information.

Thx
Henk

Submitted by support on Tue, 2012-11-20 08:57

Hi Henk,

It's straight forward to add additional custom fields to Product Mapping so they override any (or missing) values from the feeds. It's is covered in the forum but spread across several threads so I will re-document the changes here for a single custom field - simply repeat for each custom field you wish to add.

Firstly, assuming that you have already added the custom field "colour" according to the normal instructions in this thread, first create and run a corresponding dbmod.php script to add the new field to the `productsmap` table:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."productsmap`
            ADD `colour` VARCHAR(255) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Next, edit admin/productsmap_configure.php and look for the following code at line 70:

  alternates = '".database_safe($alternates)."',

...and REPLACE with:

  alternates = '".database_safe($alternates)."',
  colour = '".database_safe(widget_posted($_POST["colour"]))."',

Next, locate the following code beginning around line 125:

    print "Custom Image URL:<br />";
    print "<input type='text' name='image_url' value='".widget_safe($productmap["image_url"])."' />";
    print "<br /><br />";

...and REPLACE with:

    print "Custom Image URL:<br />";
    print "<input type='text' name='image_url' value='".widget_safe($productmap["image_url"])."' />";
    print "<br /><br />";
    print "Custom Colour:<br />";
    print "<input type='text' name='colour' value='".widget_safe($productmap["colour"])."' />";
    print "<br /><br />";

Next, edit includes/admin.php and locate the following code around line 309:

  if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];

...and REPLACE with:

  if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];
  if ($admin_importProductMappingsOverrides[$importRecord["name"]]["colour"]) $importRecord["colour"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["colour"];

And finally locate the following code around line 483:

  $admin_importProductMappingsOverrides[$productsmap["name"]]["image_url"] = (($productsmap["image_url"])?$productsmap["image_url"]:"");

...and REPLACE with:

  $admin_importProductMappingsOverrides[$productsmap["name"]]["colour"] = (($productsmap["colour"])?$productsmap["colour"]:"");

The custom values will automatically be picked up by your custom filters in WordPress.

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-11-20 10:52

Hi David,

Thx, I implemented this fields is it also possible to group by sku and not search in admin for products to map.

So if there is a master product ( what i have made) use this information for products with the same sku.

Cheers
Henk

Submitted by support on Tue, 2012-11-20 11:31

Hello Henk,

Am I correct in thinking that at is stands the sku would only come from the feed and not be a custom field in Product Mapping?

Would it be convenient to add an sku field to Product Mapping in the way described above so that the custom fields can be loaded into an array indexed by sku and applied that way as well as by name?

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-11-20 12:09

Hi David,

I have added a sku field, how do you loaded it into an array indexed by sku and name ( now the Alternatives are on names ) ?

Thx
Henk

Submitted by support on Tue, 2012-11-20 12:17

Hi Henk,

That's great - now then in includes/admin.php, where you added this code shortly after line 483:

  $admin_importProductMappingsOverrides[$productsmap["name"]]["colour"] = (($productsmap["colour"])?$productsmap["colour"]:"");

...add on the next line (it must go at the end of this block of code, just before the closing } so that the duplicate array indexed by sku contains all the fields:

  $admin_importProductMappingsOverrides[$productsmap["sku"]] = $admin_importProductMappingsOverrides[$productsmap["name"]];

Now, back up in the import record handler function where the overrides are applied, look for the following comment around line 312:

    /* check product record for minimum required fields */

(you'll notice this is just after the block that you will have just modified as per the above instructions) and REPLACE with:

    if (isset($admin_importProductMappingsOverrides[$importRecord["sku"]]))
    {
      if ($admin_importProductMappingsOverrides[$importRecord["sku"]]["colour"]) $importRecord["colour"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["colour"];
    }
    /* check product record for minimum required fields */

The above continues the `colour` example - edit as required; and add any additional lines for other fields as required!

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-11-20 15:34

Super works perfect thx

Henk