Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateQty.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 
12 {
18  const ADMIN_RESOURCE = 'Magento_Sales::sales_creditmemo';
19 
23  protected $creditmemoLoader;
24 
28  protected $pagePageFactory;
29 
33  protected $resultJsonFactory;
34 
38  protected $resultRawFactory;
39 
47  public function __construct(
48  Action\Context $context,
49  \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader,
50  \Magento\Framework\View\Result\PageFactory $resultPageFactory,
51  \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
52  \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
53  ) {
54  $this->creditmemoLoader = $creditmemoLoader;
55  $this->resultPageFactory = $resultPageFactory;
56  $this->resultJsonFactory = $resultJsonFactory;
57  $this->resultRawFactory = $resultRawFactory;
58  parent::__construct($context);
59  }
60 
66  public function execute()
67  {
68  try {
69  $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
70  $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
71  $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
72  $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
73  $this->creditmemoLoader->load();
74  $resultPage = $this->resultPageFactory->create();
75  $response = $resultPage->getLayout()->getBlock('order_items')->toHtml();
76  } catch (\Magento\Framework\Exception\LocalizedException $e) {
77  $response = ['error' => true, 'message' => $e->getMessage()];
78  } catch (\Exception $e) {
79  $response = ['error' => true, 'message' => __('We can\'t update the item\'s quantity right now.')];
80  }
81  if (is_array($response)) {
82  $resultJson = $this->resultJsonFactory->create();
83  $resultJson->setData($response);
84  return $resultJson;
85  } else {
86  $resultRaw = $this->resultRawFactory->create();
87  $resultRaw->setContents($response);
88  return $resultRaw;
89  }
90  }
91 }
$response
Definition: 404.php:11
__()
Definition: __.php:13
__construct(Action\Context $context, \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory)
Definition: UpdateQty.php:47