Hi guys!
I have the following problem - using Magento REST API I create a Quote, add to it an item, billing and shipping addresses and shipping method. Then I get the Quote ID and pass it to a custom module.
And here is my problem, I load the Quote based on the provided ID, but when try to get the items the returned value is empty.
$this->quote = $this->quoteFactory->create()->load($this->quoteId);
// some of the data in the quote as json:
{
"entity_id": "68",
"store_id": "1",
"created_at": "2024-06-26 12:17:27",
"updated_at": "2024-06-26 12:17:27",
"converted_at": null,
"is_active": "1",
"is_virtual": "0",
"is_multi_shipping": "0",
"items_count": "1",
"items_qty": "1.0000",
"orig_order_id": "0",
"store_to_base_rate": "0.0000",
"store_to_quote_rate": "0.0000",
"base_currency_code": "USD",
"store_currency_code": "USD",
"quote_currency_code": "USD",
"grand_total": "59.0000",
"base_grand_total": "59.0000",
}
$this->items = $this->quote->getItems();
I am trying this on Magento 2.4.6-p1, but probably I miss something.
Any ideas?
Regards!
Hello @mpstoevgmaea24
Before attempting to retrieve the items, verify that the quote with the given ID exists and is properly loaded.
Check if Quote Exists
$this->quote = $this->quoteFactory->create()->load($this->quoteId); if (!$this->quote->getId()) { throw new \Magento\Framework\Exception\LocalizedException(__('Quote does not exist.')); }
Use getAllItems
The getItems() method may return only certain types of items (e.g., visible items). Use getAllItems() to retrieve all quote items.
$items = $quote->getAllItems(); if (empty($items)) { throw new \Magento\Framework\Exception\LocalizedException(__('No items found in the quote.')); }
Hope it helps !
If you find our reply helpful, please give us kudos.
A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.
WebDesk Solution Support Team
Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Thank You,
WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Location: 150 King St. W. Toronto, ON M5H 1J9