You are here:  » Mapping by EAN or by reference


Mapping by EAN or by reference

Submitted by Jordanus on Fri, 2011-12-16 18:02 in

Hello David

Very happy using PT, I need some help to create an automatic mapping rule.

I've create 2 new fields in my config : "ean" and "reference" with your tuto, all is ok. Very great!
Now, I would like matching my products by EAN and if the EAN is not available with some merchants, matching in the same time by reference. Is it possible?

Thank you

Submitted by support on Fri, 2011-12-16 18:08

Hi Jordanus,

Thank you for your comments!

It's straight forward to add additional fields to the Product Mapping comparison logic. In includes/admin.php look for the following code at line 288:

if (strpos($importRecord["name"],$word) !== FALSE) $found++;

...and REPLACE with:

if (
   (strpos($importRecord["name"],$word) !== FALSE)
   ||
   (strpos($importRecord["ean"],$word) !== FALSE)
   ||
   (strpos($importRecord["reference"],$word) !== FALSE)
   )
   $found++;

Cheers,
David.
--
PriceTapestry.com

Submitted by Jordanus on Fri, 2011-12-16 19:09

Thank you for your quick reply!

Also is it possible on a product search to search with the product name: reference, brand name and category at the same time?

Many Thanks, good week-end !
Jordanus

Submitted by support on Fri, 2011-12-16 21:47

Hi Jordanus,

Sure - first of all disable full text indexing in config.advanced.php by replacing line 8 with:

  $config_useFullText = TRUE;

Next, search.php look for the following code at line 229:

  $where .= "search_name LIKE '%".database_safe($word)."%'";

...and REPLACE with:

  $where .= "search_name LIKE '%".database_safe($word)."%'";
  $where .= " OR reference LIKE '%".database_safe($word)."%' ";
  $where .= " OR brand LIKE '%".database_safe($word)."%' ";
  $where .= " OR category LIKE '%".database_safe($word)."%' ";

Cheers,
David.
--
PriceTapestry.com

Submitted by Jordanus on Sat, 2011-12-17 13:34

Thank you David, perfect!

Submitted by Jordanus on Sat, 2011-12-17 18:25

David

Last thing, after this modification above, I tried to apply 2 filters (categories and brands) when there is a product search.
I've used your post http://www.pricetapestry.com/node/212 but it works only for a category search.

I woud like to display these 2 filters on a search result with only the categories and brands available on the products results

I hope you understand my help request
Thank you
Jordanus

Submitted by support on Sat, 2011-12-17 18:45

Hi Jordanus,

It's probably best to start with the latest sidebar filters mod (which you can reduce down if you don't require all of it) available from the download extras page..

As you've already made changes to search.php and I'll merge the sidebar filter components of search.php in your latest version from our email thread and forward that to you now...

Cheers,
David.
--
PriceTapestry.com

Submitted by lisbali12 on Tue, 2012-09-18 15:17

Hi David,

Sorry to hijack this thread - I've got a very similar question. I have too many products to contemplate product mapping and so would like to set up reference number matching. My problem is that while some merchants provide ean numbers, others only provide the mpn (manufacturer's part number) which needs to be matched with the brand to be certain of a correct product identification.

How would I re-write the code so that I could stipulate that mpn AND brand must be matched together? So where I have (strpos($importRecord["mpn"],$word) !== FALSE) as per below, within the same instruction must be "brand"?

if (
(strpos($importRecord["name"],$word) !== FALSE)
||
(strpos($importRecord["ean"],$word) !== FALSE)
||
(strpos($importRecord["mpn"],$word) !== FALSE)
)
$found++;

Hope I've explained that clearly! Sorry, this is probably really fundamental but I'm too much of a code numpty to risk it!

Many thanks as always.

Submitted by support on Tue, 2012-09-18 15:37

Hi,

No problem - this would actually be better matched as an "exact match" condition. At the point you've identifed in includes/admin.php where Product Mapping is applied, at the top of that block of code you'll see where exact match comparison is applied by this code:

    if (isset($admin_importProductMappings["=".$importRecord["name"]]))
    {
      $importRecord["name"] = $admin_importProductMappings["=".$importRecord["name"]];
    }
    else

...(beginning at line 270 in the distribution) so if you REPLACE that with:

    if (isset($admin_importProductMappings["=".$importRecord["name"]]))
    {
      $importRecord["name"] = $admin_importProductMappings["=".$importRecord["name"]];
    }
    elseif (isset($admin_importProductMappings["=".$importRecord["brand"]." ".$importRecord["mpn"]]))
    {
      $importRecord["name"] = $admin_importProductMappings["=".$importRecord["brand"]." ".$importRecord["mpn"]];
    }
    else

With that in place, you'll be able to enter as an Alternative on the configuration page for a Product Mapping:

=Brand MPN

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by koen on Sun, 2013-03-10 12:44

Hi David,

I'm getting more and more feeds containing EAN, but I cant get it working. I've added an EAN field to my import using your "tutorial" above. And I've changed the code in admin.php om line 288 to:

if ($word)
            {
if (
   (strpos($importRecord["EAN"],$word) !== FALSE)
   ||
   (strpos($importRecord["name"],$word) !== FALSE)
   )
   $found++;
            }

I've configured my feeds again and Imported them, but no mapping is being done on the EAN code (nor on the name's, but that is because they're not the same). In PHPMyadmin I can see two records in my products table that should've been mapped by EAN, but they are not. If necessary I can send you the database records.

Can you please help me?

Thanks a lot,
Koen

Submitted by support on Mon, 2013-03-11 08:56

Hello Koen,

The only think I can think of that may be incorrect is that PHP is case sensitive in terms of variable names and array keys, whereas MySQL is not (at least for MyISAM tables anyway). The first thing I would do is have a go with:

if ($word)
{
  if (
   (strpos($importRecord["ean"],$word) !== FALSE)
   ||
   (strpos($importRecord["name"],$word) !== FALSE)
   )
   $found++;
}

If still no joy, if you could email me your config.advanced.php and includes/admin.php i'll check everything over for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by endurado on Thu, 2014-01-16 14:23

Hello David,

I also have a topic related question:
With niche mode switched on, I want to map by EAN (and alternatives). It seems to work, if I add the EAN into pt_productsmap 'alternates' and do the above suggested changes in admin.php. But I have EAN in pt_productsmap field "ean" anyway. Is there an easy solution for ean mapping (additional to alternatives) without adding ean to alternatives?

Thanks a lot,
Sven

Submitted by support on Thu, 2014-01-16 16:08

Hi Sven,

Sure - in includes/admin.php look for the following code at line 471:

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

...and REPLACE with:

  $admin_importProductMappingsOverrides[$productsmap["name"]]["image_url"] = (($productsmap["image_url"])?$productsmap["image_url"]:"");
  if ($productsmap["ean"])
  {
    $admin_importProductMappings[$productsmap["ean"]] = $productsmap["name"];
  }

That will automatically append an ean value if specified explicitly to the Alternatives list.

Cheers,
David.
--
PriceTapestry.com

Submitted by endurado on Fri, 2014-01-17 20:41

Thanks David, this works fine, as always. It gives me more matches than alternates only for some products.
I'm not sure to understand the mapping process 100% and wondering, if while importing the feeds in niche mode, the algorithm is now searching for ean only in the feeds ean field or also in the feeds product name field. It could reduce feed import time, if the alternates from product mapping are only matched with feed product name and ean from product mapping with ean from feed. But maybe it is already like this?
Best regards
Sven

Submitted by support on Sat, 2014-01-18 10:44

Hello Sven,

As it stands with the modification above it will be testing both against both, but is an extremely fast section of code so it wouldn't have any significant impact on import time if they were to be made separate, it at all!

Cheers,
David.
--
PriceTapestry.com