Anu Mary Anu Mary - 2 years ago 140
PHP Question

How to get order details in product detail page in magento 2

How show the past order details of a particular product in product details page.
The version that i am using is magento 2.0.3.

Answer Source

Try this:

$tableOrder = $this->_resource->getTableName('sales_order'); 
$object_manager = \Magento\Framework\App\ObjectManager::getInstance();

$collection=$object_manager->get("Magento\Sales\Model\Order\Item")->getCollection()->addFieldToFilter("product_id",Your Product Id);
$collection->getSelect()->join( array('order'=> $tableOrder), 'order.entity_id = main_table.order_id', array("*"));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download