You are here:  » Buy url directly instead of product page


Buy url directly instead of product page

Submitted by magnaromagna on Thu, 2010-06-03 01:01 in

Hello David,
hope you are fine and welcome again after holidays

In my installation I prefer to remove/not use the single product page, so in search results I'd like to change from
<?php print $product["productHREF"]; ?>
to
<?php print tapestry_buyURL($priceProduct); ?>

Is it possible, right? And which modifications to do for this?

Thanks!

Submitted by support on Fri, 2010-06-04 05:23

Hi,

This is a straight forward modification to search.php. I'll post the modifications for both distributions of Price Tapestry as I know you've been a user for a long time...

Latest Distribution (11/09A)

Look for the following code beginning at line 270:

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

...and REPLACE with:

      if ($product["numMerchants"] == 1)
      {
        $searchresults["products"][$k]["productHREF"] = tapestry_buyURL($product);
      }
      elseif ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($product["normalised_name"]).".html";
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode($product["normalised_name"]);
      }

Original Distribution (01/06A)

Look for the following code beginning at line 164:

      if ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
      }

...and REPLACE with:

      if ($product["numMerchants"] == 1)
      {
        $searchresults["products"][$k]["productHREF"] = tapestry_buyURL($product);
      }
      elseif ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
      }

Cheers,
David.

Submitted by magnaromagna on Fri, 2010-06-04 08:56

Thanks David,
but I still see the link to the product instead the link to the buy url, I mean I see

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

but, if possible, I prefer see the buyurl of each merchant.

Submitted by support on Fri, 2010-06-04 10:28

Hi,

The above code will only link to the merchant if there is only 1 merchant - is that the case with the searches you have tried and it is still going to the product page?

Cheers,
David.

Submitted by magnaromagna on Fri, 2010-06-04 12:17

Hi,
no I mean search results where there are many merchants. This is an example page:

{link saved}

Thanks

Submitted by support on Fri, 2010-06-04 12:22

Hi,

That should be how it's working - could you email me your search.php and html/searchresults.php and I'll check it out for you...

Cheers,
David.

Submitted by babyuniverse on Sun, 2010-06-13 00:38

Hi,

Can you please advise how to amend this slightly so it opens the buy url in a new window - target=_blank

Thanks
Richard

Submitted by support on Mon, 2010-06-14 08:23

Hi Richard,

This is best done within the includes/tapestry.php file. In that file, you will find the following code beginning at line 51:

    if ($config_useTracking)
    {
      return $config_baseHREF."jump.php?id=".$product["id"];
    }
    else
    {
      return $product["buy_url"];
    }

REPLACE that with:

    if ($config_useTracking)
    {
      $retval = $config_baseHREF."jump.php?id=".$product["id"];
    }
    else
    {
      $retval = $product["buy_url"];
    }
    return $retval."' target='_BLANK";

It may look like there is a ' missing after _BLANK, but that's OK - it' balanced out by the additional ' added after the Buy URL ($retval in the above code), so the HTML that is ultimately generated will be valid!

Cheers,
David.

Submitted by marco.saiu on Tue, 2018-01-09 17:26

Hello David,

i try to change my search.php when have only 1 product link directly to the product buy link.

      foreach($searchresults["products"] as $k => $product)
      {
        $searchresults["products"][$k] = array_merge($searchresults["products"][$k],$rows3[$product["id"]]);
      // saiu https://www.pricetapestry.com/node/3467
      //$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
      //if ($product["numMerchants"] == 1)
      //{
      // $searchresults["products"][$k]["productHREF"] = tapestry_buyURL($product);
      //}
      //else
      // $searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
      //}

But not work!

Thanks,
Marco Saiu

Submitted by support on Wed, 2018-01-10 11:04

Hello Marco,

The modification looks OK but prior to 16/09A the buy_url field is not present in $product so if you are not using tracking ($config_useTracking = FALSE) the tapestry_buyURL() function would return an empty link. To add the field, look for the following code at line 476:

  $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,name,normalised_name,image_url,description,price,rating,buy_url FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

Cheers,
David.
--
PriceTapestry.com