Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Sample.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  $sampleId = $this->getRequest()->getParam('sample_id', 0);
24  $sample = $this->_objectManager->create(\Magento\Downloadable\Model\Sample::class)->load($sampleId);
25  if ($sample->getId()) {
26  $resource = '';
27  $resourceType = '';
28  if ($sample->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
29  $resource = $sample->getSampleUrl();
30  $resourceType = DownloadHelper::LINK_TYPE_URL;
31  } elseif ($sample->getSampleType() == DownloadHelper::LINK_TYPE_FILE) {
33  $helper = $this->_objectManager->get(\Magento\Downloadable\Helper\File::class);
34  $resource = $helper->getFilePath($sample->getBasePath(), $sample->getSampleFile());
35  $resourceType = DownloadHelper::LINK_TYPE_FILE;
36  }
37  try {
38  $this->_processDownload($resource, $resourceType);
39  exit(0);
40  } catch (\Exception $e) {
41  $this->messageManager->addError(
42  __('Sorry, there was an error getting requested content. Please contact the store owner.')
43  );
44  }
45  }
46  return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
47  }
48 }
_redirect($path, $arguments=[])
Definition: Action.php:167
$helper
Definition: iframe.phtml:13
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
exit
Definition: redirect.phtml:12