I'm trying to get all attributes that belong to each product set back, either using the \Magento\Catalog\Model\Product\Attribute\ManagementFactory
or \Magento\Catalog\Api\ProductAttributeManagementInterface
.
It's works fine when there is one attribute set and returns the results expected; however if I want to get multiple attribute sets - the subsequent request is not as expected.
Digging into the code I've traced it down into \Magento\Eav\Model\AttributeManagement::getAttributes
and echo'ing the select that the method generates shows the second query appends the attribute set filter as opposed to resetting it.
To recreate it you can use the following code; attribute set 4 is the 'default' one and 9 is the one that I have manually added.
Once the code below is ran it generates the following selects
$obj->create()->getAttributes(4);
SELECT `main_table`.*, `entity_attribute`.* FROM `eav_attribute` AS `main_table` INNER JOIN `eav_entity_attribute` AS `entity_attribute` ON entity_attribute.attribute_id = main_table.attribute_id WHERE (`entity_attribute`.`attribute_set_id` = '4') ORDER BY entity_attribute.sort_order ASC
$obj->create()->getAttributes(9); (note the 2 where clauses)
SELECT `main_table`.*, `entity_attribute`.* FROM `eav_attribute` AS `main_table` INNER JOIN `eav_entity_attribute` AS `entity_attribute` ON entity_attribute.attribute_id = main_table.attribute_id WHERE (`entity_attribute`.`attribute_set_id` = '4') AND (`entity_attribute`.`attribute_set_id` = '9') ORDER BY entity_attribute.sort_order ASC
<?php
require __DIR__ . '/app/bootstrap.php';
class TestApp extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface
{
public function launch()
{
$this->_state->setAreaCode('adminhtml');
$obj = $this->_objectManager->create('\Magento\Catalog\Model\Product\Attribute\ManagementFactory');
$attr1 = $obj->create()->getAttributes(4);
$attr2 = $obj->create()->getAttributes(9);
die();
}
public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
{
return false;
}
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);