Esempio n. 1
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param SampleInterface $sample
  * @param bool $isGlobalScopeContent
  * @return int
  */
 protected function saveSample(\Magento\Catalog\Api\Data\ProductInterface $product, SampleInterface $sample, $isGlobalScopeContent)
 {
     $sampleData = ['sample_id' => $sample->getid() === null ? 0 : $sample->getid(), 'is_delete' => 0, 'type' => $sample->getSampleType(), 'sort_order' => $sample->getSortOrder(), 'title' => $sample->getTitle()];
     if ($sample->getSampleType() == 'file' && $sample->getSampleFile() === null) {
         $sampleData['file'] = $this->jsonEncoder->encode([$this->fileContentUploader->upload($sample->getSampleFileContent(), 'sample')]);
     } elseif ($sample->getSampleType() === 'url') {
         $sampleData['sample_url'] = $sample->getSampleUrl();
     } else {
         //existing file
         $sampleData['file'] = $this->jsonEncoder->encode([['file' => $sample->getSampleFile(), 'status' => 'old']]);
     }
     $downloadableData = ['sample' => [$sampleData]];
     $product->setDownloadableData($downloadableData);
     if ($isGlobalScopeContent) {
         $product->setStoreId(0);
     }
     $this->downloadableType->save($product);
     return $product->getLastAddedSampleId();
 }