I want to configurable product add to cart programmatically in magento 2 to customer cart

2 Answers 2


Find the customer in the backend, click on edit. You should see a tab on the left called shopping cart. You would expect that it should work from there. But it doesn't. Or at least I didn't find a way to make it work.

But here is how I did. Click on the 'Create order' from the customer edit screen. Select a store view to associate the order with. Then add to the order the products you want to put in the cart. After adding them, you will see for each line a column named Action. Select from the dropdown for each product "Move to shopping cart". Then hit "Update items and qty's". That's it.

  • I think he needs to add it programmatically ? Feb 13, 2018 at 11:46

You can use following approach for the solution :

First we need to load a customer for ex :


then we need to create an empty cart and quote as follows :

$cartId = $this->cartManagementInterface->createEmptyCart(); //Create empty cart
$quote = $this->cartRepositoryInterface->get($cartId); // load empty cart quote
$customer= $this->customerRepository->getById($customer->getEntityId());

after above you need to add products to the quote

$options = array(
                90 => 53,
                143 => 170
$params = array(
    'product' => $productId,
    'super_attribute' => $options,
    'qty' => $qty
$_product = $this->productRepository->getById($productId);    

Where productRepository is an instance of \Magento\Catalog\Api\ProductRepositoryInterface

  • thanks for answer but i want to add product to customer cart Feb 13, 2018 at 11:37
  • Please check my update answer for a better idea on how to do it. Feb 13, 2018 at 11:44

Your Answer

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

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