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
8 
12 
17 {
23  protected $_coreRegistry;
24 
28  protected $wishlistProvider;
29 
33  protected $resultPageFactory;
34 
41  public function __construct(
42  Action\Context $context,
44  \Magento\Framework\Registry $coreRegistry,
45  \Magento\Framework\View\Result\PageFactory $resultPageFactory
46  ) {
47  $this->wishlistProvider = $wishlistProvider;
48  $this->_coreRegistry = $coreRegistry;
49  $this->resultPageFactory = $resultPageFactory;
50  parent::__construct($context);
51  }
52 
59  public function execute()
60  {
61  $id = (int)$this->getRequest()->getParam('id');
63  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
64  try {
65  /* @var $item \Magento\Wishlist\Model\Item */
66  $item = $this->_objectManager->create(\Magento\Wishlist\Model\Item::class);
67  $item->loadWithOptions($id);
68  if (!$item->getId()) {
69  throw new \Magento\Framework\Exception\LocalizedException(
70  __("The Wish List item can't load at this time. Please try again later.")
71  );
72  }
73  $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
74  if (!$wishlist) {
75  throw new NotFoundException(__('Page not found.'));
76  }
77 
78  $this->_coreRegistry->register('wishlist_item', $item);
79 
80  $params = new \Magento\Framework\DataObject();
81  $params->setCategoryId(false);
82  $params->setConfigureMode(true);
83  $buyRequest = $item->getBuyRequest();
84  if (!$buyRequest->getQty() && $item->getQty()) {
85  $buyRequest->setQty($item->getQty());
86  }
87  if ($buyRequest->getQty() && !$item->getQty()) {
88  $item->setQty($buyRequest->getQty());
89  $this->_objectManager->get(\Magento\Wishlist\Helper\Data::class)->calculate();
90  }
91  $params->setBuyRequest($buyRequest);
93  $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
94  $this->_objectManager->get(
95  \Magento\Catalog\Helper\Product\View::class
96  )->prepareAndRender(
97  $resultPage,
98  $item->getProductId(),
99  $this,
100  $params
101  );
102 
103  return $resultPage;
104  } catch (\Magento\Framework\Exception\LocalizedException $e) {
105  $this->messageManager->addError($e->getMessage());
106  $resultRedirect->setPath('*');
107  return $resultRedirect;
108  } catch (\Exception $e) {
109  $this->messageManager->addError(__('We can\'t configure the product right now.'));
110  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
111  $resultRedirect->setPath('*');
112  return $resultRedirect;
113  }
114  }
115 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
$wishlist
Definition: wishlist.php:10
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
__construct(Action\Context $context, \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
Definition: Configure.php:41
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18