This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

snakemaster
snakemaster

Hi all,

I have been using the OC Mall plugin for some time and one thing I don't like is the variant hashId in the URL.

For those who don't know Mall. It's a webshop plugin where you have single products (like Bike) and products consisting of multiple variants (like Jersey Red, Jersey Blue, etc) The url for products are like /product/bike/ and for variant /product/jersey/79pR5aln

I do understand why the choice was made to use the hashed id of the Variant (79pR5aln), I just don't like it because it's not SEO and user friendly. So I thought of some solutions to change it.

  1. Change the Variant HashID to a slug. This means changing the code and returning a different value. It would work but has some downsides

    • It's easy and simple
    • I think it's bad practice to alter other plugin code, updates break it.
    • I think it's bad practice to abuse a method and make it return an unexpected result (getHashIdAttribute should not return a slug)
    • The Variant slug would have to be project-wide unique to resolve it without the Product url.
  2. Make a canonical URL like /product/jersey-red that uses Middleware to fake the request route /product/jersey/79pR5aln without redirecting in the browser.

    • No tampering plugin code
    • This should work instantly for reading URL's
    • I'd still have to figure out how to create the URL's without tampering code or recreating all components that link to variants.

I think the second would be my best choice, I have some questions regarding the implementation.

  1. Is it possible to override/extend the Twig pageFilter to return the canonical URL when the variantID URL is build?
  2. If not, is it possible to override/extend the CMS controller and change the method pageUrl() to return the canonical url?
  3. Is there another solution that I haven't thought of?
daftspunky
daftspunky

I'd extend the Mall component class in my own plugin and override the function that looks up the product to use a slug instead of a HashID. However, it might be best to work with the plugin author to discover the best solution

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.