How get row from sales_order_item table by item_id in Magento 2?
-
22-02-2021 - |
Question
How get specific row from sales_order_item
by giving item_id
?
Which collection use to filter row?
Can anyone guide me ? has any direct or indirect way to fetch sales_order_item
record from item_id
?
Solution
Try using the repository.
use Magento\Sales\Api\OrderItemRepositoryInterface;
/**
* @var OrderItemRepositoryInterface
*/
private $orderItemRepository;
public function __construct(
OrderItemRepositoryInterface $orderItemRepository
) {
$this->orderItemRepository = $orderItemRepository;
}
Now:
$orderItem = $this->orderItemRepository->get(4);
error_log($orderItem->getName());
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange