/** * Check if sample content is valid * * @param SampleInterface $sample * @param bool $validateSampleContent * @return bool * @throws InputException */ public function isValid(SampleInterface $sample, $validateSampleContent = true) { if (!is_int($sample->getSortOrder()) || $sample->getSortOrder() < 0) { throw new InputException(__('Sort order must be a positive integer.')); } if ($validateSampleContent) { $this->validateSampleResource($sample); } return true; }
/** * Check if sample content is valid * * @param SampleInterface $sample * @param bool $validateSampleContent * @return bool * @throws InputException */ public function isValid(SampleInterface $sample, $validateSampleContent = true) { if (filter_var($sample->getSortOrder(), FILTER_VALIDATE_INT) === false || $sample->getSortOrder() < 0) { throw new InputException(__('Sort order must be a positive integer.')); } if ($validateSampleContent) { $this->validateSampleResource($sample); } return true; }
/** * @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(); }