_fileResponseFactory = $fileResponseFactory; $this->json = $json ?: ObjectManager::getInstance()->get(Json::class); parent::__construct($context); } /** * Custom options download action * * @return \Magento\Framework\Controller\Result\Forward * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExitExpression) */ public function execute() { $option = $this->_objectManager->create( \Magento\Wishlist\Model\Item\Option::class )->load( $this->getRequest()->getParam('id') ); /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); if (!$option->getId()) { $resultForward->forward('noroute'); return $resultForward; } $optionId = null; if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) { $optionId = str_replace( \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode() ); if ((int)$optionId != $optionId) { $resultForward->forward('noroute'); return $resultForward; } } $productOption = $this->_objectManager->create(\Magento\Catalog\Model\Product\Option::class)->load($optionId); if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file' ) { $resultForward->forward('noroute'); return $resultForward; } try { $info = $this->json->unserialize($option->getValue()); $secretKey = $this->getRequest()->getParam('key'); if ($secretKey == $info['secret_key']) { $this->_fileResponseFactory->create( $info['title'], ['value' => $info['quote_path'], 'type' => 'filename'], DirectoryList::ROOT, $info['type'] ); } } catch (\Exception $e) { $resultForward->forward('noroute'); return $resultForward; } } }