Can't get order with OrderRepositoryInterface
-
14-04-2021 - |
Question
I have an order in sales_order with entity_id = 1 and increment_id = 000000001.
Both ways of trying to get this order fails with the same response.
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', '000000001')
->create();
$orderList = $this->_orderRepository->getList($searchCriteria);
and
$orderList = $this->_orderRepository->get($orderId);
Any idea why do these throw the following exception?
{
"message": "No such entity with %fieldName = %fieldValue",
"parameters": {
"fieldName": "orderId",
"fieldValue": "1"
}
}
Solution
Turns out I was authenticated with a customer token, and customers don't have access to that resource (editing it at least).
I logged in as admin and am now able to change orders.
OTHER TIPS
Try this code
$order_id = 000000001;
$order_data = $this->orderRepository->get($order_id);
if (!empty($order_data)) {
foreach ($order_data->getAllItems() as $value) {
echo "Product Name: ".$value->getName()." Product ID: ".$value->getProductId();
}
}
I Hope This Helps You.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange