1

I'm trying to filter by order_item to get a list of orders.

Get all orders where an order item has a price greater than 5.

How would this be done? Collections? Joins?

1 Answer 1

0

Use below code to filter order collection based on order item price

    protected $_resourceFactory;

    public function __construct(
        .....
        \Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory $resourceFactory,
        ....
    ) {
        $this->_resourceFactory = $resourceFactory;
    }


    public function yourfunction(){
        $collection = $this->_resourceFactory->create();
        $collection->getSelect()->joinLeft(
                   ['order'=>$collection->getTable('sales_order')],
                   'main_table.order_id = order.entity_id',
                   ['order_status'=>'order.status','base_shipping_amount'=>'order.base_shipping_amount']);
                $collection->addFieldToFilter('price',array('gt' => 5));

        return $collection;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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