You are here:  » Unmapped by merchant


Unmapped by merchant

Submitted by ChrisNBC on Tue, 2014-12-02 14:29 in

Hi David,

Hope all is going well.

I'm currently using unmapped.php, I wondered if you might be able to tell me how to modify the script to include the merchant and EAN (if present), ideally into a txt file rather than just dump on screen but if the txt is complicated, just being able to add merchant and ean would be great...

Thanks in advance.

Regards
Chris

Submitted by support on Wed, 2014-12-03 21:59

Hi Chris,

If you're using the code from the first post in this thread then to include `merchant` and `ean` would be just:

<?php
  header
("Content-Type: text/plain");
  require(
"includes/common.php");
  
$filename = (isset($_GET["filename"])?$_GET["filename"]:"");
  
$sql "SELECT name,merchant,ean FROM `".$config_databaseTablePrefix."products` WHERE name NOT IN (SELECT name FROM `".$config_databaseTablePrefix."productsmap`)";
  if (
$filename$sql .= " AND filename='".database_safe($filename)."'";
  
$link = @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
  @
mysql_select_db($config_databaseName,$link);
  
$result mysql_unbuffered_query($sql,$link);
  if (
$result)
  {
    while(
$row mysql_fetch_array($result,MYSQL_ASSOC))
    {
      print 
$row["name"]." - ".print $row["merchant"]." - ".print $row["ean"]."\n";
    }
  }
?>

Notice the replacement of "DISTINCT(name)" with just "name" in this version so that you will capture each different merchant's unmapped products, not just _a_ unmapped product.

To output to a text file, say feeds/unmapped.txt (since feeds/ is normally writable by PHP in a Price Tapestry installation) then you could use:

<?php
  header
("Content-Type: text/plain");
  require(
"includes/common.php");
  
$fp fopen($config_feedDirectory."unmapped.txt","w");
  
$filename = (isset($_GET["filename"])?$_GET["filename"]:"");
  
$sql "SELECT name,merchant,ean FROM `".$config_databaseTablePrefix."products` WHERE name NOT IN (SELECT name FROM `".$config_databaseTablePrefix."productsmap`)";
  if (
$filename$sql .= " AND filename='".database_safe($filename)."'";
  
$link = @mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
  @
mysql_select_db($config_databaseName,$link);
  
$result mysql_unbuffered_query($sql,$link);
  if (
$result)
  {
    while(
$row mysql_fetch_array($result,MYSQL_ASSOC))
    {
      
fwrite($fp,$row["name"]." - ".print $row["merchant"]." - ".print $row["ean"]."\n");
    }
  }
  
fclose($fp);
  print 
"Done.";
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2014-12-04 11:21

Hi David,

Thanks for your quick response.

I modified the script with the above and once I had repointed the call for includes/common the list dumped to screen fine and an 'unmapped' file was generated in the feeds folder. The on screen output is perfect but the text file output only contains a long single line of merchant and product names with no eans and no line breaks. I wondered if you may be able to suggest what's going wrong and how it might be resolved?

Thanks in advance.

Regards
Chris

Submitted by support on Thu, 2014-12-04 11:28

Hi Chris,

Depending on what you're using the view the output file it might need to have \r\n (carriage
return / new line) instead of just \n (new line), but also I recall that your ean field is
actually upper case so needs to be $row["EAN"] - have a go with:

  fwrite($fp,$row["name"]." - ".print $row["merchant"]." - ".print $row["EAN"]."\r\n");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com