diff --git a/Model/Product/Attribute/Backend/Website.php b/Model/Product/Attribute/Backend/Website.php new file mode 100644 index 0000000..e2e64b4 --- /dev/null +++ b/Model/Product/Attribute/Backend/Website.php @@ -0,0 +1,27 @@ + + */ +namespace Experius\ProductWebsiteIdsApi\Model\Product\Attribute\Backend; + +class Website extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend +{ + /** + * Set website ids to product data + * + * @param \Magento\Catalog\Model\Product $object + * @return $this + */ + public function afterLoad($object) + { + $object->setData($this->getAttribute()->getAttributeCode(), $object->getWebsiteIds()); + return parent::afterLoad($object); + } +} diff --git a/Model/ProductRepository.php b/Model/ProductRepository.php new file mode 100644 index 0000000..ab6f03c --- /dev/null +++ b/Model/ProductRepository.php @@ -0,0 +1,30 @@ +storeManager->hasSingleStore()) { + $product->setWebsiteIds(array_unique($websiteIds)); + } + } + return $product; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e016dfe --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Experius Product website ids module for Magento 2 +Adds functionality to the API to set and get website ids per product + +### This module uses a preference for the productRepository class which could conflict. Unfortunately there was no other way. \ No newline at end of file diff --git a/Setup/InstallData.php b/Setup/InstallData.php new file mode 100644 index 0000000..8c586bb --- /dev/null +++ b/Setup/InstallData.php @@ -0,0 +1,47 @@ +eavSetupFactory = $eavSetupFactory; + } + + + public function install( + ModuleDataSetupInterface $setup, + ModuleContextInterface $context + ){ + $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'website_ids', + [ + 'type' => 'static', + 'label' => 'Websites', + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'backend' => 'Experius\ProductWebsiteIdsApi\Model\Product\Attribute\Backend\Website', + 'required' => false, + 'sort_order' => 9, + 'visible' => false, + 'group' => 'General', + 'is_used_in_grid' => false, + 'is_visible_in_grid' => false, + 'is_filterable_in_grid' => false, + ] + ); + + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ee5bfdf --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "experius/module-productwebsiteidsapi", + "description": "Adds functionality to the API to set and get website ids per product", + "authors": [ + { + "name": "Experius", + "email": "info@experius.nl" + } + ], + "require": {}, + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Experius\\ProductWebsiteidsApi\\": "" + } + } +} \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..24f0bfe --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..9064056 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..299f1c6 --- /dev/null +++ b/registration.php @@ -0,0 +1,6 @@ +