You are here:  » Grouping products also with EAN code

Support Forum



Grouping products also with EAN code

Submitted by redspark on Tue, 2010-01-12 14:32 in

Hi David,

I have added an extra field (very easy thanx to the config.advanced) in my database and in the feed registration. I had a look at: http://www.pricetapestry.com/node/775
to see how i can group products based on the ean code as well on the product name. But the code in products.php seems to be rewritten and i cant figure it out. Can you help me?

regards,

B.

Submitted by support on Tue, 2010-01-12 15:39

Hi,

The replacement code for the latest distribution, in products.php, look for the following code starting at line 12:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."' ORDER BY price";
    $numRows = database_querySelect($sql,$rows);

...and REPLACE with:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."' ORDER BY price";
    $numRows = database_querySelect($sql,$rows);
    $sku = "";
    foreach($rows as $row)
    {
      if ($row["sku"])
      {
        $sku = $row["sku"];
        break;
      }
    }
    if ($sku)
    {
      $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."' OR sku='".database_safe($sku)."' ORDER BY price";
      $numRows = database_querySelect($sql,$rows);
    }

(of course if you've used ean instead of sku as the new field just replace as appropriate)

Hope this helps!

Cheers,
David.

Submitted by philstone on Tue, 2010-03-16 16:28

hi david

just trying the ean code - works great

some feeds have an issue that there are several product entries with the same ean code - not sure why, culprit happens tobe dixons, currys etc, is there a way to delete ean products that occur more than once in the same feed so that none of the duplicates are imported as this is better than wrong price comparison results

regards

Phil Stone
www.buy24-7.net

Submitted by support on Wed, 2010-03-17 09:55

Hi Phil,

Sure, you could conditionally construct dupe_hash based on the ean field (if one exists). In includes/admin.php (latest distribution); look for the following code on line 297:

    $dupe_key .= $normalisedName;

...and REPLACE with:

    if ($importRecord["ean"])
    {
      $dupe_key .= $importRecord["ean"];
    }
    else
    {
      $dupe_key .= $normalisedName;
    }

Cheers,
David.

Submitted by philstone on Thu, 2010-03-18 16:55

thanks david, works perfect,

was wondering as well, for products that have an empty ean field, is there a way that they will not be dragged into a comparison product page with other products with empty ean's?

regards

Phil Stone
www.buy24-7.net

Submitted by support on Thu, 2010-03-18 17:55

Hi Phil,

That shouldn't be happening - the code above (in products.php) looks for an EAN and only uses it for comparison if one is found. The above code is based on "sku" rather than "ean", so double check that you have replaced every occurrence correctly. If you're still not sure, if you could email me your products.php i'll check it out for you...

Cheers,
David.

Submitted by philstone on Thu, 2010-03-18 20:40

Sorry, overlooked that, works perfect now

thanks yet again!!!

regards

Phil Stone
www.buy24-7.net

Submitted by philstone on Thu, 2010-03-25 16:29

hi David

was wondering is there a mod can be made to this products.php to allow products without a matching ean number but that compare under a different product name appear on the comparison table?

eg

at the minute if you go to AEG HC3360M there are 8 products compared, but only 7 compared when someone goes to AEG Chimney Hood HC3360M Stainless Steel

regards

Phil Stone
www.buy24-7.net

Submitted by support on Thu, 2010-03-25 16:33

Hi Phil,

Can you email me the latest products.php and I'll check what's going on there...

Cheers,
David.

Submitted by philstone on Mon, 2010-11-29 11:46

hi david

just getting this implemented in the new script

i get this error when i upload the code above:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/buy247/public_html/includes/database.php on line 27

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/buy247/public_html/includes/database.php on line 32

Warning: Cannot modify header information - headers already sent by (output started at /home/buy247/public_html/includes/database.php:27) in /home/buy247/public_html/products.php on line 92

Warning: Cannot modify header information - headers already sent by (output started at /home/buy247/public_html/includes/database.php:27) in /home/buy247/public_html/products.php on line 93

the lines in products.php are

line 92: header("HTTP/1.1 301 Moved Permanently");
line 93: header("Location: ".$config_baseHREF.tapestry_hyphenate($rows[0]["name"]).".html");
 

could you please advise me on what i am doing wrong,
thanks
philip

www.buy24-7.net

Submitted by support on Mon, 2010-11-29 12:47

Hi Phil,

As it's a database error, my guess is that the ean field has not yet been added to the products table - instructions and dbmod.php for the latest version are in this thread.

If that all looks OK, enable database debug mode by changing line 6 of config.advanced.php as follows:

  $config_databaseDebugMode = TRUE;

...then browse to the page again and let me know what error message is displayed as that should indicate the problem...

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Mon, 2012-03-19 12:40

I have a problem with the compare prices on ean, it shows not the lowest prices on searchresult and related products. Is it easy to change that?

ALECTO DBX82

{link saved}

{link saved}

Thx
Henk

Submitted by support on Mon, 2012-03-19 16:30

Hello Henk,

The easiest work around for this would be to re-query for lowest price by ean or name at the top of html/searchresults.php - have a go with:

<?php
  
foreach($searchresults["products"] as $k => $p)
  {
    if (
$p["ean"])
    {
      
$sql "SELECT price FROM `".$config_databaseTablePrefix."products` WHERE ean='".datbase_safe($p["ean"])."' OR normalised_name = '".database_safe($p["normalised_name"])."' ORDER BY price LIMIT 1";
      
database_querySelect($sql,$result);
      
$searchresults["products"][$k]["price"] = $result[0]["price"];
      
$searchresults["products"][$k]["minPrice"] = $result[0]["minPrice"];
    }
  }
?>

Cheers,
David.
--
PriceTapestry.com