Everything works well, but it adds for all by default, but I need it added for a specific customer, regardless of whether it’s active at the moment or not, I have a customer ID, but how can i add product to his card ?

    \Magento\Checkout\Model\Cart $cart,
    \Magento\Catalog\Model\ProductRepository $productRepository,
    \Magento\Quote\Model\QuoteRepository $quoteRepository,

    $this->_cart = $cart;
    $this->_productRepository = $productRepository;
    $this->_quoteRepository = $quoteRepository;


public function autoAddToCart(){


try {
    $data = [
        'qty' => $products_count,
        'product' => $products_id,
        'bundle_option' => $selectionProds
     $cartId = $this->_cart->getQuote()->getId();
     $quote = $this->_quoteRepository->getActive($cartId);
      catch(\Exception $e) {
           echo  $e->getMessage();

you need to assign customer to quote


more info you can found https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/

hope it will help you

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.