特定の属性を持つ属性セット
-
16-10-2019 - |
質問
特定の属性を含む属性セットでコレクションを入手するにはどうすればよいですか?
各属性セットをロードして内部の属性をチェックしないように、単一のコレクションウォーク(シングルセレクト)からこれにできるようになりたいです。
私はこの縫い目が標準的なもののようなものであることを知っていますが、最近は少し遅いです。
解決
$attributeId = 96;
$collection = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->addFieldToFilter('eav_entity_attribute.attribute_id', $attributeId)
->addFieldToFilter('eav_entity_type.entity_type_code', Mage_Catalog_Model_Product::ENTITY)
->join(array('eav_entity_type'=> 'eav/entity_type'), 'eav_entity_type.entity_type_id=main_table.entity_type_id','entity_type_code')
->join(array('eav_entity_attribute'=> 'eav/entity_attribute'), 'eav_entity_attribute.attribute_set_id=main_table.attribute_set_id', 'attribute_id');
他のヒント
@mageuzが完璧な答えを書く直前にこれを見つけました。属性セットIDのみが必要な場合は高速です。多分他の誰かがそれを必要としています。
$attributeId = 123;
$setInfo = Mage::getResourceModel('eav/entity_attribute_set')
->getSetInfo(array($attributeId));
$attributeSetIds = array_keys($setInfo[$attributeId]);
Magentoオブジェクトでそれを行う方法がわかりませんが、直接クエリも機能します
SELECT `eav_entity_attribute`.`attribute_set_id`
FROM `eav_attribute` , `eav_entity_attribute`
WHERE `eav_attribute`.`attribute_code` = 'cost'
AND `eav_attribute`.`attribute_id` = `eav_entity_attribute`.`attribute_id`
以下のコードを使用して、特定の属性セットのすべての属性を取得できます。
$data = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter(9) // Add attribute set ID
->load();
所属していません magento.stackexchange