You are here:  » Product page


Product page

Submitted by george-p on Mon, 2014-10-13 17:25 in

Hello David,

at product page Product - Main part, i want to have a link of product category, brand, merchant

how i can do this?

also i edited pto_search.php with this code http://www.pricetapestry.org/node/317 to link from search results direct to "buy url" and works fine for search results , but for featured products the link is site/jump.php?id= without id

Submitted by support on Tue, 2014-10-14 08:49

Hello George,

Whilst %DB_merchant% etc. are available to use within the Product / Main template, to accurately generate links to the /merchant/Merchant-Name/ pages etc. a hyphenated version of the values needs to be available, which can be added easily. In pto_product.php look for the following code at line 158:

    $each = trim(preg_replace('/[ ]{2,}/',' ',$each));

...and REPLACE with:

    if (strpos($each,"%DBH_"))
    {
      preg_match_all('/%DBH_(.*)%/U',$each,$matches);
      foreach($matches[1] as $field)
      {
        $each = str_replace("%DBH_".$field."%",pto_common_hyphenate($product->$field),$each);
      }
    }
    $each = trim(preg_replace('/[ ]{2,}/',' ',$each));

Now the links can be constructed within your template as follows:

<p><a href='/merchant/%DBH_merchant%/'>%DB_merchant%</a></p>
<p><a href='/category/%DBH_category%/'>%DB_category%</a></p>
<p><a href='/brand/%DBH_brand%/'>%DB_brand%</a></p>

Regarding the use of buy_url directly, for Featured Products the equivalent mod would be to look for the following code at line 139 of pto_featured.php:

  $each = str_replace("%PRODUCT_URL%",pto_common_productHREF($row),$each);

...and REPLACE with:

  $each = str_replace("%PRODUCT_URL%",pto_common_productHREF($row),$each);
  $each = str_replace("%BUY_URL%",pto_common_buyURL($row),$each);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-14 09:05

thanks works great!

the only problem i notice now is the id is missing from Related products, buy url is site/jump.php?id= without id

Submitted by support on Tue, 2014-10-14 10:24

Hi George,

`id` field isn't included in the Related Products query but can be added if you edit pto_product.php and look for the following code at line 251:

    $sql = "SELECT DISTINCT(name),MATCH name AGAINST ('".$wpdb->escape($pto_product)."') AS relevance FROM `".$pto_config_databaseTablePrefix."products` ".($ignoreFullText?"IGNORE INDEX (name_2)":"USE INDEX (name_2)")." WHERE ".$where." ORDER BY relevance DESC LIMIT 3";

...and REPLACE with:

    $sql = "SELECT id,DISTINCT(name),MATCH name AGAINST ('".$wpdb->escape($pto_product)."') AS relevance FROM `".$pto_config_databaseTablePrefix."products` ".($ignoreFullText?"IGNORE INDEX (name_2)":"USE INDEX (name_2)")." WHERE ".$where." ORDER BY relevance DESC LIMIT 3";

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-14 10:30

that code is at line 223

i replaced with the new code but now related products disappear

Submitted by support on Tue, 2014-10-14 10:45

Hello George,

If you revert that, at line 230 you should have the following;

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

...REPLACE that with:

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

And then look for the following code at line 245:

      $pto_searchResults[$k]->name = $rows3[$product->name]->name;

...and REPLACE with:

      $pto_searchResults[$k]->id = $rows3[$product->name]->id;
      $pto_searchResults[$k]->name = $rows3[$product->name]->name;

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-14 10:48

works fine now, thanks!

Submitted by george-p on Tue, 2014-10-14 14:28

one more question

at product page how i can check if product have brand ?

Submitted by support on Tue, 2014-10-14 15:28

Hi George,

The replacement described above to add %DBH_fieldname% support was actually referring to the Prices / Each template so if that's all working, all you need to do is add support for the %IF_DB_fieldname% ... %ENDIF_DB_fieldname% control placeholders just above that point. To do this, look for the following code at line beginning at line 148 of pto_product.php:

    if (strpos($each,"%DB_"))
    {
      preg_match_all('/%DB_(.*)%/U',$each,$matches);
      foreach($matches[1] as $field)
      {
        $each = str_replace("%DB_".$field."%",$product->$field,$each);
      }
    }

...and REPLACE with:

    if (strpos($each,"%DB_"))
    {
      preg_match_all('/%DB_(.*)%/U',$each,$matches);
      foreach($matches[1] as $field)
      {
        if ($product->$field)
        {
          $each = str_replace("%IF_DB_".$field."%","",$each);
          $each = str_replace("%ENDIF_DB_".$field."%","",$each);
          $each = str_replace("%DB_".$field."%",$product->$field,$each);
        }
        else
        {
          $each = str_replace("%DB_".$field."%","",$each);
          $each = preg_replace('/%IF_DB_'.$field.'%(.*)%ENDIF_DB_'.$field.'%/U','',$each);
        }
      }
    }

You'll then be able to use, for example:

%IF_DB_brand%
<p><a href='/brand/%DBH_brand%/'>%DB_brand%</a></p>
%ENDIF_DB_brand%

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-14 16:12

that works but only for Prices template

how i can make it work for Product Main template ?

Submitted by george-p on Tue, 2014-10-14 16:21

i figured out, at pto_product.php line 507

i replaced this code

    if (strpos($html_product,"%DB_"))
    {
      preg_match_all('/%DB_(.*)%/U',$html_product,$matches);
      foreach($matches[1] as $field)
      {
        $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
      }
    }

with this

if (strpos($html_product,"%DB_"))
    {
      preg_match_all('/%DB_(.*)%/U',$html_product,$matches);
      foreach($matches[1] as $field)
      {
        if ($product->$field)
        {
          $html_product = str_replace("%IF_DB_".$field."%","",$html_product);
          $html_product = str_replace("%ENDIF_DB_".$field."%","",$html_product);
          $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
        }
        else
        {
          $html_product = str_replace("%DB_".$field."%","",$html_product);
          $html_product = preg_replace('/%IF_DB_'.$field.'%(.*)%ENDIF_DB_'.$field.'%/U','',$html_product);
        }
      }
    }