Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LinkSample.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Downloadable\Helper\Download as DownloadHelper;
11 
13 {
20  public function execute()
21  {
22  $linkId = $this->getRequest()->getParam('link_id', 0);
24  $link = $this->_objectManager->create(\Magento\Downloadable\Model\Link::class)->load($linkId);
25  if ($link->getId()) {
26  $resource = '';
27  $resourceType = '';
28  if ($link->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
29  $resource = $link->getSampleUrl();
30  $resourceType = DownloadHelper::LINK_TYPE_URL;
31  } elseif ($link->getSampleType() == DownloadHelper::LINK_TYPE_FILE) {
32  $resource = $this->_objectManager->get(
33  \Magento\Downloadable\Helper\File::class
34  )->getFilePath(
35  $this->_getLink()->getBaseSamplePath(),
36  $link->getSampleFile()
37  );
38  $resourceType = DownloadHelper::LINK_TYPE_FILE;
39  }
40  try {
41  $this->_processDownload($resource, $resourceType);
42  exit(0);
43  } catch (\Exception $e) {
44  $this->messageManager->addError(
45  __('Sorry, there was an error getting requested content. Please contact the store owner.')
46  );
47  }
48  }
49  return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
50  }
51 }
_redirect($path, $arguments=[])
Definition: Action.php:167
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
exit
Definition: redirect.phtml:12