2016-07-29 4 views
0

Magento 1.9で属性の管理オプション(値)を取得したいと考えています。これまでのところ私はそれを行うことができた:属性の管理オプション(値)を取得するにはどうすればよいですか?

<?php 
define(CURRENT_STORE_ID, Mage::app()->getStore()->getStoreId()); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
// Display admin value of "attribute" 
echo $_product->getAttributeText('attribute'); 
Mage::app()->setCurrentStore(CURRENT_STORE_ID); 
// Still display admin value of "attribute" 
echo $_product->getAttributeText('attribute'); 
?> 

問題がある、私は私が必要な(つまり、値)管理者のオプションを取得した後に戻って「ノーマル」店舗への切り替え方法を見つけ出すことはできません。

編集:

<?php 
// Display the normal value of "attribute" 
echo $_product->getAttributeText('attribute'); 
define(CURRENT_STORE_ID, Mage::app()->getStore()->getStoreId()); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
// Still display the normal value "attribute" 
echo $_product->getAttributeText('attribute'); 
Mage::app()->setCurrentStore(CURRENT_STORE_ID); 
// Still display the normal value "attribute" 
echo $_product->getAttributeText('attribute'); 
?> 

事前にありがとうございます。

答えて

1

アプリエミュレーションを試しましたか?

// Switch to Admin Store 
$appEmulation = Mage::getSingleton('core/app_emulation'); 
$adminEnvironmentEmulation = $appEmulation->startEnvironmentEmulation(Mage_Core_Model_App::ADMIN_STORE_ID); 
echo $_product->getAttributeText('attribute'); 
$appEmulation->stopEnvironmentEmulation($adminEnvironmentEmulation); 

// Switch back to previous store 
echo $_product->getAttributeText('attribute'); 
+0

私はしませんでした。私はちょうどアプリケーションのエミュレーションを使ってみましたが、私はまだ 'echo'の管理者の値を取得しています。とにかくお返事ありがとう! – louisfischer

+0

管理ストアに切り替える前に、まず属性の値を 'echo'すると、別の値になりますか? – nano

+0

私がエコー$ _product-> getAttributeText( '属性'); '何かをストアまたはアプリケーションのエミュレーションに切り替える前に、私はすべての' echo $ _product-> getAttributeText( 'attribute'); 'に対して通常の値を取得しています。奇妙な、それじゃない? – louisfischer

関連する問題