I am trying to add items to my cart by using the magento 2 Rest API.
Is it possible to get the Customer token by using the customer session? I have looked into this and tried to implement a mix of a few ways to get the results i require.
public function getCustomerToken(){
$result = "null";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
$customerToken = $this->tokenModelFactory->create();
$tokenKey = $customerToken->createCustomerToken($customerSession->getCustomer()->getId())->getToken();
$result = $tokenKey;
}
else{
$result = "null";
}
return $result;
}
This is what i have so far. This is currently throwing an error
Undefined property: Vendor\Module\Block\Index\Index::$tokenModelFactory
To add the items to the cart I need 3 things, the product sku, the quantity and the QuoteID.
to get the quote ID, i must create a cart for the user and to do this i need the customers token.
This is the article I have been learning from: http://devdocs.magento.com/guides/v2.1/get-started/order-tutorial/order-create-quote.html
Is it possible to do what i am trying to?
Thanks