Similar to this, but with Magento 2
I want to load a configurable product page, with pre-selected attribute value.
My final purpose is to replace the simple product's url in the catalog with the "parent" configurable's url, with the selected attribute values from the simple product.
I have retrieved the "parent" configurable's url for every product, and i have replaced it with the simple product's url in the catalog. I am missing a way to load the configurable's product page, with different selected values each time.
Best Answer
I adapted my answer from this code snippet here...
This method will take a configured product and a simple child product and return the "hash" URL that preselects the variant. The key method doing the work here is
getConfigurableAttributesAsArray()