2017-05-23 47 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);