Skip to content

magento 2.4 add to cart multiple simple products with options

I’m trying to add to cart multiple simple products with different custom options at once. So far, I’ve overridden the checkout/add controller and replaced the line

$this->cart->addProduct($product, $params) // around line 125

with following code:


foreach($multipleItems as $productId = $productData) {
    $product = $this->_initProduct($productId);
    $newParams = $params;
    $newParams['product'] = $productId;
    $newParams['qty'] = $productData['qty'];
    $newParams['options'] = $productData['options'];
    $this->cart->addProduct($product, $newParams);
}

With this code I am able to add the first product correctly with its options but the subsequent ones are added without the custom options.

Does anyone know how can I add all my simple products with their different custom options?