Magento 2 Get Product ID From RMA Item Programatically

July 15th, 2021

Since RMA’s are only a feature of Magento EE, there’s not much information out there about creating custom modules to interact with them.

Below is a small snippet for getting the order item and then the product id using an RMA Item Model.

Using ObjectManager:

$orderitemrepo = $objectManager->get("Magento\Sales\Api\OrderItemRepositoryInterface");
$orderItemId = $rmaitem->getOrderItemId();
$orderItem = $orderitemrepo->get($orderItemId);
$productId = $orderItem->getProductId();

Using DI (Reccommended):

Add \Magento\Sales\Api\OrderItemRepositoryInterface $_orderitemrepo into your constructor.

$orderItemId = $rmaitem->getOrderItemId();
$orderItem = $this->_orderitemrepo->get($orderItemId);
$productId = $orderItem->getProductId();

It’s assumed here that $rmaItem is an RMA Item Model and not an ID.

You can get it by iterating over the collection returned from $rmaItems = $rma->getItems(); where, again, $rma is an RMA model and not an ID.


Leave a Reply

Your email address will not be published. Required fields are marked *