0

I want to get RMA returns details by current registry or by order id.

How can i load RMA by registry or order id?

Any help or hint will be appreciated.

3

This is a demo class code about rma, I hope to help you.

<?php

namespace YourVendorName\YourModuleName\Demo;

class RmaDemo
{
    protected $orderFactory;

    protected $rmaFactory;

    protected $rmaItemFactory;

    public function __construct(
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Rma\Model\ResourceModel\Rma\CollectionFactory $rmaFactory,
        \Magento\Rma\Model\ResourceModel\Item\CollectionFactory $rmaItemFactory
    )
    {
        $this->orderFactory = $orderFactory;
        $this->rmaFactory = $rmaFactory;
        $this->rmaItemFactory = $rmaItemFactory;
    }

    // eg: $orderId = xxxxx
    public function execute($orderId)
    {
        // 1.get rma collection by orderId
        // return array and rma_entity_id $RmaData['entity_id']
        $RmaData = $this->getRmaCollection($orderId);

        // 2.get rma item collection by orderId
        $order = $this->orderFactory->create()->load($orderId);
        foreach ($order->getItems() as $item) {
            $RmaItemData = $this->getRmaItemCollection($item->getItemId());
        }
    }

    /**
     * @param $orderId
     * @return array
     */
    public function getRmaCollection($orderId)
    {
        return $this->rmaFactory->create()->addFieldToSelect(
            '*'
        )->addFieldToFilter(
            'order_id',
            $orderId
        )->getFirstItem();
    }

    /**
     * @param $orderItemId
     * @return array
     */
    public function getRmaItemCollection($orderItemId)
    {
        return $this->rmaItemFactory->create()->addFieldToSelect(
            '*'
        )->addFieldToFilter(
            'order_item_id',
            $orderItemId
        )->getFirstItem();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.