Class SampleRepository @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Definition at line 28 of file SampleRepository.php.
◆ __construct()
- Parameters
-
ProductRepositoryInterface | $productRepository | |
Type | $downloadableType | |
SampleInterfaceFactory | $sampleDataObjectFactory | |
ContentValidator | $contentValidator | |
ContentUploaderInterface | $fileContentUploader | |
EncoderInterface | $jsonEncoder | |
SampleFactory | $sampleFactory | |
Definition at line 84 of file SampleRepository.php.
◆ buildSample()
buildSample |
( |
|
$resourceData | ) |
|
|
protected |
Build a sample data object
- Parameters
-
\Magento\Downloadable\Model\Sample | $resourceData | |
- Returns
- \Magento\Downloadable\Model\Sample
Definition at line 118 of file SampleRepository.php.
120 $sample = $this->sampleDataObjectFactory->create();
setBasicFields($resourceData, $dataObject)
◆ save()
Update downloadable sample of the given product
- Parameters
-
string | $sku | |
\Magento\Downloadable\Api\Data\SampleInterface | $sample | |
bool | $isGlobalScopeContent | |
- Returns
- int
- Exceptions
-
InputException | |
NoSuchEntityException | |
Implements SampleRepositoryInterface.
Definition at line 175 of file SampleRepository.php.
180 $product = $this->productRepository->get($sku,
true);
182 $sampleId = $sample->getId();
184 return $this->updateSample(
$product, $sample, $isGlobalScopeContent);
187 throw new InputException(
188 __(
'The product needs to be the downloadable type. Verify the product and try again.')
191 $validateSampleContent = !($sample->getSampleType() ===
'file' && $sample->getSampleFile());
192 if (!$this->contentValidator->isValid($sample, $validateSampleContent)) {
193 throw new InputException(
194 __(
'The sample information is invalid. Verify the information and try again.')
198 if (!in_array($sample->getSampleType(), [
'url',
'file'],
true)) {
199 throw new InputException(
__(
'The sample type is invalid. Verify the sample type and try again.'));
202 $title = $sample->getTitle();
204 throw new InputException(
__(
'The sample title is empty. Enter the title and try again.'));
saveSample(\Magento\Catalog\Api\Data\ProductInterface $product, SampleInterface $sample, $isGlobalScopeContent)
◆ saveSample()
- Parameters
-
\Magento\Catalog\Api\Data\ProductInterface | $product | |
SampleInterface | $sample | |
bool | $isGlobalScopeContent | |
- Returns
- int
Definition at line 217 of file SampleRepository.php.
223 'sample_id' => (int)$sample->getId(),
225 'type' => $sample->getSampleType(),
226 'sort_order' => $sample->getSortOrder(),
227 'title' => $sample->getTitle(),
230 if ($sample->getSampleType() ===
'file' && $sample->getSampleFile() ===
null) {
231 $sampleData[
'file'] = $this->jsonEncoder->encode(
233 $this->fileContentUploader->upload($sample->getSampleFileContent(),
'sample'),
236 }
elseif ($sample->getSampleType() ===
'url') {
237 $sampleData[
'sample_url'] = $sample->getSampleUrl();
240 $sampleData[
'file'] = $this->jsonEncoder->encode(
243 'file' => $sample->getSampleFile(),
252 if ($isGlobalScopeContent) {
256 return $product->getLastAddedSampleId();
elseif(isset( $params[ 'redirect_parent']))
◆ setBasicFields()
setBasicFields |
( |
|
$resourceData, |
|
|
|
$dataObject |
|
) |
| |
|
protected |
Subroutine for buildLink and buildSample
- Parameters
-
\Magento\Downloadable\Model\Link | \Magento\Downloadable\Model\Sample | $resourceData | |
\Magento\Downloadable\Api\Data\LinkInterface | \Magento\Downloadable\Api\Data\SampleInterface | $dataObject | |
- Returns
- null
Definition at line 132 of file SampleRepository.php.
134 $dataObject->setId($resourceData->getId());
135 $storeTitle = $resourceData->getStoreTitle();
136 $title = $resourceData->getTitle();
137 if (!empty($storeTitle)) {
138 $dataObject->setTitle($storeTitle);
140 $dataObject->setTitle(
$title);
142 $dataObject->setSortOrder($resourceData->getSortOrder());
143 $dataObject->setSampleType($resourceData->getSampleType());
144 $dataObject->setSampleFile($resourceData->getSampleFile());
145 $dataObject->setSampleUrl($resourceData->getSampleUrl());
◆ $contentValidator
◆ $downloadableType
◆ $fileContentUploader
◆ $jsonEncoder
◆ $productRepository
◆ $sampleDataObjectFactory
◆ $sampleFactory
The documentation for this class was generated from the following file: