I want to Filter Orders based on Shipping country I have filtered using other attributes like grand_base_total
and store_id
but struck at shipping country as there is no any attribute for that in sales_order
table
-
Can you add your code for order collection ?So that I can add filter as per your requirement – ParulThakkar Jun 16 '20 at 7:31
-
I want to get only those order which has country_id = 'US – User 69 Jun 16 '20 at 7:40
-
yes but can you add your collection query ? – ParulThakkar Jun 16 '20 at 8:01
-
@ParulThakkar I have done this please check my answer and let me know is it the right way to do this? – User 69 Jun 16 '20 at 11:51
Add a comment
|
I have done this using one of the clues from M1 Question
protected $_orderCollectionFactory;
public function __construct(
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
) {
$this->_orderCollectionFactory = $orderCollectionFactory;
}
public function getOrderCollection()
{
$collection = $this->_orderCollectionFactory->create()
/* Joined with `sales_order_address` to get COuntry Id */
->join(
'sales_order_address',
'sales_order_address.parent_id=main_table.entity_id',
'sales_order_address.country_id ')
/* Added `country_id` Filter */
->addFieldToFilter('country_id',
array('IN' => 'US,UK')
);
return $collection;
}