Magento仅获取特定商店的制造商标签
我试图只为一个特定的商店获得制造商标签,但它不起作用,我总是得到所有商店的所有制造商。有什么想法吗?这是我的密码:Magento仅获取特定商店的制造商标签,magento,Magento,我试图只为一个特定的商店获得制造商标签,但它不起作用,我总是得到所有商店的所有制造商。有什么想法吗?这是我的密码: $entityTypeIdentifier = 'catalog_product'; $attributeCode = 'manufacturer'; $storeId = 2; $attributeModel = Mage::getModel('eav/entity_attribute'); $attributeId = $at
$entityTypeIdentifier = 'catalog_product';
$attributeCode = 'manufacturer';
$storeId = 2;
$attributeModel = Mage::getModel('eav/entity_attribute');
$attributeId =
$attributeModel->getIdByCode($entityTypeIdentifier,$attributeCode);
$attribute = $attributeModel->load($attributeId);
$attribute->setStoreId( $storeId );
$attributeOptionsModel = Mage::getModel('eav/entity_attribute_source_table');
$attributeTable = $attributeOptionsModel->setAttribute($attribute);
$options = $attributeOptionsModel->getAllOptions(false);
echo '<pre>';
print_r($options);
这是eav_属性_选项_值表:
值\u id
选项\u id
商店标识
价值观
1263
204
0
3M ESPAñA
1264
204
1.
3M ESPAñA在Mage_Eav_Model_Entity_Attribute_Source_Table类的getAllOptions函数中,无论选项是否具有存储特定值,都将返回该选项的值 例如,如果一个属性有100个选项,而store 2有20个选项的值,则无论是否设置StoreID2,option model都将返回100个选项。若您设置了存储id,模型将在存储2值中返回其中20个选项,在默认值中返回其他80个选项 但如果你只需要回答这20个值,那么你就是我的朋友:
我想你是想甩掉只在商店2使用的制造商。Magento将始终转储选项的值,无论其是否具有存储特定的值。如果商店ID 0和1上的选项204有3M ESPAñA值,则Magento将商店2的商店0值作为默认值返回。哇!这正是我需要的,它就像一个符咒:
Array
(
[0] => Array
(
[value] => 204
[label] => 3M ESPAÑA
)
.
.
.
$entityTypeIdentifier = 'catalog_product';
$attributeCode = 'manufacturer';
$storeId = 2;
$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('read');
$query = $connection->select()
->from(array('e' => $resource->getTableName('eav/attribute')), array())
->joinLeft(array(
'f' => $resource->getTableName('eav/entity_type')),
"e.entity_type_id = f.entity_type_id AND f.entity_type_code = '$entityTypeIdentifier'",
array()
)
->joinLeft(array(
'g' => $resource->getTableName('eav/attribute_option')),
'e.attribute_id = g.attribute_id',
array()
)
->joinRight(
array('h' => $resource->getTableName('eav/attribute_option_value')),
"g.option_id = h.option_id AND h.store_id = $storeId",
array('h.option_id', 'h.value')
)
->where('e.attribute_code = ?', $attributeCode);
$options = $connection->fetchAssoc($query);
echo '<pre>';
print_r($options);