/** * Ajax handler to response configuration fieldset of composite product in quote items * * @return \Magento\Framework\View\Result\Layout */ public function execute() { // Prepare data $configureResult = new \Magento\Framework\DataObject(); try { $quoteItemId = (int) $this->getRequest()->getParam('id'); if (!$quoteItemId) { throw new \Magento\Framework\Exception\LocalizedException(__('Quote item id is not received.')); } $quoteItem = $this->_objectManager->create('Magento\\Quote\\Model\\Quote\\Item')->load($quoteItemId); if (!$quoteItem->getId()) { throw new \Magento\Framework\Exception\LocalizedException(__('Quote item is not loaded.')); } $configureResult->setOk(true); $optionCollection = $this->_objectManager->create('Magento\\Quote\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter([$quoteItemId]); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); $configureResult->setCurrentStoreId($quoteItem->getStoreId()); $configureResult->setProductId($quoteItem->getProductId()); $sessionQuote = $this->_objectManager->get('Magento\\Backend\\Model\\Session\\Quote'); $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId()); } catch (\Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } // Render page /** @var \Magento\Catalog\Helper\Product\Composite $helper */ $helper = $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite'); return $helper->renderConfigureResult($configureResult); }
/** * Action to reconfigure cart item * * @return \Magento\Framework\View\Result\Page|\Magento\Framework\Controller\Result\Redirect */ public function execute() { // Extract item and product to configure $id = (int) $this->getRequest()->getParam('id'); $productId = (int) $this->getRequest()->getParam('product_id'); $quoteItem = null; if ($id) { $quoteItem = $this->cart->getQuote()->getItemById($id); } try { if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) { $this->messageManager->addError(__("We can't find the quote item.")); return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('checkout/cart'); } $params = new \Magento\Framework\DataObject(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($resultPage, $quoteItem->getProduct()->getId(), $this, $params); return $resultPage; } catch (\Exception $e) { $this->messageManager->addError(__('We cannot configure the product.')); $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); return $this->_goBack(); } }
/** * Ajax handler to response configuration fieldset of composite product in customer's wishlist. * * @return \Magento\Framework\View\Result\Layout */ public function execute() { $configureResult = new \Magento\Framework\DataObject(); try { $this->_initData(); $configureResult->setProductId($this->_wishlistItem->getProductId()); $configureResult->setBuyRequest($this->_wishlistItem->getBuyRequest()); $configureResult->setCurrentStoreId($this->_wishlistItem->getStoreId()); $configureResult->setCurrentCustomerId($this->_wishlist->getCustomerId()); $configureResult->setOk(true); } catch (Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } return $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult); }
/** * Action to reconfigure wishlist item * * @return \Magento\Framework\Controller\ResultInterface * @throws NotFoundException */ public function execute() { $id = (int) $this->getRequest()->getParam('id'); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); try { /* @var $item \Magento\Wishlist\Model\Item */ $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item'); $item->loadWithOptions($id); if (!$item->getId()) { throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t load the Wish List item right now.')); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $this->_coreRegistry->register('wishlist_item', $item); $params = new \Magento\Framework\DataObject(); $params->setCategoryId(false); $params->setConfigureMode(true); $buyRequest = $item->getBuyRequest(); if (!$buyRequest->getQty() && $item->getQty()) { $buyRequest->setQty($item->getQty()); } if ($buyRequest->getQty() && !$item->getQty()) { $item->setQty($buyRequest->getQty()); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); } $params->setBuyRequest($buyRequest); /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($resultPage, $item->getProductId(), $this, $params); return $resultPage; } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $resultRedirect->setPath('*'); return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t configure the product right now.')); $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $resultRedirect->setPath('*'); return $resultRedirect; } }
/** * Ajax handler to response configuration fieldset of composite product in customer's cart * * @return \Magento\Framework\View\Result\Layout */ public function executeInternal() { $configureResult = new \Magento\Framework\DataObject(); try { $this->_initData(); $quoteItem = $this->_quoteItem; $optionCollection = $this->_objectManager->create('Magento\\Quote\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter($quoteItem); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setOk(true); $configureResult->setProductId($quoteItem->getProductId()); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); $configureResult->setCurrentStoreId($quoteItem->getStoreId()); $configureResult->setCurrentCustomerId($this->_customerId); } catch (\Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } return $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult); }