문제

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"
    }
}
도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top