-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bart Lubbersen
committed
Dec 21, 2016
0 parents
commit 567397f
Showing
8 changed files
with
155 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,27 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* Catalog product categories backend attribute model | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
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); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Experius\ProductWebsiteIdsApi\Model; | ||
|
||
class ProductRepository extends \Magento\Catalog\Model\ProductRepository | ||
{ | ||
|
||
/** | ||
* Merge data from DB and updates from request | ||
* | ||
* @param array $productData | ||
* @param bool $createNew | ||
* @return \Magento\Catalog\Api\Data\ProductInterface|Product | ||
* @throws NoSuchEntityException | ||
*/ | ||
protected function initializeProductData(array $productData, $createNew) | ||
{ | ||
$websiteIds = null; | ||
if (isset($productData['website_ids'])){ | ||
$websiteIds = $productData['website_ids']; | ||
} | ||
$product = parent::initializeProductData($productData, $createNew); | ||
if ($websiteIds){ | ||
if (!$this->storeManager->hasSingleStore()) { | ||
$product->setWebsiteIds(array_unique($websiteIds)); | ||
} | ||
} | ||
return $product; | ||
} | ||
} |
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,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. |
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,47 @@ | ||
<?php | ||
|
||
|
||
namespace Experius\ProductWebsiteIdsApi\Setup; | ||
|
||
use Magento\Eav\Setup\EavSetup; | ||
use Magento\Framework\Setup\InstallDataInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Eav\Setup\EavSetupFactory; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
|
||
class InstallData implements InstallDataInterface { | ||
|
||
private $eavSetupFactory; | ||
|
||
|
||
public function __construct(EavSetupFactory $eavSetupFactory){ | ||
$this->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, | ||
] | ||
); | ||
|
||
} | ||
} |
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,23 @@ | ||
{ | ||
"name": "experius/module-productwebsiteidsapi", | ||
"description": "Adds functionality to the API to set and get website ids per product", | ||
"authors": [ | ||
{ | ||
"name": "Experius", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {}, | ||
"license": [ | ||
"OSL-3.0", | ||
"AFL-3.0" | ||
], | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"Experius\\ProductWebsiteidsApi\\": "" | ||
} | ||
} | ||
} |
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,10 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Magento\Catalog\Api\ProductRepositoryInterface" type="Experius\ProductWebsiteIdsApi\Model\ProductRepository" /> | ||
</config> |
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,8 @@ | ||
<?xml version="1.0" ?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Experius_ProductWebsiteIdsApi" setup_version="1.0.0"> | ||
<sequence> | ||
<module name="Magento_Catalog" /> | ||
</sequence> | ||
</module> | ||
</config> |
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,6 @@ | ||
<?php | ||
\Magento\Framework\Component\ComponentRegistrar::register( | ||
\Magento\Framework\Component\ComponentRegistrar::MODULE, | ||
'Experius_ProductWebsiteIdsApi', | ||
__DIR__ | ||
); |