Guest User

Untitled

a guest
Nov 9th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <?php
  2.  
  3. namespace CustomConfirmControllerAdminhtmlOrder;
  4.  
  5. use MagentoFrameworkControllerResultFactory;
  6. use MagentoBackendAppActionContext;
  7. use MagentoUiComponentMassActionFilter;
  8. use CustomConfirmModelResourceModelSaleslistCollectionFactory;
  9.  
  10. /**
  11. * Class Payseller.
  12. */
  13. class MassConfirm extends MagentoBackendAppAction
  14. {
  15. /**
  16. * @var MagentoSalesApiOrderRepositoryInterface
  17. */
  18. protected $_orderRepository;
  19.  
  20. /**
  21. * @var MagentoSalesModelServiceInvoiceService
  22. */
  23. protected $_invoiceService;
  24.  
  25. /**
  26. * @var MagentoFrameworkDBTransaction
  27. */
  28. protected $_transaction;
  29.  
  30. protected $_order;
  31.  
  32. public function __construct(
  33. MagentoFrameworkAppActionContext $context,
  34. MagentoSalesApiOrderRepositoryInterface $orderRepository,
  35. MagentoSalesModelServiceInvoiceService $invoiceService,
  36. MagentoSalesModelOrder $orderInfo,
  37. MagentoFrameworkDBTransaction $transaction
  38. ) {
  39. $this->_orderRepository = $orderRepository;
  40. $this->_order = $orderInfo;
  41. $this->_invoiceService = $invoiceService;
  42. $this->_transaction = $transaction;
  43. parent::__construct($context);
  44. }
  45.  
  46. /**
  47. * Execute action.
  48. *
  49. * @return MagentoBackendModelViewResultRedirect
  50. *
  51. * @throws MagentoFrameworkExceptionLocalizedException|Exception
  52. */
  53. public function execute()
  54. {
  55. /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
  56. $resultRedirect = $this->resultRedirectFactory->create();
  57.  
  58. $wholedata = $this->getRequest()->getPost();
  59.  
  60. foreach ($wholedata['selected'] as $orderId){
  61.  
  62.  
  63. $order = $this->_orderRepository->get($orderId);
  64.  
  65.  
  66. $order2=$this->_order->load($orderId);
  67. $items = $order2->getAllItems();
  68. echo $orderId;
  69. //var_dump($items);
  70. foreach($items as $i){
  71. //var_dump($i);
  72. // code to retrieve product id
  73. }
  74.  
  75.  
  76. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  77. $order_ = $objectManager->create('MagentoSalesModelOrder')
  78. ->load($orderId);
  79.  
  80. $order_->setState("processing")->setStatus("processing");
  81.  
  82. $order_->save();
  83.  
  84. }
  85. $this->messageManager->addSuccess(__('The order has been confirm. '));
  86. return $resultRedirect->setPath('sales/order/index');
  87. }
  88.  
  89. }
  90.  
  91. $order_ = $objectManager->create('MagentoSalesModelOrder')
  92. ->load($orderId);
  93. $orderItems = $order_->getAllItems();
  94. foreach ($orderItems as $item) {
  95. $proID = $item->getProductId();
  96. $itemSku = $item->getSku();
  97. }
  98.  
  99. /**
  100. * @var MagentoCatalogModelProductFactory
  101. */
  102. protected $_productFactory;
  103.  
  104.  
  105.  
  106. public function __construct(
  107. ...
  108. MagentoCatalogModelProductFactory $productFactory,
  109. ...
  110. ) {
  111. ...
  112. $this->_productFactory = $productFactory;
  113. ...
  114. }
  115.  
  116. $order_ = $_objectManager->create('MagentoSalesModelOrder')
  117. ->load($orderId);
  118. $orderItems = $order_->getAllItems();
  119. foreach ($orderItems as $item)
  120. {
  121. $productIds[] = $item->getProductId();
  122.  
  123. }
  124.  
  125. $collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
  126. 'name'
  127. )->addAttributeToSelect(
  128. 'sku'
  129. )->addAttributeToSelect(
  130. 'price'
  131. )->addAttributeToFilter(
  132. 'entity_id', array('in' => $productIds)
  133. );
Advertisement
Add Comment
Please, Sign In to add comment