I have two stores with id 1 and 2. Am trying to add product programmatically using below code $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, //product Id 'qty' => $qty //quantity of product
$this->_cart->addProduct($product_coll, $params); $this->_cart->save();

Checkout flow works well for the store 1. But for store 2, when I add any product to cart using above script. It is adding it to the store 1. I found out this when I looked into the magento quote table . Even though am in store 2, when i add product to cart the quote tables shows it is assigned to store 1. So the order was also place in store 1 instead of store 2.

Can anyone please help me with this ASAP?


Set store id when get product

$product_coll=$this->productRepository->getById($productId, false, $storeId)
| improve this answer | |
  • Actually am using custom REST API to add products to cart and to fetch all the cart items. When I return the store id from that API it return only the default store_id as 1 even if i'm in store 2. Can you please tell me what error i would have done during the custom API creation? – Prabhu M. Mar 22 '19 at 7:36
  • Is custom REST API is always in default scope? How shall I make that to other stores scope? – Prabhu M. Mar 22 '19 at 11:23

I was using my custom REST API to add, fetch and remove the products to and from cart.

The problem was I didn't specify the Scope section in the REST API url as per the Magento Documentation


<HTTP verb> http://<host>/rest/<scope>/<endpoint>

In place of scope we should pass our store code

| improve this answer | |

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.