Hello there,
I made a custom attribute called 'baseprice' which I want to show below the normal product price in the price_info box that also holds the taxt information.
Those information are rendered in the 'frontend/base/default/template/magesetup/price_info.phtml'
This is the content of the file:
<?php
/**
* This file is part of a FireGento e.V. module.
*
* This FireGento e.V. module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* @category FireGento
* @package FireGento_MageSetup
* @author FireGento Team <team@firegento.com>
* @copyright 2013-2015 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
?>
<?php
/**
* @var $this FireGento_MageSetup_Block_Catalog_Product_Price
*/
?>
<?php $shippingCostUrl = Mage::helper( 'magesetup' )->getShippingCostUrl() ?>
<?php if( !empty( $shippingCostUrl ) && $this->getIsShowShippingLink() ): ?>
<?php if( $this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX ): ?>
<?php if( $this->getIsIncludingShippingCosts() ): ?>
<span class="tax-details"><?php echo $this->__( 'Excl. %s Tax', $this->getFormattedTaxRate() ) ?><span class="tax-separator">, </span><span class="shipping-cost-details"><?php echo $this->__( 'incl. <a href="%s">Shipping Cost</a>', $shippingCostUrl ) ?></span></span>
<?php else: ?>
<span class="tax-details"><?php echo $this->__( 'Excl. %s Tax', $this->getFormattedTaxRate() ) ?><span class="tax-separator">, </span><span class="shipping-cost-details"><?php echo $this->__( 'excl. <a href="%s">Shipping Cost</a>', $shippingCostUrl ) ?></span></span>
<?php endif ?>
<?php elseif( $this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX ): ?>
<?php if( $this->getIsIncludingShippingCosts() ): ?>
<span class="tax-details"><?php echo $this->__( 'Incl. %s Tax', $this->getFormattedTaxRate() ) ?><span class="tax-separator">, </span><span class="shipping-cost-details"><?php echo $this->__( 'incl. <a href="%s">Shipping Cost</a>', $shippingCostUrl ) ?></span></span>
<?php else: ?>
<span class="tax-details"><?php echo $this->__( 'Incl. %s Tax', $this->getFormattedTaxRate() ) ?><span class="tax-separator">, </span><span class="shipping-cost-details"><?php echo $this->__( 'excl. <a href="%s">Shipping Cost</a>', $shippingCostUrl ) ?></span></span>
<?php endif ?>
<?php elseif( $this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH ): ?>
<?php if( $this->getIsIncludingShippingCosts() ): ?>
<span class="tax-details"><?php echo $this->__('incl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
<?php else: ?>
<span class="tax-details"><?php echo $this->__('excl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
<?php endif ?>
<?php endif ?>
<?php if ($this->getIsShowWeightInfo()): ?>
(<?php echo $this->__('Shipping Weight %s', $this->getFormattedWeight()) ?>)
<?php endif ?>
<?php else: ?>
<?php if( $this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX ): ?>
<span class="tax-details"><?php echo $this->__( 'Excl. %s Tax', $this->getFormattedTaxRate() ) ?></span>
<?php elseif( $this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX ): ?>
<span class="tax-details"><?php echo $this->__( 'Incl. %s Tax', $this->getFormattedTaxRate() ) ?></span>
<?php endif ?>
<?php endif ?>
I noticed that if I want to show the information at the place I want to show them add, I have to add it after the 'tax-detail' lines (one of them marked in bold above).
Unfortunately I have not much experience working with php. I know that I have to get my attribute 'baseprice' for the current product and just show it there. The problem is, that I was not successful in getting the attribute and printing it. Whatever I tried, I got an error and the page stopped rendering at the price_info box.
I know it is not a hard problem, I just don't know what information I already have and how to do it exactly.
Hopefully someone can help me out here.
Thanks!
Solved! Go to Solution.
I don't know how your extension is working and what $this returns.
But I think this will be help full to you.
Try solution and add this code to your place:
1)
$id = Mage::registry('current_product')->getId();
$baseprice = Mage::getModel('catalog/product')->load($id)->getBaseprice();
OR
2)
$id = $this->getProduct()->getId();
$baseprice = Mage::getModel('catalog/product')->load($id)->getBasepricce();
I don't know how your extension is working and what $this returns.
But I think this will be help full to you.
Try solution and add this code to your place:
1)
$id = Mage::registry('current_product')->getId();
$baseprice = Mage::getModel('catalog/product')->load($id)->getBaseprice();
OR
2)
$id = $this->getProduct()->getId();
$baseprice = Mage::getModel('catalog/product')->load($id)->getBasepricce();
Hello, I tried your edits and was able to display my baseprice attribute in the product page. A new problem I encountered was that after my edits the catalogue wasn't displayed correctly anymore. I think the reason is that the price_info block wasn't being displayed anymore. It might have to do with the theme I am using. I have to take a look at it this. Thanks for the advice, you were still able to help me.
To display your custom attribute 'baseprice' below the normal product price in the price_info box, you can modify the price_info.phtml template file as follows:
<?php
/**
* This file is part of a FireGento e.V. module.
*
* This FireGento e.V. module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* @category FireGento
* @package FireGento_MageSetup
* @author FireGento Team <team@firegento.com>
* @copyright 2013-2015 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
?>
<?php
/**
* @var $this FireGento_MageSetup_Block_Catalog_Product_Price
*/
?>
<?php $shippingCostUrl = Mage::helper('magesetup')->getShippingCostUrl() ?>
<?php if (!empty($shippingCostUrl) && $this->getIsShowShippingLink()): ?>
<?php if ($this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX): ?>
<?php if ($this->getIsIncludingShippingCosts()): ?>
<span class="tax-details"><?php echo $this->__('Excl. %s Tax', $this->getFormattedTaxRate()) ?>
<span class="tax-separator">, </span><span
class="shipping-cost-details"><?php echo $this->__('incl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
</span>
<?php else: ?>
<span class="tax-details"><?php echo $this->__('Excl. %s Tax', $this->getFormattedTaxRate()) ?>
<span class="tax-separator">, </span><span
class="shipping-cost-details"><?php echo $this->__('excl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
</span>
<?php endif ?>
<?php elseif ($this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX): ?>
<?php if ($this->getIsIncludingShippingCosts()): ?>
<span class="tax-details"><?php echo $this->__('Incl. %s Tax', $this->getFormattedTaxRate()) ?>
<span class="tax-separator">, </span><span
class="shipping-cost-details"><?php echo $this->__('incl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
</span>
<?php else: ?>
<span class="tax-details"><?php echo $this->__('Incl. %s Tax', $this->getFormattedTaxRate()) ?>
<span class="tax-separator">, </span><span
class="shipping-cost-details"><?php echo $this->__('excl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
</span>
<?php endif ?>
<?php elseif ($this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH): ?>
<?php if ($this->getIsIncludingShippingCosts()): ?>
<span class="tax-details"><?php echo $this->__('incl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
<?php else: ?>
<span class="tax-details"><?php echo $this->__('excl. <a href="%s">Shipping Cost</a>', $shippingCostUrl) ?></span>
<?php endif ?>
<?php endif ?>
<?php if ($this->getIsShowWeightInfo()): ?>
(<?php echo $this->__('Shipping Weight %s', $this->getFormattedWeight()) ?>)
<?php endif ?>
<!-- Add the baseprice attribute here -->
<?php $product = $this->getProduct(); ?>
<?php if ($product->getBaseprice()): ?>
<div class="baseprice">
<?php echo $this->__('Base Price: %s', $product->getBaseprice()) ?>
</div>
<?php endif ?>
<?php else: ?>
<?php if ($this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX): ?>
<span class="tax-details"><?php echo $this->__('Excl. %s Tax', $this->getFormattedTaxRate()) ?></span>
<?php elseif ($this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX): ?>
<span class="tax-details"><?php echo $this->__('Incl. %s Tax', $this->getFormattedTaxRate()) ?></span>
<?php endif ?>
<?php endif ?>In the modified template file, I added the following code right below the line <?php if ($this->getIsShowWeightInfo()): ?>:
<!-- Add the baseprice attribute here -->
<?php $product = $this->getProduct(); ?>
<?php if ($product->getBaseprice()): ?>
<div class="baseprice">
<?php echo $this->__('Base Price: %s', $product->getBaseprice()) ?>
</div>
<?php endif ?>This code retrieves the current product object using $this->getProduct() and checks if the 'baseprice' attribute has a value using $product->getBaseprice(). If the attribute has a value, it will be displayed below the normal product price in a <div> with the class baseprice. The value is displayed using the echo $this->__() method, which allows for translation if needed.
Make sure you have defined the 'baseprice' attribute correctly in your Magento lifeboostnutrition setup, and that it has values assigned to the relevant products.