Skip to content

Commit 656b875

Browse files
committed
MAGETWO-87785: Creation of attribute with new input type via API
1 parent 72523a5 commit 656b875

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ interface ProductAttributeInterface extends \Magento\Catalog\Api\Data\EavAttribu
3232
const CODE_TIER_PRICE_FIELD_VALUE_TYPE = 'value_type';
3333
const CODE_SEO_FIELD_META_DESCRIPTION = 'meta_description';
3434
const CODE_WEIGHT = 'weight';
35+
36+
/**
37+
* @return \Magento\Eav\Api\Data\AttributeExtensionInterface
38+
*/
39+
public function getExtensionAttributes();
3540
}

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* @method int setSearchWeight(int $value)
2222
* @method bool getIsUsedForPriceRules()
2323
* @method int setIsUsedForPriceRules(int $value)
24-
* @method \Magento\Eav\Api\Data\AttributeExtensionInterface getExtensionAttributes()
2524
*
2625
* @author Magento Core Team <core@magentocommerce.com>
2726
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -80,6 +79,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
8079
*/
8180
protected $_indexerEavProcessor;
8281

82+
/**
83+
* @var \Magento\Eav\Api\Data\AttributeExtensionFactory
84+
*/
85+
private $eavAttributeFactory;
86+
8387
/**
8488
* @param \Magento\Framework\Model\Context $context
8589
* @param \Magento\Framework\Registry $registry
@@ -129,12 +133,15 @@ public function __construct(
129133
LockValidatorInterface $lockValidator,
130134
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
131135
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
136+
\Magento\Eav\Api\Data\AttributeExtensionFactory $eavAttributeFactory = null,
132137
array $data = []
133138
) {
134139
$this->_indexerEavProcessor = $indexerEavProcessor;
135140
$this->_productFlatIndexerProcessor = $productFlatIndexerProcessor;
136141
$this->_productFlatIndexerHelper = $productFlatIndexerHelper;
137142
$this->attrLockValidator = $lockValidator;
143+
$this->eavAttributeFactory = $eavAttributeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
144+
->get(\Magento\Eav\Api\Data\AttributeExtensionFactory::class);
138145
parent::__construct(
139146
$context,
140147
$registry,
@@ -887,4 +894,18 @@ public function setIsFilterableInGrid($isFilterableInGrid)
887894
$this->setData(self::IS_FILTERABLE_IN_GRID, $isFilterableInGrid);
888895
return $this;
889896
}
897+
898+
/**
899+
* @return \Magento\Eav\Api\Data\AttributeExtensionInterface
900+
*/
901+
public function getExtensionAttributes()
902+
{
903+
$extensionAttributes = $this->_getExtensionAttributes();
904+
if (null === $extensionAttributes) {
905+
/** @var \Magento\Eav\Api\Data\AttributeExtensionInterface $extensionAttributes */
906+
$extensionAttributes = $this->eavAttributeFactory->create();
907+
$this->setExtensionAttributes($extensionAttributes);
908+
}
909+
return $extensionAttributes;
910+
}
890911
}

app/code/Magento/Eav/Api/Data/AttributeInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,14 @@ public function setValidationRules(array $validationRules = null);
307307
* @return \Magento\Eav\Api\Data\AttributeExtensionInterface|null
308308
*/
309309
public function getExtensionAttributes();
310+
311+
/**
312+
* Set an extension attributes object
313+
*
314+
* @param \Magento\Eav\Api\Data\AttributeExtensionInterface $extensionAttributes
315+
* @return $this
316+
*/
317+
public function setExtensionAttributes(
318+
\Magento\Eav\Api\Data\AttributeExtensionInterface $extensionAttributes
319+
);
310320
}

app/code/Magento/Eav/Model/Entity/Attribute.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
* @api
1717
* @method \Magento\Eav\Model\Entity\Attribute setOption($value)
18-
* @method \Magento\Eav\Api\Data\AttributeExtensionInterface getExtensionAttributes()
1918
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2019
* @since 100.0.2
2120
*/

0 commit comments

Comments
 (0)