Question

I want to retrieve orders of a specific store? Is there any way to achieve it. R&D just gave me methods to get store id from order or get store/customer information using order. But i have not found anything which helps me to fetch the orders collection of a specific store

Was it helpful?

Solution

In your constructor, import

\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory

and set

$this->_orderCollectionFactory = $orderCollectionFactory;

and if you already have a way of obtaining the store ID you should be able to call it by passing it in like:

public function getOrderCollectionByStoreId($storeId)
{

    $collection = $this->_orderCollectionFactory->create()
       ->addAttributeToSelect('*')
       ->addFieldToFilter('store_id', $storeId);
     
    return $collection;
     
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top