This could be the problem:
<img src="../images/sale-icon.png" width="101" height="58" class="onsaleicon" />
When you are not on homepage the relative path to the image is wrong.
Use this instead:
<img src="<?php echo $this->getSkinUrl('images/sale-icon.png')?>" width="101" height="58" class="onsaleicon" />
and place your image in skin/frontend/{interface}/{theme}/images/
.
Small tip:
Don't use this:
$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();
You are loading the product 3 times and you don't need to do that. You can load it only once if neccesary:
$mainProduct = Mage::getModel('catalog/product')->load($_product->getId());
$specialprice = $mainProduct->getSpecialPrice();
// Get the Special Price FROM date
$specialPriceFromDate = $mainProduct->getSpecialFromDate();
// Get the Special Price TO date
$specialPriceToDate = $mainProduct->getSpecialToDate();
but you can go without loading it, by editing the attributes 'special_price', 'special_from_date' and
special_to_date` and setting
used in product listingto
yes`.
bigger tip:
You can check if the product has a discount without checking the special price and the dates. This works even if you have a discount from a catalog rule:
if ($_product->getPrice() > $_product->getFinalPrice())
Using the handles: catalog_category_default, catalog_category_layered and catalogsearch_result_index you should be able to change the template of the products list.
For the two category layout handles you would need the following snippet.
<catalog_category_default>
<reference name="product_list">
<action method="setTemplate">
<template>MyModule/Availability/catalog/product/list.phtml</template>
</action>
</reference>
</catalog_category_default>
<catalog_category_layered>
<reference name="product_list">
<action method="setTemplate">
<template>MyModule/Availability/catalog/product/list.phtml</template>
</action>
</reference>
</catalog_category_layered>
But for the search results page you would need to make a slight change as the block is not called product_list but search_result_list:
<catalogsearch_result_index>
<reference name="search_result_list">
<action method="setTemplate">
<template>MyModule/Availability/catalog/product/list.phtml</template>
</action>
</reference>
</catalogsearch_result_index>
Best Answer
To modify product price using custom logic you can rewrite getFinalPrice from the class
Mage_Catalog_Model_Product
.You can find example how to extend magento core class using, for example, this tutorial http://inchoo.net/ecommerce/magento/how_to_override_magento_model_classes/