Ejemplo n.º 1
0
 /**
  * Retrieve samples array
  *
  * @return array
  */
 public function getSampleData()
 {
     $samplesArr = [];
     if ($this->getProduct()->getTypeId() !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         return $samplesArr;
     }
     $samples = $this->getProduct()->getTypeInstance()->getSamples($this->getProduct());
     $fileHelper = $this->_downloadableFile;
     foreach ($samples as $item) {
         $tmpSampleItem = ['sample_id' => $item->getId(), 'title' => $this->escapeHtml($item->getTitle()), 'sample_url' => $item->getSampleUrl(), 'sample_type' => $item->getSampleType(), 'sort_order' => $item->getSortOrder()];
         $sampleFile = $item->getSampleFile();
         if ($sampleFile) {
             $file = $fileHelper->getFilePath($this->_sampleModel->getBasePath(), $sampleFile);
             $fileExist = $fileHelper->ensureFileInFilesystem($file);
             if ($fileExist) {
                 $name = '<a href="' . $this->getUrl('adminhtml/downloadable_product_edit/sample', ['id' => $item->getId(), '_secure' => true]) . '">' . $fileHelper->getFileFromPathFile($sampleFile) . '</a>';
                 $tmpSampleItem['file_save'] = [['file' => $sampleFile, 'name' => $name, 'size' => $fileHelper->getFileSize($file), 'status' => 'old']];
             }
         }
         if ($this->getProduct() && $item->getStoreTitle()) {
             $tmpSampleItem['store_title'] = $item->getStoreTitle();
         }
         $samplesArr[] = new \Magento\Framework\Object($tmpSampleItem);
     }
     return $samplesArr;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve samples array
  *
  * @return array
  */
 public function getSampleData()
 {
     $samplesArr = array();
     if ($this->getProduct()->getTypeId() !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         return $samplesArr;
     }
     $samples = $this->getProduct()->getTypeInstance()->getSamples($this->getProduct());
     $fileHelper = $this->_downloadableFile;
     foreach ($samples as $item) {
         $tmpSampleItem = array('sample_id' => $item->getId(), 'title' => $this->escapeHtml($item->getTitle()), 'sample_url' => $item->getSampleUrl(), 'sample_type' => $item->getSampleType(), 'sort_order' => $item->getSortOrder());
         $sampleFile = $item->getSampleFile();
         if ($sampleFile) {
             $file = $fileHelper->getFilePath($this->_sampleModel->getBasePath(), $sampleFile);
             $fileExist = $fileHelper->ensureFileInFilesystem($file);
             if ($fileExist) {
                 $tmpSampleItem['file_save'] = array(array('file' => $sampleFile, 'name' => $fileHelper->getFileFromPathFile($sampleFile), 'size' => $fileHelper->getFileSize($file), 'status' => 'old'));
             }
         }
         if ($this->getProduct() && $item->getStoreTitle()) {
             $tmpSampleItem['store_title'] = $item->getStoreTitle();
         }
         $samplesArr[] = new \Magento\Framework\Object($tmpSampleItem);
     }
     return $samplesArr;
 }
Ejemplo n.º 3
0
 /**
  * Add Sample File info into $sampleData
  *
  * @param array $sampleData
  * @param SampleInterface $sample
  * @return array
  */
 protected function addSampleFile(array $sampleData, SampleInterface $sample)
 {
     $sampleFile = $sample->getSampleFile();
     if ($sampleFile) {
         $file = $this->downloadableFile->getFilePath($this->sampleModel->getBasePath(), $sampleFile);
         if ($this->downloadableFile->ensureFileInFilesystem($file)) {
             $sampleData['file'][0] = ['file' => $sampleFile, 'name' => $this->downloadableFile->getFileFromPathFile($sampleFile), 'size' => $this->downloadableFile->getFileSize($file), 'status' => 'old', 'url' => $this->urlBuilder->addSessionParam()->getUrl('adminhtml/downloadable_product_edit/sample', ['id' => $sample->getId(), '_secure' => true])];
         }
     }
     return $sampleData;
 }