1

How to load configurable product with preselected options of any one of simple product?

For example

I have a configurable product http://host/product/1.

It have 2 associated simple products http://host/product/2 and http://host/product/3.

Whenever configurable product page load, I need to display the preselected options of http://host/product/2.

Can anyone share hints to achieve this?

3 Answers 3

1

Following this article by Daan van den Bergh you can do exactly what you need: https://daan.dev/magento/2/redirect-simple-products-configurable-parent-attributes-pre-selected/

0

Hi I'm in same situation. Below is my implementation (not completed yet but I believe to be "clean" solution):

  • override Magento_ConfigurableProduct::product/view/type/options/configurable.phtml in custom module, adding code to check how many child products the configurable product has (if only one, then don't render the options).

This also requires adding a Plugin class for the swatches module due to stupid magento2 hard coded template paths, refer to https://github.com/magento/magento2/issues/4400

  • create custom js component that takes the child product id available in the phtml template. This component will set the value of the "selected_configurable_option" hidden input field to that product id.

This should be enough to allow customer to set quantity and add to the cart.

I usually do only backend side so am looking up minimal way to create this js component (or do it inline if possible).

FYI this is not a fully tested or complete solution as I haven't check what these overrides do when customer is editing their cart or browsing category products.

I'm still working on it as of this post.

0

This free module does the job! :) https://github.com/magepow/magento-2-configurable-preselect
it also has an option to view preselected options in listing page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.