How to Get Simple Product from Magento 2 Configurable Product Before Add to Cart

How to Get Simple Product from Magento 2 Configurable Product Before Add to Cart

As a Magento 2 developer, you come across a variety of business demands that need to be fulfilled to optimize the profit or customer service.

As a Magento 2 developer myself, I recently came across a client who sells the configurable products having a different combination of the simple products offering different payment methods. A combination can be bought with recurring payment method and another can be bought as a one time purchase. Now, as the recurring product cannot be combined with the other payment options, it was required to get simple product from Magento 2 configurable product Before add to cart and set up the restriction accordingly.

The below code helps you get the simple products from the configuration product being added to cart to handle the various validations and restrictions based on it.

Method to Get Simple Product from Magento 2 Configurable Product Before Add to Cart”

  1. Create events.xml at app\code\Vendor\Extension\etc\
  2. Create Cartadd.php at app/code/Vendor/Extension/Observer/

That’s it!

Hope the readers find the easy solution right away unlike me to satisfy a client or do their Magento 2 development task quickly with this method!

If you get stuck in between, don’t hesitate to discuss your doubts with me in the Comments section below. I’d be happy to help 😊

Thank you.

5
(based on 9 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply