You are here:  » Product Mapping Feed

Support Forum



Product Mapping Feed

Submitted by steveb on Tue, 2009-04-07 12:32 in

Thanks for the help so far.

Would it be possible to amend productsmap.php to load a "Product Mapping feed" using csv format, via the product mapping admin page, as I find it much quicker to manipulate merchant feeds in a spreadsheet to search/find cut/past similar named items etc. This would save hours of time entering 1000s of product mappings via the admim page. Plus it would allow me to keep a local copy in a spreadsheet for easy updates.

Example Product Mapping feed:

Product_name, Merchant1, Merchant2
Ryobi CDI1803M Combi Drill, Ryobi 18V Combi Drill 13mm Ryobi CDI 1803M, Ryobi 18v 3 Speed HammerDrillDriver CDI1803M
Ryobi CHP1802M Drill, Ryobi 18V Drill Driver 13mm Ryobi CHP 1802M, Ryobi 18v 2 Speed DrillDriver CHP1802M
Ryobi CAP1801M Angle Drill, Ryobi 18V 10mm Angle Drill Ryobi CAP 1801M, Ryobi 18v Angle Drill CAP1801M
Ryobi EBS8021V Belt Sander, Ryobi 230V 800W Belt Sander Ryobi EBS 8021V, Ryobi 76mm 3 Belt Sander EBS 8021V

Submitted by support on Tue, 2009-04-07 12:45

Hi Steve,

Of course - if you upload your product mapping file to your /feeds/ folder as productmapping.txt, here's a quick import script that will load the mappings from the file for you, to be run from the /admin/ folder:

pmimport.php

<?php
  
require("../includes/common.php");
  
$input "../feeds/productmapping.txt";
  
$inputf fopen($input,"r");
  if (!
$inputf) die("Could not open input file!");
  while(!
feof($inputf))
  {
    
$line fgets($inputf);
    
$fields explode(",",$line);
    
$name array_shift($fields);
    
$alternates "";
    foreach(
$fields as $field)
    {
      
$alternates .= $field."\n";
    }
    
$sql "DELETE FROM `".$config_databaseTablePrefix."productsmap`
            WHERE name='"
.database_safe($name)."'";
    
database_queryModify($sql,$result);
    
$sql "INSERT INTO `".$config_databaseTablePrefix."productsmap`
            SET name='"
.database_safe($name)."',alternates='".database_safe($alternates)."'";
    
database_queryModify($sql,$result);
  }
  print 
"Done.";
?>

No need for a header row; the script will just take the first column as the master product name, and then as many other columns as there are as the alternatives. There don't need to be the same number on each row. NOTE that this will delete the existing product mapping record for any products in the productmapping.txt feed!

Hope this helps!

Cheers,
David.

Submitted by steveb on Tue, 2009-04-07 13:29

Wow great thanks

I assume I can still edit these mappings from the Admin page (as Existing Products) once loaded?

I assume exporting product mappings from the database would also be a similar task?
Just thinking about other PT users who have created similar mappings already and would perhaps appreciate a script to extract them in a csv format for easy editing?

Cheers

Steve

Submitted by support on Tue, 2009-04-07 15:42

Hi Steve,

Sure - you can still edit once imported. Try something like this to export:

pmexport.php

<?php
  header
("Content-Type: application/octet-stream");
  
header("Content-Disposition: attachment; filename=productmapping.txt");
  require(
"../includes/common.php");
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."productsmap` ORDER BY name";
  
database_querySelect($sql,$productsmap);
  foreach(
$productsmap as $productmap)
  {
    print 
$productmap["name"].",";
    
$alternates explode("\n",$productmap["alternates"]);
    print 
implode(",",$alternates);
    print 
"\n";
  }
?>

I wouldn't overwrite any existing productmapping.txt with the output from this until you're happy that it's working correctly...

Cheers,
David.