1

I have a table which show the associated products. Some of these products have special tier price (buy 10 and get 10% off). I want to display a sale image if a tier price is shown however i am not very experienced with php so i am struggling a bit.

I tried

    <td class="a-left">
        <?php if ($this->getCanShowProductPrice($_item)): ?>
        <?php echo $this->getPriceHtml($_item, true) ?>
        <br>
        <?php echo $this->getTierPriceHtml($_item)?> 
        <img src="/skin/frontend/base/default/images/low_price.png" alt="low price icon">
        <?php endif; ?>
    </td>

But that just show the icon on every product even without a tier price. So i figured i would need an IF statement to check if the product has a tier price and if true then display the image. So i tried this.

<td class="a-left">
                <?php if ($this->getCanShowProductPrice($_item)): ?>
                <?php echo $this->getPriceHtml($_item, true) ?>
                <br>
                <?php echo $this->getTierPriceHtml($_item)?> 
                <?php if ($this->getTierPriceHTML = True): ?>
                <img src="/skin/frontend/base/default/images/low_price.png" alt="low price icon"> <?php endif; ?>
                <?php endif; ?>
            </td>

But that just had exactly the same outcome (image displayed on all products). I am not sure what else to try so if you could help it would be brilliant.

Thanks!!!

  • where you do this code??? – Amit Bera Jul 18 '14 at 10:24
  • in grouped.phtml – Adam Allen Jul 18 '14 at 13:35
  • which magento version are you using? – MTM Jul 18 '14 at 14:00
  • Magento ver. 1.9.0.1 – Adam Allen Jul 18 '14 at 15:27
3

If $_item is a loaded product then use:

<?php if ( $_item->getTierPrice()): ?>
   <img src="<?php echo $this->getSkinUrl('images/low_price.png');?>" alt="low price icon">
<?php endif; ?>

and if $_item is not a fully loaded then use:

<?php 
   $_product =  $_item->getProduct(); 
   // OR
  // $_product = Mage::getModel('catalog/product')->load($_item->getProductId());
   // Use whichever works for you.
 if ( $_product->getTierPrice()): ?>
   <img src="<?php echo $this->getSkinUrl('images/low_price.png');?>" alt="low price icon">
<?php endif; ?>

also consider how the image url is obtained from skin folder.

  • it still just adding the image to all products in the table. instead of just the ones with tier prices – Adam Allen Jul 18 '14 at 13:50
  • is $_item a loaded product? – MTM Jul 18 '14 at 14:09
  • please check the updated answer – MTM Jul 18 '14 at 14:16

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.