You are here:  » Generating the product URL's


Generating the product URL's

Submitted by jamie on Tue, 2016-08-16 20:59 in

Hi David,

I need to create a list of all my product URL's (I am using the htaccess rewriting of the URL's).

I was just wondering if you have the set of rules you use to generate those links please? Ive noticed there are some characters such as full stops that are still in the end URL that I wouldnt have expected to be in the there.

Thanks for your help
Jamie

Submitted by support on Wed, 2016-08-17 08:32

Hello Jamie and welcome to the forum!

Product links are generated by the tapestry_productHREF() function which uses the /product/ slug followed by the normalised version of the product name (held in `normalised_name` on the products table which is intended to be a clean / URL safe version of the product name, e.g. removing characters such as &, " etc.

Based on sitemap.php which generates an XML sitemap of all product pages on your site, the following code will just print out a list of all product URLs, in text/plain:

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
header("Content-Type: text/plain");
  
$link mysqli_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword,$config_databaseName);
  
mysqli_set_charset($link,"utf8");
  
$sql "SELECT normalised_name FROM `".$config_databaseTablePrefix."products`";
  
mysqli_real_query($link,$sql);
  
$result mysqli_use_result($link);
  
$sitemapBaseHREF "http://".$_SERVER["HTTP_HOST"];
  while(
$row mysqli_fetch_assoc($result))
  {
    
$sitemapHREF tapestry_productHREF($row);
    print 
$sitemapBaseHREF.$sitemapHREF."\n";
  }
?>

Save as something like urls.php and run from the top level folder of your Price Tapestry installation.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Wed, 2016-08-17 09:39

Hi David,

Ah thats great, thank you!

I'm looking in the products table in phpmyadmin on my server, and it actually has all the data Im after.

Please could I ask you how to change the code above to give me:

1) normalised_name
2) original_name
3) buy_url
4) category
5) image_url

And then it saves it into a CSV file (instead of displaying in the browser).

Once again, thanks for your time on this,
Jamie

Submitted by support on Thu, 2016-08-18 09:19

Hi Jamie,

Use a SELECT * (all fields), and then you can output as required, for example (to save as output.csv in the feeds/ folder)

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
header("Content-Type: text/plain");
  
$fp fopen("feeds/output.csv","w");
  
$link mysqli_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword,$config_databaseName);
  
mysqli_set_charset($link,"utf8");
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."products`";
  
mysqli_real_query($link,$sql);
  
$result mysqli_use_result($link);
  
$sitemapBaseHREF "http://".$_SERVER["HTTP_HOST"];
  while(
$row mysqli_fetch_assoc($result))
  {
    
$fields = array();
    
$fields[] = $row["normalised_name"];
    
$fields[] = $row["original_name"];
    
$fields[] = $row["buy_url"];
    
$fields[] = $row["category"];
    
$fields[] = $row["image_url"];
    
fwrite($fp,implode(",",$fields)."\n");
  }
  
fclose($fp);
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Thu, 2016-08-18 16:02

Thank you so much for this David, massively helpful. The issue with my webhost is that I cannot use external software to remote access my mysql databases, so being able to download directly from the PriceTapestry site is a huge time saver.

Once again thanks very much,
Jamie

Submitted by sirmanu on Tue, 2016-09-20 15:43

Sorry for using this topic but it is the one which mention tapestry_productHREF!

As database is utf8_general_ci, can I remove accents and capital letters from the URL modifying productHREF function? (with config_useRewrite=true I think is the best combination for SEO).

It is not necessary that you provide code, as I am already using remove_accents from wordpress. As I say, is working now, but I want to know if there some kind of future problem. Thanks!

Submitted by support on Wed, 2016-09-21 08:34

Hi,

tapestry_productHREF() generates the URL from the `normalised_name` field which itself is generated by the tapestry_normalise() function, so it would probably be best to remove accents as part of the tapestry_normalise() function. To do this, first ensure that a .utf8 locale is configured by adding the following line to the end of config.php:

  setlocale(LC_ALL,"en_US.utf8");

And then edit includes/tapestry.php and look for the following code at line 22:

    $text = str_replace("-"," ",$text);

...and REPLACE with:

    $text = str_replace("-"," ",$text);
    $text = iconv("UTF-8","ASCII//TRANSLIT",$text);

(and then run a full import to set the new `normalised_name` values)

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Wed, 2016-09-21 10:32

Okey. Elegant solution! With that in mind, titles, descriptions and more, it keep showing with accents and "strange" symbols, right?

Submitted by support on Wed, 2016-09-21 10:44

Hi,

If you are seeing ? or strange characters in product names / descriptions that would normally indicate that the feed data is not in the same character encoding as the site. With utf-8 being the most commonly used character encoding that is used as the default "out of the box", so for a feed that is not displaying correctly, use a UTF8 Encode filter against the product name / description fields as required (and re-import after making changes to the filter configuration...)

Cheers,
David.
--
PriceTapestry.com