Reputation: 59
Display Sale icon on special price products in magento. Only at homepage it is showing not in all pages.
Code I have edited in
app/design/frontend/default/template/catalog/product/list.html
from the line number: 95
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"` class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php
// Get the Special Price
$specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
// Get the Special Price FROM date
$specialPriceFromDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate();
// Get the Special Price TO date
$specialPriceToDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate();
// Get Current date
$today = time();
if ($specialprice):
if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)):
?>
<img src="../images/sale-icon.png" width="101" height="58" class="onsaleicon" />
<?php
endif;
endif;
?>
</a>
This icon is displaying in homepage only not in All product list of pages. How do i display in all pages?
Please help me out of this
Upvotes: 2
Views: 7392
Reputation: 15206
This is because you insert the image like this:
<img src="../images/sale-icon.png" width="101" height="58" class="onsaleicon" />
The image should be placed in skin/frontend/{interface}/{theme}/images/
and you should reference it this way:
<img src="<?php echo $this->getSkinUrl('images/sale-icon.png');?>" width="101" height="58" class="onsaleicon" />
[EDIT]
A bit off topic, but good to know: Don't use Mage::getModel('catalog/product')->load($_product->getId())
for each product attribute you need. It slows down the page more than you think. Just edit the attributes you need (special price, special price from and special price to) in the backend set the field Used in product listing
to Yes
, reindex everything and you should be able to use directly:
$specialprice = $_product->getSpecialPrice();
$specialPriceFromDate = $_product->getSpecialFromDate();
$specialPriceToDate = $_product->getSpecialToDate();
Upvotes: 3