forked from nfe888/magento2-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from magento-south/origin/develop
[SOUTH] Sample external links module
- Loading branch information
Showing
19 changed files
with
1,501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\ExternalLinks\Api\Data; | ||
|
||
use Magento\Framework\Api\ExtensibleDataInterface; | ||
|
||
interface ExternalLinkInterface extends ExtensibleDataInterface | ||
{ | ||
const TYPE = "type"; | ||
|
||
const LINK = "link"; | ||
|
||
const PRODUCT_ID = "product_id"; | ||
|
||
const LINK_ID = "link_id"; | ||
|
||
/** | ||
* Retrieve Link Type | ||
* | ||
* @return string | ||
*/ | ||
public function getLinkType(); | ||
|
||
/** | ||
* Set Link Type | ||
* | ||
* @param string $type | ||
* @return self | ||
*/ | ||
public function setLinkType($type); | ||
|
||
/** | ||
* Retrieve Provider link | ||
* | ||
* @return string | ||
*/ | ||
public function getLink(); | ||
|
||
/** | ||
* Set Provider link | ||
* | ||
* @param string $link | ||
* @return self | ||
*/ | ||
public function setLink($link); | ||
|
||
/** | ||
* Set Product Id for further updates | ||
* | ||
* @param int $id | ||
* @return self | ||
*/ | ||
public function setProductId($id); | ||
|
||
/** | ||
* Retrieve product id | ||
* | ||
* @return int | ||
*/ | ||
public function getProductId(); | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getLinkId(); | ||
|
||
/** | ||
* @param int $linkId | ||
* @return self | ||
*/ | ||
public function setLinkId($linkId); | ||
|
||
/** | ||
* @return \Magento\ExternalLinks\Api\Data\ExternalLinkExtensionInterface|null | ||
*/ | ||
public function getExtensionAttributes(); | ||
|
||
/** | ||
* @param \Magento\ExternalLinks\Api\Data\ExternalLinkExtensionInterface $extensionAttributes | ||
* @return self | ||
*/ | ||
public function setExtensionAttributes | ||
( | ||
\Magento\ExternalLinks\Api\Data\ExternalLinkExtensionInterface $extensionAttributes | ||
); | ||
} |
16 changes: 16 additions & 0 deletions
16
sample-external-links/Api/ExternalLinksProviderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\ExternalLinks\Api; | ||
|
||
interface ExternalLinksProviderInterface | ||
{ | ||
/** | ||
* @param int $productId | ||
* @return array | ||
*/ | ||
public function getLinks($productId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\ExternalLinks\Model; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\ExternalLinks\Api\Data\ExternalLinkInterface; | ||
|
||
/** | ||
* Class ExternalLink | ||
* @package Magento\ExternalLinks\Model | ||
*/ | ||
final class ExternalLink implements ExternalLinkInterface | ||
{ | ||
/** @var array */ | ||
private $link; | ||
|
||
/** @var int */ | ||
private $linkId; | ||
|
||
/** @var int */ | ||
private $productId; | ||
|
||
/** @var string */ | ||
private $linkType; | ||
|
||
/** @var array */ | ||
private $extenstionAttributes; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLink() | ||
{ | ||
return $this->link; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setLink($link) | ||
{ | ||
$this->link = $link; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLinkType() | ||
{ | ||
return $this->linkType; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setLinkType($type) | ||
{ | ||
$this->linkType = $type; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLinkId() | ||
{ | ||
return $this->linkId; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setLinkId($linkId) | ||
{ | ||
$this->linkId = $linkId; | ||
return $this->linkId; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getProductId() | ||
{ | ||
return $this->productId; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setProductId($id) | ||
{ | ||
$this->productId = $id; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setExtensionAttributes( | ||
\Magento\ExternalLinks\Api\Data\ExternalLinkExtensionInterface $extensionAttributes | ||
) | ||
{ | ||
$this->extenstionAttributes = $extensionAttributes; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getExtensionAttributes() | ||
{ | ||
return $this->extenstionAttributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\ExternalLinks\Model\ExternalLinks; | ||
|
||
use Magento\ExternalLinks\Api\ExternalLinksProviderInterface; | ||
use Magento\ExternalLinks\Model\ResourceModel\ExternalLinks\Loader; | ||
use Magento\Framework\EntityManager\EntityManager; | ||
use Magento\ExternalLinks\Model\ExternalLinkFactory; | ||
|
||
/** | ||
* Class Provider | ||
* @package Magento\ExternalLinks\Model\ExternalLinks | ||
*/ | ||
class Provider implements ExternalLinksProviderInterface | ||
{ | ||
/** @var EntityManager */ | ||
private $entityManager; | ||
|
||
/** @var Loader */ | ||
private $loader; | ||
|
||
/** @var ExternalLinkFactory */ | ||
private $externalLinkFactory; | ||
|
||
/** | ||
* Provider constructor. | ||
* @param EntityManager $entityManager | ||
* @param Loader $loader | ||
*/ | ||
public function __construct | ||
( | ||
EntityManager $entityManager, | ||
Loader $loader, | ||
ExternalLinkFactory $externalLinkFactory | ||
) { | ||
$this->entityManager = $entityManager; | ||
$this->loader = $loader; | ||
$this->externalLinkFactory = $externalLinkFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLinks($productId) | ||
{ | ||
$externalLinks = []; | ||
$ids = $this->loader->getIdsByProductId($productId); | ||
|
||
foreach($ids as $id) { | ||
$externalLink = $this->externalLinkFactory->create(); | ||
$externalLinks[] = $this->entityManager->load($externalLink, $id); | ||
} | ||
|
||
return $externalLinks; | ||
} | ||
} |
Oops, something went wrong.