On the product view page, we're displaying a dropdown of products that are available to the customer as a free gift for that particular product.

We're loading the collection so we can get these products using:-

<?php $productGift = Mage::getModel('catalog/product')->load($giftId); ?>

This is currently displaying the product name which we can get by:-

<?php echo $productGift->getName()?>

We've created a custom attribute to use instead of the product name, so we want to display this in the dropdown instead of the product name but we're unable to use _$item or $_product, it's not a custom attribute of the current product, it needs to get the custom attribute from all the products loaded by Mage::getModel('catalog/product')->load($giftId);.

I'm unsure how to fetch this data.

It would be something like:-

<select id="select_28" class="product-custom-option" title="" name="freeGiftId">
    <option value=""><?php echo $this->__('-- Please Select --')?></option>
    <?php foreach($freeGifts as $giftId): ?>
    <?php $productGift = Mage::getModel('catalog/product')->load($giftId); ?>
    <option value="<?php echo $productGift->getId()?>">                                         
        <?php if ($productGift->getAttributeText('free_eliquid_product_name'); ?>
        <?php echo $productGift->getAttributeText('free_eliquid_product_name');?>
        <?php else: ?>
        <?php echo $productGift->getName()?>
    <?php endforeach; ?>

(If free gift product has custom attribute set then display this otherwise display the product name). How can I get the custom attribute from $productGift? Thanks.

I've tried this...

<?php if ($productGift->getXyz()): ?>
    <?php echo $productGift->getXyz()?>
<?php else: ?>
    <?php echo $productGift->getName()?>

Should this be working? Because it doesn't...

1 Answer 1


You can directly access your custom attribue of product.

Mage::getResourceModel(‘catalog/product’)->getAttributeRawValue($product_id, $attribute_code, $store_id)

Or you can Directly use

<?php $productGift = Mage::getModel('catalog/product')->load($giftId); 

Suppose you want color attribute then $productGift->getColor();

  • I've tried that already, it broke the product view page in the front end. Please check my edit, this is an example of what I tried - should that be working?
    – zigojacko
    Commented Dec 13, 2013 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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