Magento获取产品原始数据 - 选择属性文本不是ID

时间:2017-05-23 01:50:45

标签: magento

我有一个在 catalog_product_save_after 运行的观察者。我正在检查某些属性是否已更改。这很容易做到这一点;

$_product = Mage::registry('current_product');

$old = $_product->getOrigData('text_attribute');
$new = $_product->getData('text_attribute');

if($new != $old){ 
    // text_attribute has changed... 
}

现在我需要获取选择属性的产品原始文本值(不是ID)。

我试过了;

echo $_product->getOrigData('select_attribute'); // outputs int like 8947, I need the text!
echo $_product->getOrigAttributeText('select_attribute'); // Didn't work but it was worth a try.

有没有一种简单的方法可以实现这一点,还是我需要使用 getOrigData 查找文本值时返回的int?

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此代码。

$oldText = Mage::getModel('eav/entity_attribute')
                ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'text_attribute')
                ->getFrontend()
                ->getOption($old);

$newText = Mage::getModel('eav/entity_attribute')
                ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'text_attribute')
                ->getFrontend()
                ->getOption($new);
相关问题