You can use the join
method on the getSelect
object
$collection = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('*');
$collection->getSelect()->join( array('orders'=> sales_flat_order), 'orders.order_id = main_table.order_id', array('orders.status')); // join on orderid and retrieve the status column
Small side note, it's better to specifically state which fields you need instead of using addAttributeToSelect('*')
Magento 2 get order collection to update customers id using csv.
For example we can take magento 1 we can update using test.php file like that how we can update in magento 2.
I have no idea what you want to tell us here, but I can answer the question:
I am creating new module I am planing to update using controller.But in that how can i get orders collection
Collections are now a mere implementation detail, you work with them using SearchCriteria
and Repository
objects.
First, inject the OrderRepository
and the SearchCriteriaBuilder
into your controller, by adding it to the constructor parameters:
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct(
$context
);
}
Then you can use it like this:
$criteria = $this->searchCriteriaBuilder
// ->addSortOrder(...)
// ->addFilter(...)
// ...
->create();
$orderResult = $this->orderRepository->getList($criteria);
$orders = $orderResult->getItems();
Best Answer
Refer the following function:
If have any issues. Please comment. I will try to resolve.