Remove hash with attributes from URL in PrestaShop 1.7

Hello
my urls to product pages has weird hash after url that has informations about attrbutes, for example:
domain.com/t-shirt/1-1-red-shirt.html#/3-color-red/36-size-m/42-stan-bardzo_dobry_5_6
how i can remove the part #/3-color-red/36-size-m/42-stan-bardzo_dobry_5_6 ?

Expert answer 

This part of url contains information about combination, so when you will access to product page prestashop will automatically select attributes defined in the url. 

If you want to remove it, you will need to modify the prestashop's core or use a module pretty urls (it removes hash with attributes, id product and also id product attrbute from url).


Modification of core
if you want to just remove the hash with attributes info you need to modify the Link.php class that is available in directory classes/Link.php

there is a function that builds urls to product pages:
public function getProductLink(    $product,    $alias = null,    $category = null,    $ean13 = null,    $idLang = null,    $idShop = null,    $ipa = 0,    $force_routes = false,    $relativeProtocol = false,    $addAnchor = false,    $extraParams = array()
){    ...}

inside this function you can find code like (somewhere near line 221)
$anchor = $ipa ? $product->getAnchor((int) $ipa, (bool) $addAnchor) : '';

modify it to:

$anchor = '';




Share on Google Plus

About VEKIA

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

8 comments:

  1. It works great. If I wanted to remove a category or subcategory and product ID from product url, how do I edit it?
    From: https://example/long-sleeve/5268-13168-top-with-long-sleeves.html
    To: https://example/top-with-long-sleeves.html

    ReplyDelete
    Replies
    1. hello
      go to preferences > traffic (prestashop 1.7)
      go to preferences > seo & urls (prestashop 1.6)

      there is a section to manage "schema of urls"
      change the schema for "product pages" from: {category:/}{rewrite}.html to:{rewrite}.html

      Delete
  2. Hi


    You simply replace the line 220 of the file classes / link.php:
    $ anchor = $ ipa? $ product-> getAnchor ((int) $ ipa, (bool) $ addAnchor): '';

    by

    $ anchor = '';

    clear cache

    example url:

    https://www.trophee-sportif.com/trophees-ceramique/3223-209228-trophee-ceramique.html#/654-option_gravure-non

    bECOMES

    https://www.trophee-sportif.com/trophees-ceramique/3223-trophee-ceramique.html

    is that all it takes? and it works?
    thank you

    ReplyDelete
    Replies
    1. I am affraid that with this method the attribute swich on product page will not work correctly, but of course case requires verification

      Delete

  3. You simply replace the line 220 of the file classes / link.php:
    $ anchor = $ ipa? $ product-> getAnchor ((int) $ ipa, (bool) $ addAnchor): '';

    by

    $ anchor = '';

    clear cache

    example url:

    https://www.trophee-sportif.com/trophees-ceramique/3223-209228-trophee-ceramique.html#/654-option_gravure-non

    bECOMES

    https://www.trophee-sportif.com/trophees-ceramique/3223-trophee-ceramique.html

    is that all it takes? and it works?
    thank you

    ReplyDelete
  4. Thank you

    it does not work error 500


    I tried in the override / classes directory to insert this link.php file.

    It works but in the back office it creates a conflict of pdf generation for invoices, delivery notes etc.

    On the customer side, no problem.

    But that's not good too.

    ReplyDelete
  5. do you have a module that works for version 1.7.2.4 ?

    ReplyDelete
    Replies
    1. pretty clean urls is ready to work with all currently available prestashop 1.7.x releases including 1.7.2.4

      Delete