diff --git a/Model/Accessory.php b/Model/Accessory.php index 95f2539..9f5263a 100644 --- a/Model/Accessory.php +++ b/Model/Accessory.php @@ -6,7 +6,16 @@ namespace MagePal\LinkProduct\Model; -class Accessory extends \Magento\Framework\DataObject +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\ResourceModel\Product\Link\Collection; +use Magento\Framework\DataObject; +use MagePal\LinkProduct\Model\Product\Link; + +/** + * Class Accessory + * @package MagePal\LinkProduct\Model + */ +class Accessory extends DataObject { /** * Product link instance @@ -15,8 +24,12 @@ class Accessory extends \Magento\Framework\DataObject */ protected $linkInstance; + /** + * Accessory constructor. + * @param Link $productLink + */ public function __construct( - \MagePal\LinkProduct\Model\Product\Link $productLink + Link $productLink ) { $this->linkInstance = $productLink; } @@ -34,10 +47,10 @@ public function getLinkInstance() /** * Retrieve array of Accessory products * - * @param \Magento\Catalog\Model\Product $currentProduct + * @param Product $currentProduct * @return array */ - public function getAccessoryProducts(\Magento\Catalog\Model\Product $currentProduct) + public function getAccessoryProducts(Product $currentProduct) { if (!$this->hasAccessoryProducts()) { $products = []; @@ -53,10 +66,10 @@ public function getAccessoryProducts(\Magento\Catalog\Model\Product $currentProd /** * Retrieve accessory products identifiers * - * @param \Magento\Catalog\Model\Product $currentProduct + * @param Product $currentProduct * @return array */ - public function getAccessoryProductIds(\Magento\Catalog\Model\Product $currentProduct) + public function getAccessoryProductIds(Product $currentProduct) { if (!$this->hasAccessoryProductIds()) { $ids = []; @@ -71,10 +84,10 @@ public function getAccessoryProductIds(\Magento\Catalog\Model\Product $currentPr /** * Retrieve collection accessory product * - * @param \Magento\Catalog\Model\Product $currentProduct + * @param Product $currentProduct * @return \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection */ - public function getAccessoryProductCollection(\Magento\Catalog\Model\Product $currentProduct) + public function getAccessoryProductCollection(Product $currentProduct) { $collection = $this->getLinkInstance()->useAccessoryLinks()->getProductCollection()->setIsStrongMode(); $collection->setProduct($currentProduct); @@ -84,10 +97,10 @@ public function getAccessoryProductCollection(\Magento\Catalog\Model\Product $cu /** * Retrieve collection accessory link * - * @param \Magento\Catalog\Model\Product $currentProduct - * @return \Magento\Catalog\Model\ResourceModel\Product\Link\Collection + * @param Product $currentProduct + * @return Collection */ - public function getAccessoryLinkCollection(\Magento\Catalog\Model\Product $currentProduct) + public function getAccessoryLinkCollection(Product $currentProduct) { $collection = $this->getLinkInstance()->useAccessoryLinks()->getLinkCollection(); $collection->setProduct($currentProduct); diff --git a/Model/Product/CopyConstructor/Accessory.php b/Model/Product/CopyConstructor/Accessory.php index fd77d5e..97ea15c 100644 --- a/Model/Product/CopyConstructor/Accessory.php +++ b/Model/Product/CopyConstructor/Accessory.php @@ -6,16 +6,24 @@ namespace MagePal\LinkProduct\Model\Product\CopyConstructor; -class Accessory implements \Magento\Catalog\Model\Product\CopyConstructorInterface +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\CopyConstructorInterface; +use Magento\Catalog\Model\Product\Link; + +/** + * Class Accessory + * @package MagePal\LinkProduct\Model\Product\CopyConstructor + */ +class Accessory implements CopyConstructorInterface { /** * Build product links * - * @param \Magento\Catalog\Model\Product $product - * @param \Magento\Catalog\Model\Product $duplicate + * @param Product $product + * @param Product $duplicate * @return void */ - public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate) + public function build(Product $product, Product $duplicate) { $data = []; $attributes = []; @@ -27,10 +35,11 @@ public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\ $attributes[] = $attribute['code']; } } - /** @var \Magento\Catalog\Model\Product\Link $link */ + /** @var Link $link */ foreach ($product->getAccessoryLinkCollection() as $link) { $data[$link->getLinkedProductId()] = $link->toArray($attributes); } + $duplicate->setAccessoryLinkData($data); } } diff --git a/Model/Product/Link.php b/Model/Product/Link.php index 679561b..f5786fe 100644 --- a/Model/Product/Link.php +++ b/Model/Product/Link.php @@ -6,6 +6,10 @@ namespace MagePal\LinkProduct\Model\Product; +/** + * Class Link + * @package MagePal\LinkProduct\Model\Product + */ class Link extends \Magento\Catalog\Model\Product\Link { const LINK_TYPE_ACCESSORY = 7; diff --git a/Model/ProductLink/CollectionProvider/Accessory.php b/Model/ProductLink/CollectionProvider/Accessory.php index 6f99fe2..5a44112 100644 --- a/Model/ProductLink/CollectionProvider/Accessory.php +++ b/Model/ProductLink/CollectionProvider/Accessory.php @@ -6,11 +6,22 @@ namespace MagePal\LinkProduct\Model\ProductLink\CollectionProvider; -class Accessory implements \Magento\Catalog\Model\ProductLink\CollectionProviderInterface +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\ProductLink\CollectionProviderInterface; + +/** + * Class Accessory + * @package MagePal\LinkProduct\Model\ProductLink\CollectionProvider + */ +class Accessory implements CollectionProviderInterface { /** @var \MagePal\LinkProduct\Model\Accessory */ protected $accessoryModel; + /** + * Accessory constructor. + * @param \MagePal\LinkProduct\Model\Accessory $accessoryModel + */ public function __construct( \MagePal\LinkProduct\Model\Accessory $accessoryModel ) { @@ -20,7 +31,7 @@ public function __construct( /** * {@inheritdoc} */ - public function getLinkedProducts(\Magento\Catalog\Model\Product $product) + public function getLinkedProducts(Product $product) { return (array) $this->accessoryModel->getAccessoryProducts($product); } diff --git a/Plugin/CatalogImportExport/Model/Import/Product.php b/Plugin/CatalogImportExport/Model/Import/Product.php index 0fa4ffc..43a6a33 100644 --- a/Plugin/CatalogImportExport/Model/Import/Product.php +++ b/Plugin/CatalogImportExport/Model/Import/Product.php @@ -2,22 +2,25 @@ namespace MagePal\LinkProduct\Plugin\CatalogImportExport\Model\Import; +use Magento\CatalogImportExport\Model\Import\Produc; +use MagePal\LinkProduct\Model\Product\Link; + /** * @see \Magento\CatalogImportExport\Model\Import\Product::getLinkNameToId */ class Product { /** - * REMARK: needs core patch https://github.com/magento/magento2/pull/21230/commits/0846e9aed7040659e7ce3e109eb91df3f5fdfb7e.patch + * REMARK: needs core patch + * https://github.com/magento/magento2/pull/21230/commits/0846e9aed7040659e7ce3e109eb91df3f5fdfb7e.patch * - * @param \Magento\CatalogImportExport\Model\Import\Produc $subject + * @param \Magento\CatalogImportExport\Model\Import\Product $subject * @param $result - * * @return mixed */ public function afterGetLinkNameToId(\Magento\CatalogImportExport\Model\Import\Product $subject, $result) { - $result['_accessory_'] = \MagePal\LinkProduct\Model\Product\Link::LINK_TYPE_ACCESSORY; + $result['_accessory_'] = Link::LINK_TYPE_ACCESSORY; return $result; } diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index eb9bce9..2210b24 100644 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -9,7 +9,13 @@ use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; +use MagePal\LinkProduct\Model\Product\Link; +use MagePal\LinkProduct\Ui\DataProvider\Product\Form\Modifier\Accessory; +/** + * Class InstallSchema + * @package MagePal\LinkProduct\Setup + */ class InstallSchema implements InstallSchemaInterface { @@ -25,8 +31,8 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con * Install product link types in table (catalog_product_link_type) */ $catalogProductLinkTypeData = [ - 'link_type_id' => \MagePal\LinkProduct\Model\Product\Link::LINK_TYPE_ACCESSORY, - 'code' => \MagePal\LinkProduct\Ui\DataProvider\Product\Form\Modifier\Accessory::DATA_SCOPE_ACCESSORY + 'link_type_id' => Link::LINK_TYPE_ACCESSORY, + 'code' => Accessory::DATA_SCOPE_ACCESSORY ]; $setup->getConnection()->insertOnDuplicate( @@ -38,7 +44,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con * install product link attributes position in table catalog_product_link_attribute */ $catalogProductLinkAttributeData = [ - 'link_type_id' => \MagePal\LinkProduct\Model\Product\Link::LINK_TYPE_ACCESSORY, + 'link_type_id' => Link::LINK_TYPE_ACCESSORY, 'product_link_attribute_code' => 'position', 'data_type' => 'int', ]; diff --git a/Ui/DataProvider/Product/Form/Modifier/Accessory.php b/Ui/DataProvider/Product/Form/Modifier/Accessory.php index cd7b5fa..22bbec0 100644 --- a/Ui/DataProvider/Product/Form/Modifier/Accessory.php +++ b/Ui/DataProvider/Product/Form/Modifier/Accessory.php @@ -6,9 +6,14 @@ namespace MagePal\LinkProduct\Ui\DataProvider\Product\Form\Modifier; +use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related; use Magento\Ui\Component\Form\Fieldset; -class Accessory extends \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related +/** + * Class Accessory + * @package MagePal\LinkProduct\Ui\DataProvider\Product\Form\Modifier + */ +class Accessory extends Related { const DATA_SCOPE_ACCESSORY = 'accessory'; /** @@ -39,10 +44,10 @@ public function modifyMeta(array $meta) 'componentType' => Fieldset::NAME, 'dataScope' => static::DATA_SCOPE, 'sortOrder' => $this->getNextGroupSortOrder( - $meta, - self::$previousGroup, - self::$sortOrder - ), + $meta, + self::$previousGroup, + self::$sortOrder + ), ], ], ], diff --git a/Ui/DataProvider/Product/Related/AccessoryDataProvider.php b/Ui/DataProvider/Product/Related/AccessoryDataProvider.php index 00117dc..93c9028 100644 --- a/Ui/DataProvider/Product/Related/AccessoryDataProvider.php +++ b/Ui/DataProvider/Product/Related/AccessoryDataProvider.php @@ -8,6 +8,10 @@ use Magento\Catalog\Ui\DataProvider\Product\Related\AbstractDataProvider; +/** + * Class AccessoryDataProvider + * @package MagePal\LinkProduct\Ui\DataProvider\Product\Related + */ class AccessoryDataProvider extends AbstractDataProvider { /** diff --git a/composer.json b/composer.json index 2fe74d5..cb250f6 100644 --- a/composer.json +++ b/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.1.3|~7.2.0", - "magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.0", + "magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.*", "magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*" }, "type": "magento2-module", - "version": "1.1.1", + "version": "1.1.2", "autoload": { "files": [ "registration.php"