Definition at line 14 of file Management.php.
◆ __construct()
- Parameters
-
\Magento\Catalog\Api\ProductRepositoryInterface | $productRepository | |
\Magento\Catalog\Model\Product\LinkTypeProvider | $linkTypeProvider | |
Definition at line 30 of file Management.php.
◆ getLinkedItemsByType()
getLinkedItemsByType |
( |
|
$sku, |
|
|
|
$type |
|
) |
| |
{Provide the list of links for a specific product
- Parameters
-
- Returns
- \Magento\Catalog\Api\Data\ProductLinkInterface[]
}
Implements ProductLinkManagementInterface.
Definition at line 41 of file Management.php.
45 $linkTypes = $this->linkTypeProvider->getLinkTypes();
47 if (!isset($linkTypes[
$type])) {
48 throw new NoSuchEntityException(
49 __(
'The "%1" link type is unknown. Verify the type and try again.', (
string)
$type)
52 $product = $this->productRepository->get($sku);
◆ setProductLinks()
setProductLinks |
( |
|
$sku, |
|
|
array |
$items |
|
) |
| |
{Assign a product link to another product
- Parameters
-
}
Implements ProductLinkManagementInterface.
Definition at line 68 of file Management.php.
70 $linkTypes = $this->linkTypeProvider->getLinkTypes();
74 foreach (
$items as $newLink) {
75 $type = $newLink->getLinkType();
79 if (!isset($linkTypes[
$type])) {
80 throw new NoSuchEntityException(
81 __(
'The "%1" link type wasn\'t found. Verify the type and try again.',
$type)
87 $product = $this->productRepository->get($sku);
90 $existingLinks =
$product->getProductLinks();
92 if (!empty($existingLinks)) {
93 foreach ($existingLinks as
$link) {
104 $this->productRepository->save(
$product);
105 }
catch (\Exception $exception) {
106 throw new CouldNotSaveException(
__(
'The linked products data is invalid. Verify the data and try again.'));
◆ $linkTypeProvider
◆ $productRepository
The documentation for this class was generated from the following file: