i have made a drop down named test_attribute and multi_attribute for products and i want to show that into api call of products as well i have made extension_attributes.xml but nothing in extension_attributes.xml shows up in api call can some body help?
extension_attributes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="MagentoCatalogApiDataProductInterface">
<attribute code="multi_attribute" type="string[]" />
<attribute code="test_attributee" type="int" />
<attribute code="is_featured" type="string" />
</extension_attributes>
</config>
db_schema.xml
<?xml version="1.0" ?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table comment="Catalog Product Table" engine="innodb" name="catalog_product_entity" resource="default">
<column comment="Featured Product" length="64" name="is_featured" nullable="true" xsi:type="varchar"/>
</table>
</schema>
di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- <preference for="FSDTestApiProductsInterface" type="FSDTestModelProductsManagment"/> -->
<type name="MagentoCatalogApiProductRepositoryInterface">
<plugin name="product_repository_plugin" type="FSDTestPluginProductRepositoryInterface" />
</type>
</config>
productRepositoryInterface.php
<?php
namespace FSDTestPlugin;
use MagentoCatalogApiDataProductExtensionInterface;
use MagentoCatalogApiDataProductInterface;
use MagentoCatalogApiDataProductExtensionFactory;
class ProductRepositoryInterface
{
/**
* @var ProductExtensionFactory
*/
private $extensionFactory;
/**
* @param ProductExtensionFactory $extensionFactory
*/
public function __construct(ProductExtensionFactory $extensionFactory)
{
$this->extensionFactory = $extensionFactory;
}
public function afterGet(
MagentoCatalogApiProductRepositoryInterface $subject,
MagentoCatalogApiDataProductInterface $entity
) {
$ourCustomData = $this->customDataRepository->get($entity->getId());
$extensionAttributes = $entity->getExtensionAttributes(); /** get current extension attributes from entity **/
$extensionAttributes->setOurCustomData($ourCustomData);
$entity->setExtensionAttributes($extensionAttributes);
return $entity;
}
public function afterSave(
MagentoCatalogApiProductRepositoryInterface $subject,
MagentoCatalogApiDataProductInterface $entity
) {
$extensionAttributes = $entity->getExtensionAttributes(); /** get current extension attributes from entity **/
$ourCustomData = $extensionAttributes->getOurCustomData();
$this->customDataRepository->save($ourCustomData);
return $entity;
}
/**
* Loads product entity extension attributes
*
* @param ProductInterface $entity
* @param ProductExtensionInterface|null $extension
* @return ProductExtensionInterface
*/
public function afterGetExtensionAttributes(
ProductInterface $entity,
ProductExtensionInterface $extension = null
) {
if ($extension === null) {
$extension = $this->extensionFactory->create();
}
return $extension;
}
}
UpgradeData.php
<?php
/**
* Copyright © FoodServiceDirect, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace FSDTestSetup;
use MagentoFrameworkSetupUpgradeDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavSetupEavSetupFactory;
class UpgradeData implements UpgradeDataInterface
{
/**
*
* @var type
*/
private $eavSetupFactory;
/**
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
if (version_compare($context->getVersion(), '1.1.1', '<')) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'test_attribute',
[
'group' => 'General',
'type' => 'int',
'label' => 'Include Test Attribute',
'user_defined' => false,
'backend' => '',
'input' => 'boolean',
'visible' => true,
'wysiwyg_enabled' => false,
'source' => MagentoEavModelEntityAttributeSourceBoolean::class,
'required' => false,
'sort_order' => 150,
'default' => '0',
'global' => MagentoCatalogModelResourceModelEavAttribute::SCOPE_GLOBAL,
'used_in_product_listing' => true,
'visible_on_front' => false,
]
);
}
if (version_compare($context->getVersion(), '1.1.4', '<')) {
dd("jfjf");
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'multi_attribute',
[
'group' => 'General',
'label' => 'Multiselect Attribute',
'type' => 'text',
'input' => 'multiselect',
'source' => 'FSDTestExtensionModelConfigProductExtensionoption',
'required' => false,
'sort_order' => 30,
'global' => MagentoCatalogModelResourceModelEavAttribute::SCOPE_STORE,
'used_in_product_listing' => true,
'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
'visible_on_front' => false,
'visible' => true
]
);
}
if (version_compare($context->getVersion(), '1.3.1', '<')) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'test_attributee',
[
'group' => 'General',
'type' => 'int',
'label' => 'Include Test Attribute',
'user_defined' => false,
'backend' => '',
'input' => 'boolean',
'visible' => true,
'wysiwyg_enabled' => false,
'source' => MagentoEavModelEntityAttributeSourceBoolean::class,
'required' => false,
'sort_order' => 150,
'default' => '0',
'global' => MagentoCatalogModelResourceModelEavAttribute::SCOPE_GLOBAL,
'used_in_product_listing' => true,
'visible_on_front' => false,
]
);
}
if (version_compare($context->getVersion(), '1.4.0', '<')) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'multi_attribute',
[
'group' => 'General',
'label' => 'Select Titles',
'type' => 'text',
'input' => 'multiselect',
'source' => 'FSDTestModelAllTitles',
'required' => false,
'sort_order' => 30,
'global' => MagentoCatalogModelResourceModelEavAttribute::SCOPE_STORE,
'used_in_product_listing' => true,
'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
'visible_on_front' => false,
'visible' => true
]
);
}
$setup->endSetup();
}
}