You are here:  » Add EAN to url


Add EAN to url

Submitted by falmeida on Tue, 2014-05-06 00:12 in

Hi david

Is it possible to add EAN to url so that it shows something like:

/product/Warlock-Corona-5-Pack-071610211636.html

Thx

Submitted by support on Tue, 2014-05-06 09:13

Hi Falmedia,

Sure - but it would require that the EAN is fixed length and always numeric. If not, this could be corrected with filters so let me know if you're not sure; otherwise if you edit includes/tapestry.php and look for the following code at line 69:

return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"])).".html";

...and REPLACE with:

return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"]))."-".$product["ean"].".html";

Then in .htaccess, look for the following rule at line 7:

RewriteRule ^product/(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]

...and REPLACE with;

RewriteRule ^product/(.*)-[0-9]{12}.html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by falmeida on Tue, 2014-05-06 12:48

hi david

in my case the ean field doesnt have a fixed length and sometimes contains letters because its sometimes the SKU of the retailer.

Submitted by support on Tue, 2014-05-06 13:21

Hi falmedia,

Ah ok - a more flexible rule would then be to use:

RewriteRule ^product/(.*)-([^-]+).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]

Cheers,
David.
--
PriceTapestry.com

Submitted by falmeida on Tue, 2014-05-06 14:25

hi david

i forgot to mention another thing the ean field on some cases is empty, its working if the product has the ean field but not on those that dont have it

also i get no results on merchants/category/brand the url displays correctly but on search box i get "merchant::"

Submitted by support on Tue, 2014-05-06 15:12

Hi falmeida,

Would you prefer a placeholder in place of an empty EAN, e.g. "000", or some other URL structure that can uniquely separate the ean from the product name (otherwise it would be indistinguishable from the last word of the product name.... For the former, e.g. "000" in place of an empty EAN, then in place of the replacement to includes/tapestry.php described above, use:

return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"]))."-".($product["ean"]?$product["ean"]:"000").".html";

Alternatively, for "-ean-" as the separator, use:

return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"])).($product["ean"]?"-ean-".$product["ean"]:"").".html";

And the corresponding .htaccess rules (they must be in this order) :

RewriteRule ^product/(.*)-ean-(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^product/(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]

If the merchant/category/brand URLs are still broken after the above change, if you would like to email me your full .htaccess and also search.php I'll double check any changes for you...

Cheers,
David.
--
PriceTapestry.com