Beispiel #1
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param LinkInterface $link
  * @param bool $isGlobalScopeContent
  * @return int
  */
 protected function saveLink(\Magento\Catalog\Api\Data\ProductInterface $product, LinkInterface $link, $isGlobalScopeContent)
 {
     $linkData = ['link_id' => $link->getid() === null ? 0 : $link->getid(), 'is_delete' => 0, 'type' => $link->getLinkType(), 'sort_order' => $link->getSortOrder(), 'title' => $link->getTitle(), 'price' => $link->getPrice(), 'number_of_downloads' => $link->getNumberOfDownloads(), 'is_shareable' => $link->getIsShareable()];
     if ($link->getLinkType() == 'file' && $link->getLinkFile() === null) {
         $linkData['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($link->getLinkFileContent(), 'link_file')]);
     } elseif ($link->getLinkType() === 'url') {
         $linkData['link_url'] = $link->getLinkUrl();
     } else {
         //existing link file
         $linkData['file'] = $this->jsonEncoder->encode([['file' => $link->getLinkFile(), 'status' => 'old']]);
     }
     if ($link->getSampleType() == 'file' && $link->getSampleFile() === null) {
         $linkData['sample']['type'] = 'file';
         $linkData['sample']['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($link->getSampleFileContent(), 'link_sample_file')]);
     } elseif ($link->getSampleType() == 'url') {
         $linkData['sample']['type'] = 'url';
         $linkData['sample']['url'] = $link->getSampleUrl();
     }
     $downloadableData = ['link' => [$linkData]];
     $product->setDownloadableData($downloadableData);
     if ($isGlobalScopeContent) {
         $product->setStoreId(0);
     }
     $this->downloadableType->save($product);
     return $product->getLastAddedLinkId();
 }
Beispiel #2
0
 /**
  * Add Sample File info into $linkData
  *
  * @param array $linkData
  * @param LinkInterface $link
  * @return array
  */
 protected function addSampleFile(array $linkData, LinkInterface $link)
 {
     $sampleFile = $link->getSampleFile();
     if ($sampleFile) {
         $file = $this->downloadableFile->getFilePath($this->linkModel->getBaseSamplePath(), $sampleFile);
         if ($this->downloadableFile->ensureFileInFilesystem($file)) {
             $linkData['sample']['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/link', ['id' => $link->getId(), 'type' => 'sample', '_secure' => true])];
         }
     }
     return $linkData;
 }