1

I have a Custom attribute name ( product string ) on Product in which i have save a string i want to get those orders which will have that product string of same value.

I will get the product by :

$collection = $this->_orderCollectionFactory->create()
            ->addAttributeToSelect('*')
            ->setOrder('created_at','desc');
return $collection;
1

Get the collection in your block file

public function getOrderCollection()
    {
        $collection = $this->_orderCollectionFactory->create();           
        $collection->addAttributeToSelect('*'); 
        $collection->addAttributeToFilter('your_attribute_code_here', 1);
        $collection->setOrder('created_at','desc');
        return $collection; 
    }

now call this collection in your phtml file

2
  • I am getting error Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'custom_attribute' in 'where clause', query was: SELECT main_table.* FROM sales_order AS main_table WHERE (custom_attribute = 'test_string') ORDER BY created_at DESC @Chikku
    – Prits
    Aug 10 '20 at 17:08
  • Actually i want to use order and product collection togather.
    – Prits
    Aug 10 '20 at 17:08

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.