php - Magento 如何通过选项 ID 获取属性值?

标签 php magento

所以我有

$attribute_option_id = Mage::getResourceModel('catalog/product')
->getAttributeRawValue($productId, 'my_attribute', $storeId);

这给了我类似 $attribute_option_id = 12345

现在如何获取此 ID 的(文本)值?

谢谢

最佳答案

这应该有效。

$product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
$text = $product->getAttributeText('my_attribute');

[编辑]
如果你不想加载完整的产品,你可以偷偷摸摸地想一想。冒充产品。

因此您可以像以前一样获得选项 ID

$attribute_option_id = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'my_attribute', $storeId);

然后只创建一个产品的空实例并为其设置一些属性。

$product = Mage::getModel('catalog/product')
    ->setStoreId($storeId)
    ->setData('my_attribute', $attribute_option_id);//the result from above

$text = $product->getAttributeText('my_attribute');

已经确认这有效。 See it here .

关于php - Magento 如何通过选项 ID 获取属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22987787/

相关文章:

javascript - 在 javascript 中将数组映射到对象中的键

php - Doctrine 多级继承映射

php - 如何使用带有唯一 ID 的 insert_batch

magento - 在 magento 2 中 getModel 的正确方法是什么?

magento 网站迁移后 CSS 不加载

magento - 更改 Magento SKU 是否会影响订单历史记录

php - 传递可变大小的表单

php - 保留主页重定向,但将 http 更改为 https 全站(包括子域)

magento - Magento 管理面板中系统配置的空白屏幕

php - Magento - 购买可下载产品时删除账单和运输信息