Get Orders by Store Id
-
15-04-2021 - |
Pregunta
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
Solución
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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange