Hello i am working on my Magento 1.9 checkout (order review) and i want to display the attribute "color" only if the product bought is a t-shirt but not if its something else... Here is the code i use until now - its without the category check:

<?php $_item = $this->getItem() ?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo 'Artikelnummer: '.$_product->getResource()->getAttribute('COLOR')->getFrontend()->getValue($_product).'<br>'; ?>

But i have problems with the category check, my first approach was to set the category-ids and then check for them, if they match then display the attribute:

$CategoryIds = array(3,4);
$productCategory = $_product->getAvailableInCategories();
if (count(array_intersect($CategoryIds,$productCategory))) {
        $_item = $this->getItem();
$_product= Mage::getSingleton('catalog/product')->load($_item->getProductId());
echo 'Artikelnummer: '.$_product->getResource()->getAttribute('COLOR')->getFrontend()->getValue($_product).'<br>';

The problem is, that this code doesn't work - it just woun't load the last checkout step.

If someone could help me, i would be very thankfull!

Thanks, Daniel


here is simple solution for that

<?php $_item = $this->getItem() ?>
$CategoryIds = array(3,4);
$_product= Mage::getModel('catalog/product')->load($_item->getProductId());
$cats = $_product->getCategoryIds();
foreach($cats as $cat)
   if (in_array($cat,$CategoryIds))
<?php echo 'Artikelnummer: '.$_product->getResource()->getAttribute('COLOR')->getFrontend()->getValue($_product).'<br>'; ?>
<?php endif; ?>
  • Thank you for the solution - it works with a minor improvemet -> I think there should be a "=true" behind the "if($showcolor):" – Daniel Jan 23 '17 at 11:42
  • @Daniel if($showcolor): this condition by default mean $showcolor==true – Qaisar Satti Jan 23 '17 at 11:45
  • I tried to add a product that isnt in category 3 / 4, then there is no attribute (color) being showed however its showing the "Artikelnummer:" text... This is with the "=true" ---- If i do it like you said it (without the =true), there will be nothing displayed even if its in the category... – Daniel Jan 23 '17 at 11:48
  • @Daniel updated code and tested too – Qaisar Satti Jan 23 '17 at 12:03
  • 1
    Thank you very, very much! I tried it and it works - i will do it with some other attributes, if something wount work, i will write you here, but for now the code is working. Thank you, have a nice day! :) – Daniel Jan 23 '17 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.