You are here:  » Sku.html To Replace ProductName.html On Product Page


Sku.html To Replace ProductName.html On Product Page

Submitted by Rocket32 on Sat, 2009-01-10 22:46 in

I need to know which files to change in order to get the product page url to change from "product/product.html" to "product/sku.html" or both.
Which files along with the .htaccess file needs to be changed?

Submitted by support on Mon, 2009-01-19 08:35

Hi There,

Have you already added sku as a new field to your database (following the instructions in http://www.pricetapestry.com/node/313)

Cheers,
David.

Submitted by Rocket32 on Tue, 2009-01-20 01:21

Yes I have added the sku field and placed the sku on the product page.
-I am wondering how much work would it be to have the product url as a sku.html instead.
-Also on the comparison table at the bottom of the product page I would like to slip the sku field in there somewhere with sku number along side the name field.
-Where would I find information on parsing a feed with same names and different sku numbers without deleting the products with the different skus? I'm trying to see what would be a better way of adding these products with different skus. I read something earlier about adding a color. I could add the sku if possible. Where would I find this information again?

Submitted by support on Tue, 2009-01-20 10:45

Hi,

With the sku in place in the products table, to make the link become sku.html instead of product.html should just require 2 changes. Firstly, in search.php, look for the following code on line 166:

$searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";

...and REPLACE this with:

$searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["sku"]).".html";

(i'm assuming the field is called "sku")

Then, in products.php, look for the following code on line 12:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;

...and REPLACE this with

$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE sku = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;

To incorporate the sku field into the prices table; in html/prices.php the product name is currently displayed by this code on line 12:

<td><?php print $product["name"]; ?></td>

...so to display the SKU alongside and in brackets, REPLACE this with:

<td><?php print $product["name"]; ?> (<?php print $product["sku"]; ?>)</td>

Regarding the import - you could add the SKU as part of the product name using the filters. To do this, add a Text After filter to the product name, and then enter the following in the text box on the configuration page:

 (%SKU%)

Note the space at the beginning - this is so that the SKU does not immediately follow the product name but leaves a gap - and where SKU is the field name in the feed that contains the SKU. This may mean that you don't need to implement the last part as by doing this the SKU will be shown in the prices table by default...

Cheers,
David.

Submitted by Rocket32 on Wed, 2009-01-21 01:06

Everything worked fine. Thanks.

Will the reviews and related work together with the new sku urls? I noticed when i go to the review page. It goes to /review/productname.html page. I am assuming this still works together with the skus and product names without having to make any changes.

1 Problem I do have is now I cannot seem to get the related items to show anymore on the product page probably because of the sku changes.

Also on the product page, how do I change the following code to show the name instead of the sku? Now the sku shows here instead of the product name.

 $banner["h2"] = translate("Price search results for")." <strong>".htmlentities($q,ENT_QUOTES,$config_charset)."</strong>&nbsp;";

Submitted by support on Wed, 2009-01-21 08:36

Hi,

Both these are easily fixed - it's just because these sections of the code expect the product name to be in $q rather than the SKU. They can be fixed in a single line by mapping $q back to the product name after the database query.

To do this, look for the following code around line 46 of products.php:

$product["products"] = $rows;

..and REPLACE this with:

$product["products"] = $rows;
$q = $product["products"][0]["name"];

Cheers,
David.

Submitted by Rocket32 on Thu, 2009-01-22 01:01

Works perfect. David you are awesome. It does exactly what I needed.

Submitted by Rocket32 on Sun, 2013-11-10 06:28

Hello David. How do I accomplish this same task of sku.html with the latest PT distribution along with compairing by name or sku. But name being first choice of compairing.

Submitted by support on Sun, 2013-11-10 10:42

Hi,

Since the sku comparison mods were posted - which aren't ideal if not every record for the same product has SKU I posted a utility for automatic product mapping by unique ID which you might want to try in preference to linking by sku.html. If you'd rather the original method just let me know and I'll re-document it for 13/03A...

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Sun, 2013-11-10 15:34

I am looking to just change product page from /product/Product_Name.html to /product/Sku.html. In doing that, is it still possible to compair products by name first after doing the automatic product mapping by unique ID?

Submitted by Rocket32 on Tue, 2013-11-12 00:42

Hello David. I'll just rather the re-document for 13/03A on the sku.html. A question I have, is if the old PT version with sku.html already implemented was updated to version 13/03A, would any files need to be adjusted?

Thanks.
Rocket

Submitted by support on Tue, 2013-11-12 09:35

Hi Rocket32,

Firstly in includes/tapestry.php look for the following code at line 67:

    if ($config_useRewrite)
    {
      return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"])).".html";
    }
    else
    {
      return $config_baseHREF."products.php?q=".urlencode($product["normalised_name"]);
    }

...and REPLACE with:

    if ($config_useRewrite)
    {
      return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["sku"])).".html";
    }
    else
    {
      return $config_baseHREF."products.php?q=".urlencode($product["sku"]);
    }

Then, in products.php look for the following code at line 12:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE sku = '".database_safe($q)."'";

...and then the following code at line 124:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";

...and REPLACE with:

      $sql2 = "SELECT id,sku,name,normalised_name,image_url,description,price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";

And finally in search.php, look for the following code at line 374:

  $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

...and REPLACE with:

  $sql2 = "SELECT id,sku,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

In terms of upgrading an earlier distribution - the template files (html/*) are fully backwards compatible but in terms of modification made to the core files these would be overwritten by an upgrade and the changes re-applied. However an alternative that I help users with who have customised earlier distributions is to "back port" the newer features into an earlier distribution, so just let me know if you would like any help with that...

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Wed, 2013-11-13 04:18

Hello David, First off I made a mistake in asking to compare by name. I want to compare by price & change product url to sku.html. I changed the 3 files as mentioned. But I get the following error when clicking on /product/sku.html page.

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

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

When changing back to old products.php, no error occurs.

Submitted by support on Wed, 2013-11-13 10:39

Hi Rocket32,

If you could temporarily enable database debug mode by changing line 6 of config.advanced.php as follows:

  $config_databaseDebugMode = TRUE;

...and then view the page with the mods in place again, extended MySQL error information will be displayed that should indicate the problem - let me know what is displayed and I'll check it out for you...

Thanks,
David.
--
PriceTapestry.com