1

I created one group product. In this, I have added 3 simple products. Now, I want to add 10$ plus in all 3 products when add to the cart. How can I do that?

I used this event checkout_cart_product_add_after

But, It's only updated 1 product. How can I update all product prices?

<?php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;
 
class UpdateAddToCart implements ObserverInterface
{     
    public function execute(Observer $observer)
    {
        /* Code here */
        $item = $observer->getEvent()->getData('quote_item');
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        $price = 100;
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        $item->getProduct()->setIsSuperMode(true);
    }
}

Please help me. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.