You are here:  » Duplicate products with different prices


Duplicate products with different prices

Submitted by jamie on Tue, 2016-09-20 19:42 in

Hi David,

One last question, I promise!

When importing all my products, all the duplicates are deleted and only one product is left (which is excellent!).

However, I am noticing the prices on some products on my PT site do not match up with the merchant.

Upon further investigation in the feed files...

--PRODUCT NAME-- --PRICE-- --MERCHANT--
Urban Helmet 2016 -- 54.99 -- XYZ
Urban Helmet 2016 -- 54.99 -- XYZ
Urban Helmet 2016 -- 54.99 -- XYZ
Urban Helmet 2016 -- 54.99 -- XYZ
Urban Helmet 2016 -- 54.99 -- XYZ
Urban Helmet 2016 -- 44.99 -- XYZ
Urban Helmet 2016 -- 54.99 -- ABC
Urban Helmet 2016 -- 54.99 -- ABC
Urban Helmet 2016 -- 54.99 -- ABC
Urban Helmet 2016 -- 54.99 -- ABC
Urban Helmet 2016 -- 54.99 -- ABC
Urban Helmet 2016 -- 44.99 -- ABC

It looks like PT is taking the first price - so on my site the price is showing £54.99 but it should infact be £44.99.

How can I change the code to take the cheapest price for duplicated products, instead of just the first price?

(I have no idea where to even start to code this up myself - I am learning though!)

Many thanks for your help as always,
Jamie

Submitted by support on Wed, 2016-09-21 08:43

Hi Jamie;

Logically this is straight forward however it does require a select operation in order to check whether the same product has already been imported, but dupe_hash is indexed so it should not have too much impact on performance.

To do this, edit includes/admin.php and look for the following code at line 503:

    $sql = sprintf("INSERT IGNORE INTO `".$config_databaseTablePrefix.$table."` SET

...and REPLACE with:

    $sql = "SELECT price FROM `".$config_databaseTablePrefix.$table."` WHERE dupe_hash='".$dupe_hash."'";
    if (database_querySelect($sql,$rows))
    {
      if ($rows[0]["price"] > $importRecord["price"])
      {
        $sql = "DELETE FROM `".$config_databaseTablePrefix.$table."` WHERE dupe_hash='".$dupe_hash."'";
        database_queryModify($sql,$result);
      }
    }
    $sql = sprintf("INSERT IGNORE INTO `".$config_databaseTablePrefix.$table."` SET

(theoretically this could be done in memory by creating a hash table of the currently imported price for a given dupe_hash but since memory is limited and there is no guarantee that sufficient memory would be available, querying the table is the best approach if the impact on import time is not too great...)

Cheers,
David.
--
PriceTapestry.com