Jump to content

Change a part of SEF URL, displaying product attribute name


Recommended Posts

Hello,

 

But default the URL of product with selected attribute (say 'color') is generated according to this template:

 

...productname.html#/color-colorname

 

How can I change it to

 

...productname.html#/color-colorID

 

The reason why in need this is because in case my color name uses non-latin characters, there is blank space in URL. So displaying colorID would be a nice and easy workaround about that.

 

Any advices are appreciated

Edited by Amazzing (see edit history)
Link to comment
Share on other sites

  • 2 months later...

I am having the same issue - attribute name and value in Cyrillic are not displayed in the URL. So I get something like:

 

...productname.html#/-

 

instead of

 

...productname.html#/color-colorname 
 
getProductAttribute() function in product.js seems to append the URL with attribute name and value but I am not sure what needs to be changed there or if this is the right place to look at in the first place. So any hint on how to change attribute name to attribute ID or language in which attribute name is displayed would be much appreciated.

 

After some research I found a workaround by switching on 'Use accented characters in URL' setting in Settings > SEO & URLs. Now attribute names and values are displayed in Cyrillic:

 

...productname.html#/цвет-названиецвета

Link to comment
Share on other sites

If anybody needs, here is a workaround for replacing attribute names by ids in URLs:

1) Create an override for product.php: /override/classes/Product.php

2) Override 2 functions: getAttributesParams(..), getAttributesInformationsByProduct(..) by doing 3 sets of replacements: 
--

this    : al.`name` as `attribute`
to this: al.`id_attribute` as `attribute`
--
this    : al.`name`
to this: al.`id_attribute` as `name`
--
this    : agl.`name` as `group`
to this: agl.`id_attribute_group` as `group`
 
You can find a complete override for Product.php inside the spoiler
 

 

  Reveal hidden contents

 

 

  • Like 1
Link to comment
Share on other sites

If you don't want to make all these code modifications, you can choose this way:

 

1) Install block layered navigation

2) After installation you will have a new field on attribute page, "the attribute url name".

After filling in this field, a new URL name will be used not only for blocklayered, but also for all links on the website

 

If you don't need this module, you can hide it by unhooking it, or by using css styles.

Keep in mind, that it loads an additional .css ans .js even if hidden

Edited by Amazzing (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 4 months later...
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...