Exemplo n.º 1
0
 /**
  * Add Link File info into $linkData
  *
  * @param array $linkData
  * @param LinkInterface $link
  * @return array
  */
 protected function addLinkFile(array $linkData, LinkInterface $link)
 {
     $linkFile = $link->getLinkFile();
     if ($linkFile) {
         $file = $this->downloadableFile->getFilePath($this->linkModel->getBasePath(), $linkFile);
         if ($this->downloadableFile->ensureFileInFilesystem($file)) {
             $linkData['file'][0] = ['file' => $linkFile, 'name' => $this->downloadableFile->getFileFromPathFile($linkFile), 'size' => $this->downloadableFile->getFileSize($file), 'status' => 'old', 'url' => $this->urlBuilder->addSessionParam()->getUrl('adminhtml/downloadable_product_edit/link', ['id' => $link->getId(), 'type' => 'link', '_secure' => true])];
         }
     }
     return $linkData;
 }
Exemplo n.º 2
0
 /**
  * Return array of links
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getLinkData()
 {
     $linkArr = [];
     if ($this->getProduct()->getTypeId() !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         return $linkArr;
     }
     $links = $this->getProduct()->getTypeInstance()->getLinks($this->getProduct());
     $priceWebsiteScope = $this->getIsPriceWebsiteScope();
     $fileHelper = $this->_downloadableFile;
     foreach ($links as $item) {
         $tmpLinkItem = ['link_id' => $item->getId(), 'title' => $this->escapeHtml($item->getTitle()), 'price' => $this->getCanReadPrice() ? $this->getPriceValue($item->getPrice()) : '', 'number_of_downloads' => $item->getNumberOfDownloads(), 'is_shareable' => $item->getIsShareable(), 'link_url' => $item->getLinkUrl(), 'link_type' => $item->getLinkType(), 'sample_file' => $item->getSampleFile(), 'sample_url' => $item->getSampleUrl(), 'sample_type' => $item->getSampleType(), 'sort_order' => $item->getSortOrder()];
         $linkFile = $item->getLinkFile();
         if ($linkFile) {
             $file = $fileHelper->getFilePath($this->_link->getBasePath(), $linkFile);
             $fileExist = $fileHelper->ensureFileInFilesystem($file);
             if ($fileExist) {
                 $name = '<a href="' . $this->getUrl('adminhtml/downloadable_product_edit/link', ['id' => $item->getId(), 'type' => 'link', '_secure' => true]) . '">' . $fileHelper->getFileFromPathFile($linkFile) . '</a>';
                 $tmpLinkItem['file_save'] = [['file' => $linkFile, 'name' => $name, 'size' => $fileHelper->getFileSize($file), 'status' => 'old']];
             }
         }
         $sampleFile = $item->getSampleFile();
         if ($sampleFile) {
             $file = $fileHelper->getFilePath($this->_link->getBaseSamplePath(), $sampleFile);
             $fileExist = $fileHelper->ensureFileInFilesystem($file);
             if ($fileExist) {
                 $name = '<a href="' . $this->getUrl('adminhtml/downloadable_product_edit/link', ['id' => $item->getId(), 'type' => 'sample', '_secure' => true]) . '">' . $fileHelper->getFileFromPathFile($sampleFile) . '</a>';
                 $tmpLinkItem['sample_file_save'] = [['file' => $item->getSampleFile(), 'name' => $name, 'size' => $fileHelper->getFileSize($file), 'status' => 'old']];
             }
         }
         if ($item->getNumberOfDownloads() == '0') {
             $tmpLinkItem['is_unlimited'] = ' checked="checked"';
         }
         if ($this->getProduct()->getStoreId() && $item->getStoreTitle()) {
             $tmpLinkItem['store_title'] = $item->getStoreTitle();
         }
         if ($this->getProduct()->getStoreId() && $priceWebsiteScope) {
             $tmpLinkItem['website_price'] = $item->getWebsitePrice();
         }
         $linkArr[] = new \Magento\Framework\DataObject($tmpLinkItem);
     }
     return $linkArr;
 }