Esempio n. 1
0
 /**
  * Action to reconfigure cart item
  *
  * @return void
  */
 public function execute()
 {
     // Extract item and product to configure
     $id = (int) $this->getRequest()->getParam('id');
     $quoteItem = null;
     if ($id) {
         $quoteItem = $this->cart->getQuote()->getItemById($id);
     }
     if (!$quoteItem) {
         $this->messageManager->addError(__("We can't find the quote item."));
         $this->_redirect('checkout/cart');
         return;
     }
     try {
         $params = new \Magento\Framework\Object();
         $params->setCategoryId(false);
         $params->setConfigureMode(true);
         $params->setBuyRequest($quoteItem->getBuyRequest());
         $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params);
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We cannot configure the product.'));
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $this->_goBack();
         return;
     }
 }
Esempio n. 2
0
 /**
  * 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\Object();
         $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();
     }
 }
Esempio n. 3
0
 /**
  * Initialize requested product object
  *
  * @return ModelProduct
  */
 protected function _initProduct()
 {
     $categoryId = (int) $this->getRequest()->getParam('category', false);
     $productId = (int) $this->getRequest()->getParam('id');
     $params = new \Magento\Framework\Object();
     $params->setCategoryId($categoryId);
     return $this->_objectManager->get('Magento\\Catalog\\Helper\\Product')->initProduct($productId, $this, $params);
 }
Esempio n. 4
0
 /**
  * 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.'));
         }
         $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
         if (!$wishlist) {
             throw new NotFoundException(__('Page not found.'));
         }
         $this->_coreRegistry->register('wishlist_item', $item);
         $params = new \Magento\Framework\Object();
         $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.'));
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $resultRedirect->setPath('*');
         return $resultRedirect;
     }
 }
Esempio n. 5
0
 /**
  * Action to reconfigure cart item
  *
  * @return \Magento\Framework\View\Result\Page|\Magento\Framework\Controller\Result\Redirect
  * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  */
 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);
     }
     if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) {
         $this->messageManager->addError(__("We can't find the quote item."));
         return $this->resultRedirectFactory->create()->setPath('checkout/cart');
     }
     $params = new \Magento\Framework\Object();
     $params->setCategoryId(false);
     $params->setConfigureMode(true);
     $params->setBuyRequest($quoteItem->getBuyRequest());
     $resultPage = $this->resultPageFactory->create();
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($resultPage, $quoteItem->getProduct()->getId(), $this, $params);
     return $resultPage;
 }
Esempio n. 6
0
 /**
  * Action to reconfigure wishlist item
  *
  * @return void
  * @throws NotFoundException
  */
 public function execute()
 {
     $id = (int) $this->getRequest()->getParam('id');
     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\Model\Exception(__('We can\'t load the wish list item.'));
         }
         $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
         if (!$wishlist) {
             throw new NotFoundException();
         }
         $this->_coreRegistry->register('wishlist_item', $item);
         $params = new \Magento\Framework\Object();
         $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);
         $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($item->getProductId(), $this, $params);
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->messageManager->addError($e->getMessage());
         $this->_redirect('*');
         return;
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We can\'t configure the product.'));
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $this->_redirect('*');
         return;
     }
 }
Esempio n. 7
0
 /**
  * Product view action
  *
  * @return void
  */
 public function execute()
 {
     // Get initial data from request
     $categoryId = (int) $this->getRequest()->getParam('category', false);
     $productId = (int) $this->getRequest()->getParam('id');
     $specifyOptions = $this->getRequest()->getParam('options');
     if ($this->getRequest()->isPost() && $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
         $product = $this->_initProduct();
         if (!$product) {
             $this->noProductRedirect();
         }
         if ($specifyOptions) {
             $notice = $product->getTypeInstance()->getSpecifyOptionMessage();
             $this->messageManager->addNotice($notice);
         }
         $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
         return;
     }
     // Prepare helper and params
     /** @var \Magento\Catalog\Helper\Product\View $viewHelper */
     $viewHelper = $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View');
     $params = new \Magento\Framework\Object();
     $params->setCategoryId($categoryId);
     $params->setSpecifyOptions($specifyOptions);
     // Render page
     try {
         $viewHelper->prepareAndRender($productId, $this, $params);
     } catch (\Exception $e) {
         if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) {
             $this->noProductRedirect();
         } else {
             $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
             $this->_forward('noroute');
         }
     }
 }
Esempio n. 8
0
 /**
  * Product view action
  *
  * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     // Get initial data from request
     $categoryId = (int) $this->getRequest()->getParam('category', false);
     $productId = (int) $this->getRequest()->getParam('id');
     $specifyOptions = $this->getRequest()->getParam('options');
     if ($this->getRequest()->isPost() && $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
         $product = $this->_initProduct();
         if (!$product) {
             return $this->noProductRedirect();
         }
         if ($specifyOptions) {
             $notice = $product->getTypeInstance()->getSpecifyOptionMessage();
             $this->messageManager->addNotice($notice);
         }
         if ($this->getRequest()->isAjax()) {
             $this->getResponse()->representJson($this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data')->jsonEncode(['backUrl' => $this->_redirect->getRedirectUrl()]));
             return;
         }
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setRefererOrBaseUrl();
         return $resultRedirect;
     }
     // Prepare helper and params
     $params = new \Magento\Framework\Object();
     $params->setCategoryId($categoryId);
     $params->setSpecifyOptions($specifyOptions);
     // Render page
     try {
         $page = $this->resultPageFactory->create(false, ['isIsolated' => true]);
         $this->viewHelper->prepareAndRender($page, $productId, $this, $params);
         return $page;
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return $this->noProductRedirect();
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }