2014-12-10 9 views
5

Ho un problema molto strano, posso ottenere il valore dell'attributo del prodotto in locale, ma quando vado al server live, ottengo un valore vuoto. Magento versione 1.6.2.Come ottenere il valore di attributo del prodotto in magento

Per ottenere il valore di attributo, io uso questo codice:

$product = Mage::getModel('catalog/product')->load($_item->getProductId()); 
$my_attribute = $product->getAttributeText('my_attribute'); 

PHP 5.3 e Apache 2.2 sia sul server locale e in diretta

+0

Non c'è un bel po 'siamo in grado di raccontare il server prod ... –

+0

E' un Debian. Windows 7 locale wampserver – Ali

+0

Se qualcuno sa cosa può farlo funzionare su un server e non su un altro. Quando faccio un var_dump ($ product) non ottengo my_attribute sul server live ma lo prendo sul locale – Ali

risposta

28

provare queste cose:

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

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

O

$_id = $this->getProduct()->getId(); 
$_resource = Mage::getSingleton('catalog/product')->getResource(); 
$optionValue = $_resource->getAttributeRawValue($_id, [ATTRIBUTE_ID/ATTRIBUTE_CODE], Mage::app()->getStore()); 
echo $optionValue; 

O

$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product); 

Evviva :-)

+1

Grazie @ girish-sh, ho provato tutti questi. Ma quello che sembrava funzionare è 'if ($ this-> getItemOptions()): \t foreach ($ this-> getItemOptions ($) come opzione): \t \t if ($ l'opzione [ 'label'] == ' Il mio attributo '): \t \t \t $ taille = nl2br ($ option [' value ']); \t \t endif; \t endforeach; endif; 'E questo non funziona per me su locale – Ali

+0

Si verifica un errore dopo l'esecuzione di questo codice? –

+0

Nessun errore, e ottengo il valore corretto sul server live, ma su locale ottengo un valore vuoto. – Ali