Class LinkRepository @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Definition at line 25 of file LinkRepository.php.
◆ __construct()
- Parameters
-
\Magento\Catalog\Api\ProductRepositoryInterface | $productRepository | |
\Magento\Downloadable\Model\Product\Type | $downloadableType | |
\Magento\Downloadable\Api\Data\LinkInterfaceFactory | $linkDataObjectFactory | |
LinkFactory | $linkFactory | |
Link\ContentValidator | $contentValidator | |
EncoderInterface | $jsonEncoder | |
ContentUploaderInterface | $fileContentUploader | |
Definition at line 81 of file LinkRepository.php.
◆ save()
{Update downloadable link of the given product (link type and its resources cannot be changed)
- Parameters
-
string | $sku | |
\Magento\Downloadable\Api\Data\LinkInterface | $link | |
bool | $isGlobalScopeContent | |
- Returns
- int
} @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)
Implements LinkRepositoryInterface.
Definition at line 173 of file LinkRepository.php.
175 $product = $this->productRepository->get($sku,
true);
176 if (
$link->getId() !==
null) {
177 return $this->updateLink(
$product,
$link, $isGlobalScopeContent);
180 throw new InputException(
181 __(
'The product needs to be the downloadable type. Verify the product and try again.')
184 $validateLinkContent = !(
$link->getLinkType() ===
'file' &&
$link->getLinkFile());
185 $validateSampleContent = !(
$link->getSampleType() ===
'file' &&
$link->getSampleFile());
186 if (!$this->contentValidator->isValid(
$link, $validateLinkContent, $validateSampleContent)) {
187 throw new InputException(
__(
'The link information is invalid. Verify the link and try again.'));
190 if (!in_array(
$link->getLinkType(), [
'url',
'file'],
true)) {
191 throw new InputException(
__(
'The link type is invalid. Verify and try again.'));
195 throw new InputException(
__(
'The link title is empty. Enter the link title and try again.'));
saveLink(\Magento\Catalog\Api\Data\ProductInterface $product, LinkInterface $link, $isGlobalScopeContent)
◆ saveLink()
- Parameters
-
\Magento\Catalog\Api\Data\ProductInterface | $product | |
LinkInterface | $link | |
bool | $isGlobalScopeContent | |
- Returns
- int
Definition at line 207 of file LinkRepository.php.
213 'link_id' => (int)
$link->getId(),
215 'type' =>
$link->getLinkType(),
216 'sort_order' =>
$link->getSortOrder(),
217 'title' =>
$link->getTitle(),
218 'price' =>
$link->getPrice(),
219 'number_of_downloads' =>
$link->getNumberOfDownloads(),
220 'is_shareable' =>
$link->getIsShareable(),
223 if (
$link->getLinkType() ==
'file' &&
$link->getLinkFile() ===
null) {
224 $linkData[
'file'] = $this->jsonEncoder->encode(
226 $this->fileContentUploader->upload(
$link->getLinkFileContent(),
'link_file'),
233 $linkData[
'file'] = $this->jsonEncoder->encode(
236 'file' =>
$link->getLinkFile(),
243 if (
$link->getSampleType() ==
'file') {
245 if (
$link->getSampleFile() ===
null) {
247 $this->fileContentUploader->upload(
$link->getSampleFileContent(),
'link_sample_file'),
252 'file' =>
$link->getSampleFile(),
257 $linkData[
'sample'][
'file'] = $this->jsonEncoder->encode($fileData);
264 if ($isGlobalScopeContent) {
268 return $product->getLastAddedLinkId();
elseif(isset( $params[ 'redirect_parent']))
◆ setBasicFields()
setBasicFields |
( |
|
$resourceData, |
|
|
|
$dataObject |
|
) |
| |
|
protected |
Subroutine for build link
- Parameters
-
\Magento\Downloadable\Model\Link | $resourceData | |
\Magento\Downloadable\Api\Data\LinkInterface | $dataObject | |
- Returns
- null
Definition at line 152 of file LinkRepository.php.
154 $dataObject->setId($resourceData->getId());
155 $storeTitle = $resourceData->getStoreTitle();
156 $title = $resourceData->getTitle();
157 if (!empty($storeTitle)) {
158 $dataObject->setTitle($storeTitle);
160 $dataObject->setTitle(
$title);
162 $dataObject->setSortOrder($resourceData->getSortOrder());
163 $dataObject->setSampleType($resourceData->getSampleType());
164 $dataObject->setSampleFile($resourceData->getSampleFile());
165 $dataObject->setSampleUrl($resourceData->getSampleUrl());
◆ $contentValidator
◆ $downloadableType
◆ $fileContentUploader
◆ $jsonEncoder
◆ $linkDataObjectFactory
◆ $linkFactory
◆ $productRepository
The documentation for this class was generated from the following file: