I'm building rest api to dd product to cart but it doesn't work and returns quote = null.
here is my code
/**
* @api
* @param int $productId
* @return \Magento\Quote\Model\Quote
*/
public function addItem($productId){
$customer = null;
$isGuest = true;
if($this->isLoggedIn()){
$customerId = $this->userContext->getUserId();
$isGuest = false;
}
$_product = $this->productRepository->getById($productId);
$customerId = $this->userContext->getUserId();
$quote = $this->cartObj->getQuote()->loadByCustomer($customerId);
$quote->setCustomerIsGuest($isGuest)
$this->item->setProduct($_product);
$quote->addItem($this->item);
return $quote;
}
/**
* @return bool
*/
public function isLoggedIn(){
$customerId = $this->userContext->getUserId();
$userType = $this->userContext->getUserType();
if($userType == UserContextInterface::USER_TYPE_CUSTOMER){
return true;
}
return false;
}
regarding your question, I'll get product information and quote id
– Yomna Mansour Dec 11 '18 at 10:35