You are here:  » Product ID on product detail page

Support Forum



Product ID on product detail page

Submitted by mikecdprice on Mon, 2011-08-29 20:35 in

Hello,

How do I change the product detail mod_rewrite url to or php non-rewrite to change from searching for product to display like golf+club to pull products?ID=434343 would pull up the same page?

Submitted by support on Tue, 2011-08-30 05:43

Hi Mike,

To do this it's probably best to check for $_GET["id"] at the top of products.php and if set, select associated name from the database and then re-populate $_GET["q"] from that as it is used extensively in the rest of the script. To try this, look for the following code at line 2:

  require("includes/common.php");

...and REPLACE with:

  require("includes/common.php");
  if (isset($_GET["id"]))
  {
    $sql = "SELECT name FROM `".$config_databaseTablePrefix."products` WHERE id='".database_safe($_GET["id"])."'";
    database_querySelect($sql,$rows);
    $_GET["q"] = $rows[0]["name"];
  }

To make your product links use the id= version, look for the following code at line 49 in includes/tapestry.php:

    global $config_useRewrite;

...and REPLACE with:

    global $config_useRewrite;
    return $config_baseHREF."products.php?id=".$product["id"];

Cheers,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Thu, 2011-09-01 15:53

Thank you David,

That works for the ID that the script gave. What I am hoping for is to show the product id as the same id as I have for each item in the datafeed. The reason is I only have one store and would like to have the same product ID on the url that is in the catalog.

Current product ID with the ID the script gave:

products.php?id=14881

ID on item on product datafeed is 234564.

I with the product url would show:

products.php?id=234564

Is that possible to have the product detail page url this way or some way to associate the real product id to show the script assigned product id?

Thank you

Submitted by support on Thu, 2011-09-01 16:21

Hi Mike,

That's subtly different but almost the same changes, however first you would need to get your product IDs being imported, with an appropriate field name - bear in mind that "id" is already in use as the ID field of a product record, so something like "pid" standing for "product ID" might be appropriate.

Whatever you choose, first follow the instructions in this thread to add, for example, a "pid" field to your site. Once in place, and you have re-registered your feeds to map a field to the pid field in your database, then the replacement in products.php would be:

  require("includes/common.php");
  if (isset($_GET["pid"]))
  {
    $sql = "SELECT name FROM `".$config_databaseTablePrefix."products` WHERE id='".database_safe($_GET["pid"])."'";
    database_querySelect($sql,$rows);
    $_GET["q"] = $rows[0]["name"];
  }

...and in includes/tapestry.php:

    global $config_useRewrite;
    return $config_baseHREF."products.php?id=".$product["pid"];

Cheers,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Fri, 2011-09-02 02:54

Hello David,

Thank you. It worked for display on front index page and displayed the product ID 100% correct with picture/info and the same if browsed via category or brand.

If I try to click on that product link it just gives me a page with the header and footer only. Is there something I did wrong?

Thank you.

Submitted by support on Fri, 2011-09-02 07:43

Hi Mike,

I just realised that the products.php replacement in my last post still referred to "id" - it should be:

<?php
  
require("includes/common.php");
  if (isset(
$_GET["pid"]))
  {
    
$sql "SELECT name FROM `".$config_databaseTablePrefix."products` WHERE pid='".database_safe($_GET["pid"])."'";
    
database_querySelect($sql,$rows);
    
$_GET["q"] = $rows[0]["name"];
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Fri, 2011-09-02 15:21

Hello David,

The pasted code is the same as one previous. It is still showing blank with header and footer only.

Thank you.

Submitted by support on Fri, 2011-09-02 15:24

Hi Mike,

It's only a single character change -

WHERE id='".database_safe($_GET["pid"])."'

..should have been:

WHERE pid='".database_safe($_GET["pid"])."'

Can you check that's what is in place, and if all looks OK if you could enable database debug mode by changing line 6 of config.advanced.php as follows:

  $config_databaseDebugMode = TRUE;

...and that should reveal more information; if you're not sure from the info displayed where the problem lies let me know what is displayed and I'll take a look...

Cheers,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Fri, 2011-09-02 15:29

Hello David,

Sorry, What I meant to say is that when the PID is in the code it still shows just the header and footer.

Thank you

Submitted by support on Fri, 2011-09-02 15:31

Hi Mike,

Ah OK - if you could enable database debug mode as described above and let me know what is displayed on the page that should point to the problem...

Cheers,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Fri, 2011-09-02 15:39

It is 100% matching and I did change the debug info

it shows this on the screen:

{code saved}

Submitted by support on Fri, 2011-09-02 15:48

Thanks, Mike - that looks like output from an import process (which does generate intentional errors as part of the duplicate prevention) - could you post the same output when viewing a product page with the modified code that is only showing header and footer...

Thanks,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Fri, 2011-09-02 15:59

{link saved}

Submitted by support on Sat, 2011-09-03 08:04

Hi Mike,

I see you've reverted back to normal linking to the product pages but I noticed an error in the replaced to includes/tapestry.php which should actually be:

    global $config_useRewrite;
    return $config_baseHREF."products.php?pid=".$product["pid"];

(it was still using id= that should have been pid= as above)

Cheers,
David.
--
PriceTapestry.com

Submitted by mikecdprice on Sat, 2011-09-03 09:15

Hello David,

Awesome. Thank you. It is now working. You are the best.