2017-05-23 44 views
0

我有一个观察者,运行在catalog_product_save_after。我正在检查某些属性是否发生了变化。这很容易做到这一点;Magento获取产品原始数据 - 选择属性文本没有ID

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

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

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

现在我需要获取select属性的产品原始文本值(不是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. 

是否有实现这一目标的一个简单的方法还是我需要使用INT使用getOrigData来查找文本值时返回?

回答

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);