Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace CustomConfirmControllerAdminhtmlOrder;
- use MagentoFrameworkControllerResultFactory;
- use MagentoBackendAppActionContext;
- use MagentoUiComponentMassActionFilter;
- use CustomConfirmModelResourceModelSaleslistCollectionFactory;
- /**
- * Class Payseller.
- */
- class MassConfirm extends MagentoBackendAppAction
- {
- /**
- * @var MagentoSalesApiOrderRepositoryInterface
- */
- protected $_orderRepository;
- /**
- * @var MagentoSalesModelServiceInvoiceService
- */
- protected $_invoiceService;
- /**
- * @var MagentoFrameworkDBTransaction
- */
- protected $_transaction;
- protected $_order;
- public function __construct(
- MagentoFrameworkAppActionContext $context,
- MagentoSalesApiOrderRepositoryInterface $orderRepository,
- MagentoSalesModelServiceInvoiceService $invoiceService,
- MagentoSalesModelOrder $orderInfo,
- MagentoFrameworkDBTransaction $transaction
- ) {
- $this->_orderRepository = $orderRepository;
- $this->_order = $orderInfo;
- $this->_invoiceService = $invoiceService;
- $this->_transaction = $transaction;
- parent::__construct($context);
- }
- /**
- * Execute action.
- *
- * @return MagentoBackendModelViewResultRedirect
- *
- * @throws MagentoFrameworkExceptionLocalizedException|Exception
- */
- public function execute()
- {
- /** @var MagentoBackendModelViewResultRedirect $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 = MagentoFrameworkAppObjectManager::getInstance();
- $order_ = $objectManager->create('MagentoSalesModelOrder')
- ->load($orderId);
- $order_->setState("processing")->setStatus("processing");
- $order_->save();
- }
- $this->messageManager->addSuccess(__('The order has been confirm. '));
- return $resultRedirect->setPath('sales/order/index');
- }
- }
- $order_ = $objectManager->create('MagentoSalesModelOrder')
- ->load($orderId);
- $orderItems = $order_->getAllItems();
- foreach ($orderItems as $item) {
- $proID = $item->getProductId();
- $itemSku = $item->getSku();
- }
- /**
- * @var MagentoCatalogModelProductFactory
- */
- protected $_productFactory;
- public function __construct(
- ...
- MagentoCatalogModelProductFactory $productFactory,
- ...
- ) {
- ...
- $this->_productFactory = $productFactory;
- ...
- }
- $order_ = $_objectManager->create('MagentoSalesModelOrder')
- ->load($orderId);
- $orderItems = $order_->getAllItems();
- foreach ($orderItems as $item)
- {
- $productIds[] = $item->getProductId();
- }
- $collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
- 'name'
- )->addAttributeToSelect(
- 'sku'
- )->addAttributeToSelect(
- 'price'
- )->addAttributeToFilter(
- 'entity_id', array('in' => $productIds)
- );
Advertisement
Add Comment
Please, Sign In to add comment