I am working with the Magento configurable product, in my requirement I've config & simple product, while customer added a 5 quantity of the config product with one custom option, then the 5 quantity need to add 5 different line of item in cart page.

enter image description here

For Ex, if i selected the every 1 week custom option, and select 4 quantity, then it has to be 4 different line of item.

I already know it's only possible with another custom option only, So i tried to add a each quantity as one item to cart with two custom option

  1. The selected custom option
  2. dynamically tried to add a custom option to the product.

But it's not working, do you have any idea to implement this logic it will much helpful for me.

Thanks in advance for your better support

1 Answer 1


I've tried the following scenario, it's working when i add a custom option as manually

Ex : I've a color attribute with the following values(red,blue), In the below code, in $additinalOption array I've added the red in value, then hid the addtocart, then i changed the values to blue, then hid the addtocart, now I've two line of item in my cart page. enter image description here

    $params = $this->getRequest()->getParams();
    $requestedQty = $params['qty'];
    for ($i=1; $i<=$requestedQty; $i++) { 
    $color = [1=>"red", 2=>"yellow", 3=>"blue", 4=>"black"];
                    //$productId = 5;
                    $additionalOptions['color'] = [
                        'label' => 'Color',
                        'value' => $color[$i]
                    $logger->info("Additional Option Data : ========= " . json_encode($additionalOptions));
                    //$product = $this->productRepository->getById($productId);
                    $product->addCustomOption('color', serialize($additionalOptions));
                    $logger->info("Product Custom options : " . json_encode($product->getCustomOptions('color')));
$this->cart->addProduct($product, $params);

for the same code I changed the additionalOption array value in dynamic way ($color[$i]), the qty only increased.

enter image description here

I am expecting a solution to achieve the manual process in dynamic way. Thanks in advance for your better support.

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.