Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Configure.php
Go to the documentation of this file.
1 <?php
9 
10 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
13 
18 {
22  protected $resultPageFactory;
23 
33  public function __construct(
34  Framework\App\Action\Context $context,
35  Framework\App\Config\ScopeConfigInterface $scopeConfig,
36  \Magento\Checkout\Model\Session $checkoutSession,
38  \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
39  \Magento\Checkout\Model\Cart $cart
40  ) {
41  parent::__construct(
42  $context,
43  $scopeConfig,
44  $checkoutSession,
46  $formKeyValidator,
47  $cart
48  );
49  }
50 
56  public function execute()
57  {
58  // Extract item and product to configure
59  $id = (int)$this->getRequest()->getParam('id');
60  $productId = (int)$this->getRequest()->getParam('product_id');
61  $quoteItem = null;
62  if ($id) {
63  $quoteItem = $this->cart->getQuote()->getItemById($id);
64  }
65 
66  try {
67  if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) {
68  $this->messageManager->addErrorMessage(
69  __("The quote item isn't found. Verify the item and try again.")
70  );
71  return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('checkout/cart');
72  }
73 
74  $params = new \Magento\Framework\DataObject();
75  $params->setCategoryId(false);
76  $params->setConfigureMode(true);
77  $params->setBuyRequest($quoteItem->getBuyRequest());
78 
79  $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
80  $this->_objectManager->get(\Magento\Catalog\Helper\Product\View::class)
81  ->prepareAndRender(
82  $resultPage,
83  $quoteItem->getProduct()->getId(),
84  $this,
85  $params
86  );
87  return $resultPage;
88  } catch (\Exception $e) {
89  $this->messageManager->addErrorMessage(__('We cannot configure the product.'));
90  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
91  return $this->_goBack();
92  }
93  }
94 }
__construct(Framework\App\Action\Context $context, Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Checkout\Model\Cart $cart)
Definition: Configure.php:33
$id
Definition: fieldset.phtml:14
$storeManager
__()
Definition: __.php:13
$quoteItem
Definition: quote.php:38
_goBack($backUrl=null)
Definition: Cart.php:73
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18