You are here:  » Populate custom product mapping fields with values from feed


Populate custom product mapping fields with values from feed

Submitted by endurado on Sat, 2013-12-14 17:13 in

Hello David,

to reduce effort of maintenance I'm thinking about automaticly populate some custom product mapping fields with values from the feeds, that are written in custom content fields (e.g. ean, sku, maybe parts exploded from description). The values should be taken from preferred merchants feed (order of maybe 3 merchants) .

As I'm using Niche Mode there must be some checking against product mappings while importing feeds and I'm wondering if it might be possible to populate the custom product mapping fields (if still empty) in the feed import process. And can you please tell me, which function is checking, if a product from the feed is matching a product mapping and will be imported in niche mode?

Or would it be better to check the fields when opening a product page and if empty then insert the preferred merchants value from product table?

Thanks for any thoughts and ideas.

Regards
Sven

Submitted by support on Sun, 2013-12-15 10:01

Hello Sven,

Yes that could work reasonably easily. Niche mode is implemented within the import record handler function in includes/admin.php by the following code beginning at line 317:

    /* niche mode */
    if ($config_nicheMode)
    {
      if (!in_array($importRecord["name"],$admin_importProductMappings)) return;
    }

So if the code executes beyond that point, you know that the product name has a Product Mapping entry and would be able to update if required.

The filename of the feed being imported at this point in the code is in the variable $admin_importFeed["filename"]. It sounds from your comments as if you have already added custom Product Mapping fields and will have made changes in includes/admin.php by adding them to the $admin_importProductMappingsOverrides and will have a modification just a few lines above the following point for example:

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

(if that's the not the case let me know and I'll guide you through that)

Once in place, at the point identified above we can see if

if the filename being imported is one of the preferred feeds
...and if the $admin_importProductMappingsOverrides["ean"] is empty
...and $importRecord["ean"] is not empty
then update pt_productsmap accordingly, which can be done like this:

  $preferredFeeds = array("filename1.xml","filename2.xml","filename3.csv");
  if (
     (in_array($admin_importFeed["filename"],$preferredFeeds))
     &&
     (!$admin_importProductMappingsOverrides["ean"])
     &&
     ($importRecord["ean"])
     )
  {
    $sql = "UPDATE `".$config_databaseTablePrefix."productsmap` SET ean = '".database_safe($importRecord["ean"])."' WHERE name= '".database_safe($importRecord["name"])."'";
    database_queryModify($sql,$result);
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by endurado on Mon, 2013-12-16 07:30

Thanks a lot David for your support! This works out of the box, easier than I expected...
Sven