3

I need to display a products attribute if the product price is equal to 0 on a category page on Magento, similar to this post but using price to then display an attribute: https://stackoverflow.com/questions/28489186/magento-if-attribute-value-is-x-or-y-then-show-custom-block

1
  • Ok, so I have made a little progress, but still need to get this code to then display a products attribute: <div class="price-box"> <?php if ($_product->getFinalPrice() == 0) : ?> <p>Free from <span style="color:green;">ATRRIBUTE TO DISPLAY HERE</span> per month</p> <?php else: ?> <?php echo $this->getPriceHtml($_product, true) ?> <?php endif; ?> </div> Commented Sep 11, 2015 at 13:09

2 Answers 2

2

Try out this code in list.phtml:

 <?php 

echo $price = number_format($_product->getPrice(), '2', '.', ',');
 if($price ==0)
 {
   $_product->getYourAttribute();
 } 
 ?>
4
  • I think you haven't quite got what I am trying to achieve. Commented Sep 11, 2015 at 13:08
  • @MathewPorter I have updated answer please check it.
    – Arunendra
    Commented Sep 11, 2015 at 13:14
  • @have you tried this one ??
    – Arunendra
    Commented Sep 11, 2015 at 13:15
  • Thats just essentially displaying the price if the price == 0. I need to display the attribute if the products price is == 0 Commented Sep 11, 2015 at 13:27
1

Try following assuming your attribute code is "abc_xyz" and attribute name is "attributename"

<div class="price-box">
<?php if ($_product->getFinalPrice() == 0) : ?> 
        <p>Free from <span style="color:green;"><?php echo $_helper->productAttribute($_product, $_product->getAbcXyz(), 'attributename') ?></span> per month</p> 
    <?php else: ?> 
        <?php echo $this->getPriceHtml($_product, true) ?> 
<?php endif; ?> 
</div> 
2
  • Still not quite there, I think the issue is with the fact that I need the following: Show the lowest $tariff_price (attribute that is a text field) that the bundle product price is = 0 at. $childProductIds = $_product->getTypeInstance(true)- >getChildrenIds($product->getId(), false); $TariffPrice = null; foreach ($childProductIds as $childProductId) { $product = Mage::getModel('catalog/product')->load($childProductId); if ($TariffPrice === null || $product->getPrice() < $TariffPrice) { $TariffPrice = $product->getPrice(); } } echo $TariffPrice; Commented Sep 11, 2015 at 14:32
  • The above is what I have just tried (it doesn't work anyway), but looking at it I dont think it would quite do what I am trying to achieve anyway. Commented Sep 11, 2015 at 14:37

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.