I currently have a Craft Commerce site where the product url is setup like this:

{productCategory.level(1).first().slug}/{productCategory.level(2).first().slug}/{productCategory.level(3).first().slug}/{slug}

So this gives an example url of category1/category2/category3/my-product

This all works fine. What I'd like to do is add an optional segment onto the end of this url, so for example:

category1/category2/category3/my-product/optional-thing.

I'd like the current urls to continue working, but if you add the extra optional-thing segment to the url you also get the same product.

Ultimately this is so that I can preselect a variant in a carousel on the product detail page.

I've tried doing this with routes, but so far I've been unsuccessful. Is this the right approach or is there a better, more Commerce specific way?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.