Php – Magento get product special price not working on homepage

magentoPHP

I'm editing a premium magento template right now (Hellodisplay) which has a featured product section on it's homepage. That section works by calling a specific category defined in a static block. My problem with this section is I couldn't show the special price of the products in any way. Althought the special product showed up on the product detail page. It also runs normal on the default template.

I've tried both function getSpecialProduct and getFinalProduct. GetSpecialProduct return nothing and GetFinalProduct return the normal price. I've also tried to use default theme price child html (price.phtml). It also doesn't works.

Then I check the print_r() output of $_product variable both on the homepage and also on the product page.I noticed the differences. Special array value exist only on the product pages's $_product variable. So how can I make this special price value appear on the homepage too?

This is my featured.phtml code

<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>

<?php
$product_limit = 3;
$i = 1;
$_productCollection=$this->getLoadedProductCollection();
$cat_id = $this->category_id;

$_productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect(array('name', 'price', 'small_image', 'status'), 'inner')
    ->addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id));
?>

<?php if(!$_productCollection->count()): ?>
<div class="note-msg">
    <?php echo $this->__('There are no products matching the selection. Please provide a category ID.') ?>
</div>
<?php else: ?>

    <ul class="frontgrid">
        <?php $_collectionSize = $_productCollection->count() ?>
        <?php foreach ($_productCollection as $_product): ?>
            <?php if($i >= $product_limit+1){
                break; 
            } else{
                $a = $i % 3;
                $i++; 
            } ?>
            <li class="<?php echo "col".$a; ?>">
                <a class="imglink" href="<?php echo $_product->getProductUrl() ?>">
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200, 200); ?>" width="200" height="200" alt="<?php echo $this->htmlEscape($_product->getName()); ?>" />
                </a>
                <h4><?php echo $this->htmlEscape($_product->getName()); ?></h4>
                <div class="boxbar">
                <span class="oldprice">
                    <?php if($this->htmlEscape($_product->getSpecialPrice())){ ?>
                        &euro; <?php echo number_format($this->htmlEscape($_product->getPrice()), 2) ?>
                    <? } ?>
                </span>
                <span class="price">

                    <?php if($this->htmlEscape($_product->getSpecialPrice())){ ?>
                        &euro; <?php echo number_format($this->htmlEscape($_product->getSpecialPrice()), 2) ?><br/>
                    <? } else { ?>
                        &euro; <?php echo number_format($this->htmlEscape($_product->getPrice()), 2) ?>
                    <? } ?>

                </span>
                <a class="moreinfo" href="<?php echo $_product->getProductUrl() ?>">Meer Info &raquo;</a>
                </div>
            </li>
        <?php endforeach ?>
    </ul>

<?php endif; ?>

Thanks before 🙂

Best Answer

You have to add "special_price", "special_from_date" and "special_to_date" on addAttributeToSelect array.

Related Topic