Skip to main content
Tweeted twitter.com/StackMagento/status/796426159630221312
improved title
Link
Qaisar Satti
  • 32.5k
  • 18
  • 87
  • 137

How do I get the Get product information in admin controller using the order id?

How do iI get the product information in admin controller using the order id?

Hi iI want to get the product information like product id, sku in theproduct id, sku at admin panel when(backend), When action is being performed on any order. How can iI achieve this.

How do i get the product information in admin controller using the order id?

Hi i want to get the product information like product id, sku in the admin panel when action is performed on any order. How can i achieve this

How do I get the product information in admin controller using the order id?

I want to get the product information like product id, sku at admin(backend), When action is being performed on any order. How can I achieve this.

Source Link
Nitin Pawar
  • 1.6k
  • 9
  • 24
  • 49

How do i get the product information in admin controller using the order id?

Hi i want to get the product information like product id, sku in the admin panel when action is performed on any order. How can i achieve this

This is code:

<?php
    
namespace Custom\Confirm\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Custom\Confirm\Model\ResourceModel\Saleslist\CollectionFactory;
    
/**
 * Class Payseller.
 */
class MassConfirm extends \Magento\Backend\App\Action
{
     /**
     * @var \Magento\Sales\Api\OrderRepositoryInterface
     */
    protected $_orderRepository;
 
    /**
     * @var \Magento\Sales\Model\Service\InvoiceService
     */
    protected $_invoiceService;
 
    /**
     * @var \Magento\Framework\DB\Transaction
     */
    protected $_transaction;
    
    protected $_order;
 
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Sales\Model\Service\InvoiceService $invoiceService,
        \Magento\Sales\Model\Order $orderInfo,
        \Magento\Framework\DB\Transaction $transaction
    ) {
        $this->_orderRepository = $orderRepository;
        $this->_order = $orderInfo;
        $this->_invoiceService = $invoiceService;
        $this->_transaction = $transaction;
        parent::__construct($context);
    }
   
    /**
     * Execute action.
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     *
     * @throws \Magento\Framework\Exception\LocalizedException|\Exception
     */
    public function execute()
    {
            /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        
        $wholedata = $this->getRequest()->getPost();
        
        foreach ($wholedata['selected'] as $orderId){
        
        
         $order = $this->_orderRepository->get($orderId);
            
            
                $order2=$this->_order->load($orderId);
                $items = $order2->getAllItems();
                echo $orderId;
                //var_dump($items);
                foreach($items as $i){
                 //var_dump($i);
                 // code to retrieve product id 
                }
            
                
                  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $order_ = $objectManager->create('\Magento\Sales\Model\Order')
                                           ->load($orderId); 
                 
                $order_->setState("processing")->setStatus("processing");
                 
                $order_->save();  
            
        }   
        $this->messageManager->addSuccess(__('The order has been confirm. '));
        return $resultRedirect->setPath('sales/order/index');
    }

}

Thanks in advance.