ConfigureQuoteItems.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Controller\Adminhtml\Order\Create;
  7. class ConfigureQuoteItems extends \Magento\Sales\Controller\Adminhtml\Order\Create
  8. {
  9. /**
  10. * Ajax handler to response configuration fieldset of composite product in quote items
  11. *
  12. * @return \Magento\Framework\View\Result\Layout
  13. */
  14. public function execute()
  15. {
  16. // Prepare data
  17. $configureResult = new \Magento\Framework\DataObject();
  18. try {
  19. $quoteItemId = (int)$this->getRequest()->getParam('id');
  20. if (!$quoteItemId) {
  21. throw new \Magento\Framework\Exception\LocalizedException(
  22. __('The quote item ID needs to be received. Set the ID and try again.')
  23. );
  24. }
  25. $quoteItem = $this->_objectManager->create(\Magento\Quote\Model\Quote\Item::class)->load($quoteItemId);
  26. if (!$quoteItem->getId()) {
  27. throw new \Magento\Framework\Exception\LocalizedException(
  28. __('The quote item needs to be loaded. Load the item and try again.')
  29. );
  30. }
  31. $configureResult->setOk(true);
  32. $optionCollection = $this->_objectManager->create(\Magento\Quote\Model\Quote\Item\Option::class)
  33. ->getCollection()
  34. ->addItemFilter([$quoteItemId]);
  35. $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem));
  36. $configureResult->setBuyRequest($quoteItem->getBuyRequest());
  37. $configureResult->setCurrentStoreId($quoteItem->getStoreId());
  38. $configureResult->setProductId($quoteItem->getProductId());
  39. $sessionQuote = $this->_objectManager->get(\Magento\Backend\Model\Session\Quote::class);
  40. $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId());
  41. } catch (\Exception $e) {
  42. $configureResult->setError(true);
  43. $configureResult->setMessage($e->getMessage());
  44. }
  45. // Render page
  46. /** @var \Magento\Catalog\Helper\Product\Composite $helper */
  47. $helper = $this->_objectManager->get(\Magento\Catalog\Helper\Product\Composite::class);
  48. return $helper->renderConfigureResult($configureResult);
  49. }
  50. }