Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Customizing Price.phtml getting error in category pages, but works in product pages…HELP! 
 
Danielc1234
Sr. Member
 
Avatar
Total Posts:  175
Joined:  2008-01-09
Miami, FL - United States
 

I am doing a customization on my price.phtml for my product pages and my category pages.

I made an attribute in my products called ‘retail_price’ which is just a number we are using to represent the suggested retail price of an item. Then I do some math functions to have some special stuff (you save $ thismuch, percentage saved, etc)

The problem I am having is...it is working fine on my product pages, but when you go to a category page, I am getting errors. - Undefined index ‘retail_price’ (which is the attribute that I added.)

I have included the code below so hopefully someone could take a quick look at it and see what I’m doing wrong.
I would really appreciate it.

the code between the ***** is the code I added in the price.phtml file.

*************************

<span class="retail-price-label">Price: </span><span class="retail-price">$<?php echo nl2br($_product->_data['retail_price']?></span><br />
<?php $sum_total=$_product->_data['retail_price']-$_product->_data['price'] ?> 
<?php $sum_percent
=($sum_total/$_product->_data['retail_price'])* 100 ?>
<span class="you-save">You Save$<?php print($sum_total?></span> - <span class="you-save-percent">(<?php print($sum_percent?> off!)</span>
<
class="always-free-shipping">Always Free Shipping!</p>

********************************

All the code listed below is the price.phtml file

<?php $_product $this->getProduct() ?>
<?php 
if (!$_product->isGrouped()): ?>
<div class="price-box">
<?php $_id $_product->getId() ?>
<?php $_showTax 
$_product->getShowTaxInCatalog() ?>
<?php $_priceAfterTax 
$_product->getPriceAfterTax() ?>
<?php $_finalPriceAfterTax 
$_product->getFinalPriceAfterTax() ?>
<?php $_price 
$_showTax==$_priceAfterTax $_product->getPrice() ?>
<?php $_finalPrice 
$_showTax==$_finalPriceAfterTax $_product->getFinalPrice() ?>

<span class="retail-price-label">Price: </span><span class="retail-price">$<?php echo nl2br($_product->_data['retail_price']?></span><br />

<?php if ($_finalPrice == $_price): ?>
    
<span class="regular-price-label"><?php echo $this->__('Sale Price: '?></span> <span class="regular-price" id="product-price-<?php echo $_id ?>">
        
<?php echo Mage::helper('core')->currency($_price?>
    
</span>
    <
br/>
<?php else: ?>
    
<span class="old-price">
        <
span class="label"><?php echo $this->__('Regular Price:'?></span>
        <
span class="price" id="old-price-<?php echo $_id ?>">
            
<?php echo Mage::helper('core')->currency($_price?>
        
</span>
    </
span>
    <
br/>
    <
span class="special-price">
        <
span class="label"><?php echo $this->__('Special Price:'?></span>
        <
span class="price" id="product-price-<?php echo $_id ?>">
            
<?php echo Mage::helper('core')->currency($_finalPrice?>
        
</span>
    </
span>
    <
br/>
<?php endif ?>

<?php $sum_total
=$_product->_data['retail_price']-$_product->_data['price'] ?> 
<?php $sum_percent
=($sum_total/$_product->_data['retail_price'])* 100 ?>
<span class="you-save">You Save$<?php print($sum_total?></span> - <span class="you-save-percent">(<?php print($sum_percent?> off!)</span>
<
class="always-free-shipping">Always Free Shipping!</p>
<?php if ($_showTax==2): ?>
    
<span class="price-after-tax">
        <
span class="label"><?php echo $this->__('Including Tax:'?></span>
        <
span class="regular-price" id="price-after-tax-<?php echo $_id ?>">
            
<?php echo Mage::helper('core')->currency($_finalPriceAfterTax?>
        
</span>
    </
span>
    <
br/>
<?php endif ?>

</div>
<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top