You are here:  » How To Allow Duplicate Product Names For Single Merchant


How To Allow Duplicate Product Names For Single Merchant

Submitted by keshavkshirsagar on Fri, 2015-09-04 13:01 in

Hello Sir

How We Can Allow Duplicate Product Names

I have CSV's With Same Product Name though they have different (Diff Price according to Product Color,Product Images)

I would like to modify the code to check the duplication as a combination of product name and product id. I have read the forum, but could you help me with the code changes in the pages. Also we need the product name to remain unchanged as it would affect the mapping if the name is modified.

We are using pricetapestry 15/09A (Beta)

Submitted by support on Sat, 2015-09-05 09:30

Hi,

The easiest way to allow duplicate products per merchant is to drop the dupe_filter unique key which is the mechanism through which the duplicate prevention is implemented. To do this, simply run the following dbmod.php script in the top level folder of your Price Tapestry installation, delete the file, and then re-import all feeds to allow the duplicates in:

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
$sql "TRUNCATE `".$config_databaseTablePrefix."products`";
  
database_queryModify($sql,$result);
  
$sql "DROP INDEX dupe_filter ON `".$config_databaseTablePrefix."products`";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

To re-instate duplicate prevention on an installation where the above script has been applied, use the following script:

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
$sql "TRUNCATE `".$config_databaseTablePrefix."products`";
  
database_queryModify($sql,$result);
  
$sql "CREATE UNIQUE INDEX dupe_filter ON `".$config_databaseTablePrefix."products` (dupe_hash)";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Notice that both scripts TRUNCATE (empty) the products table first, so after running the scripts there will be no products on your site and a full import will be required (this won't affect your product mapping at all, that all stays in place in other tables...)

Cheers,
David.
--
PriceTapestry.com

Submitted by keshavkshirsagar on Sat, 2015-09-05 11:40

Thank David

One more question
If we will do duplicate entry.

Will affect Product Comparison & existing product Mapping
Or How will Work Product Comparison

Submitted by support on Sat, 2015-09-05 12:31

Hi,

Product Mapping will be applied to all instances of the same product name for the same merchant, so there will still only be 1 price comparison page for the product name, but it may contain multiple entries for the same merchant, that's all.

if you have added custom fields to your site and furthermore added columns for the custom fields to the price comparison table (html/prices.php) then this is where users would be able to differentiate between the different versions.

If the different versions of the same product are different prices, they will be in price order (lowest to highest) just as if they were from different merchants.

Cheers,
David.
--
PriceTapestry.com

Submitted by keshavkshirsagar on Mon, 2015-09-07 14:03

Thank you David!

Submitted by keshavkshirsagar on Wed, 2015-09-09 11:22

Hello David

I have shown product variations in product page of same compare merchant

How we I can hide numMerchants count of same Merchants ie 2 compare ,3 compare in category or in search result page

if product entry 3 times duplicate from same Merchant it should count only 1 compare or more info instead of showing 3 compare

Duplicate names of single merchant count should be 1

Submitted by support on Wed, 2015-09-09 11:55

Hi,

This would need to be done with a re-query as the search results SQL can only include one grouping however the necessary query can be executed entirely from indexes so will be very fast and should not impact page speed at all. To give it a go, edit search.php and look for the following code at line 493:

  $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);

...and REPLACE with:

  $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
  $sql4 = "SELECT COUNT(DISTINCT(merchant)) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($searchresults["products"][$k]["name"])."'";
  database_querySelect($sql4,$rows4);
  $searchresults["products"][$k]["numMerchants"] = $rows4[0]["numMerchants"];

Cheers,
David.
--
PriceTapestry.com

Submitted by keshavkshirsagar on Wed, 2015-09-09 12:04

Its perfect Thanks :)

Submitted by keshavkshirsagar on Wed, 2015-09-09 13:20

Hello Sir

Should we required to remove bellow code

if ($parts[0]=="merchant")
{
  $sql4 = "SELECT COUNT(id) AS numMerchants
FROM `".$config_databaseTablePrefix."products`
WHERE name='".database_safe($searchresults["products"][$k]["name"])."'";
database_querySelect($sql4,$rows4);
$searchresults["products"][$k]["numMerchants"] = $rows4[0]["numMerchants"];
}

Because if we remove this code suggested new code for line 493 working

Submitted by support on Wed, 2015-09-09 13:24

Yes - remove that mod as the new code for line 493 will take over providing that functionality...

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Thu, 2017-04-06 14:38

Hi David,
I have a merchant with same product names (but different images) that I want to allow duplicate names. Can this be done per merchant only? Also using 15/09A.

Submitted by support on Fri, 2017-04-07 06:42

Hi,

You could add the image URL to the string from which the duplicate key value is generated for a specific merchant - to try this, edit includes/admin.php and look for the following code around line 481:

    $dupe_key = $importRecord["merchant"];

...and REPLACE with:

    $dupe_key = $importRecord["merchant"];
    $allowDupes = array("Merchant Name");
    if (in_array($importRecord["merchant"],$allowDupes))
    {
      $dupe_key .= $importRecord["image_url"];
    }

Using in_array makes it easy to apply the same code to more than one merchant, so if you want to apply the same to another merchant in the future, use for example;

    $allowDupes = array("Merchant 1","Merchant 2");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Ride on Fri, 2017-06-16 15:00

Is that mod still valid for 16/10A?
Thank you!

Submitted by support on Fri, 2017-06-16 15:06

Hello Ride and welcome to the forum!

Yes - the mod described is valid for 16/10A distribution / line-numbering...

Cheers,
David.
--
PriceTapestry.com

Submitted by Ride on Fri, 2017-06-16 15:13

Fastest support ever!
Thank you

Submitted by bodybuildingcom... on Mon, 2018-02-19 00:17

Hi David,

I have imlemented the mod, but I still get duplicates showing on the product page eg: {link saved}

I have replaced the code in search.php

FROM

  $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);

TO

  $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
  $sql4 = "SELECT COUNT(DISTINCT(merchant)) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($searchresults["products"][$k]["name"])."'";
  database_querySelect($sql4,$rows4);
  $searchresults["products"][$k]["numMerchants"] = $rows4[0]["numMerchants"];

I also saw the earlier comment from keshavkshirsagar to remove the following code in order to remove the duplicates on the product page:

if ($parts[0]=="merchant")
{
  $sql4 = "SELECT COUNT(id) AS numMerchants
FROM `".$config_databaseTablePrefix."products`
WHERE name='".database_safe($searchresults["products"][$k]["name"])."'";
database_querySelect($sql4,$rows4);
  $searchresults["products"][$k]["numMerchants"] = $rows4[0]["numMerchants"];
}

Could you please tell me where this is? I don't seem to see it in the search.php file.

Thanks.

Norbert

Submitted by support on Mon, 2018-02-19 09:23

Hello Norbert,

I see from your example link that duplicates are being imported so I'm wondering if it was actually to show the total number of products rather than just the number of distinct merchants in this case, which is no problem.

To do this for standalone Price Tapestry, edit search.php and look for the following code at line 502:

      $searchresults["numRows"] = $numRows;

...and REPLACE with:

      $searchresults["numRows"] = $numRows;
      if (isset($parts[1]))
      {
        $names = array();
        foreach($rows as $row)
        {
          $names[] = "'".database_safe($row["name"])."'";
        }
        $in = implode(",",$names);
        $sql4 = "SELECT name,COUNT(id) AS numMerchants,MIN(price) as minPrice FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY search_name";
        database_querySelect($sql4,$rows4);
        $requery = array();
        foreach($rows4 as $row4)
        {
          $requery[$row4["name"]] = $row4;
        }
      }

And then the following code at (now) line 553:

        $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);

...and REPLACE with:

        $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
        if (isset($parts[1]))
        {
          $searchresults["products"][$k]["numMerchants"] = $requery[$product["name"]]["numMerchants"];
          $searchresults["products"][$k]["minPrice"] = $requery[$product["name"]]["minPrice"];
        }

Apologies if mis-understood, let me know if you're still not sure and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by bodybuildingcom... on Mon, 2018-02-19 18:34

Hi David,

Thank you for the speedy response.

I have tried the code solution you have posted. Unfortunately, it didn't do the trick. I have re-imported the feeds as well.

What I am looking to do is, I have imported all the products from all the feeds, including the duplicates. The reason for that is, it seems that when I de-dupe the feed and import only one instance, most of the image links are broken for some reason. It's something to do with the feed, I think. Now, I noticed that the pictures seem to be fine for pretty much all of them except, for the odd one out.

What I would like to do is, to only show one instance on the product page, rather than all of the prices appearing multiple times i.e. {link saved}

Not sure whether this is possible? Some of the early feeds from the merchants haven't been that great unfortunately.

Thanks.

Norbert

Submitted by support on Tue, 2018-02-20 08:36

Hello Norbert,

To both de-duplicate on the product page and also to pick the longest description and make sure that if there is no image_url in the first record one is used from another record if available, edit html/product.php and look for the following code at line 2:

  $product_main = $product["products"][0];

...and REPLACE with:

  $product_main = $product["products"][0];
  $product_merchants = array();
  foreach($product["products"] as $k => $p)
  {
    if (strlen($p["description"]) > strlen($product_main["description"]))
    {
      $product_main["description"] = $p["description"];
    }
    if ($p["image_url"] && !$product_main["image_url"])
    {
      $product_main["image_url"] = $p["image_url"];
    }
    if (in_array($p["merchant"],$product_merchants))
    {
      unset($product["products"][$k]);
    }
    $product_merchants[] = $p["merchant"];
  }

I notice from your example links that you're referring to an installation in the /pt/ sub-directory so you may be using the WordPress plugin, in which case, bear in mind that the above will only apply to the product page in the standalone Price Tapestry installation. If once this is working how you want and you need to apply the same in the plugin, let me know which version you are running (2 or 3/Beta) and I'll work out the equivalent changes...

Cheers,
David.
--
PriceTapestry.com

Submitted by bodybuildingcom... on Tue, 2018-02-20 22:28

Hi David,

I have implemented the code, but the product page is now blank when I click on the products.
I have re-imported the feeds.

A couple of examples:

{link saved}

The products are visible in the results pages, but not in the products:

{link saved}

Thanks.

Norbert

Submitted by support on Wed, 2018-02-21 08:53

Hello Norbert,

Sorry about that - please could you email me your modified html/product.php and I'll check it out...

Cheers,
David.
--
PriceTapestry.com

Submitted by bodybuildingcom... on Wed, 2018-02-21 11:40

Hi David,

No problems. I have sent you an email across with the product.php attached.

Thanks.

Norbert