Posted by: james | August 4, 2009

Overwrite between part of .phtml file or make new theme for using some between part of particular page in magento..

overrite in between part… create theme and also appy it.. I have created extension to overwrite the block of checkout in which all the product details are displayed…

app/etc/modules/New_TierPrice.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<New_TierPrice>
<active>true</active>
<codePool>local</codePool>
</New_TierPrice>
</modules>
</config>

now go to..
app/code/design/frontend/default/tierprice
and create two folder..

layout
template

now in layout
app/code/design/frontend/default/tierprice/layout/tierprice.xml

//here i use checkout.xml b’cos i need to use that

<?xml version=”1.0″ encoding=”UTF-8″?>
<layout version=”0.1.0″>
<checkout_cart_index> // here i need to overwrite this module
<reference name=”checkout.cart”> // here in name give name of block..
<block type=”checkout/cart” name=”checkout.cart”>
<action method=”setCartTemplate”><value>checkout/cart.phtml</value></action>
<action method=”setEmptyTemplate”><value>checkout/cart/noItems.phtml</value></action>
<action method=”chooseTemplate”/>
<action method=”addItemRender”><type>simple</type><block>checkout/cart_item_renderer</block><template>tierprice/new.phtml</template></action>         //here give your file name with folder name and you must use folder for that.
<action method=”addItemRender”><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>tierprice/new.phtml</template></action>              <action method=”addItemRender”><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>tierprice/new.phtml</template></action>
<block type=”core/text_list” name=”checkout.cart.top_methods” as=”top_methods”>
<block type=”checkout/onepage_link” name=”checkout.cart.methods.onepage” template=”checkout/onepage/link.phtml”/>
</block>

<block type=”core/text_list” name=”checkout.cart.methods” as=”methods”>
<block type=”checkout/onepage_link” name=”checkout.cart.methods.onepage” template=”checkout/onepage/link.phtml”/>
<block type=”checkout/multishipping_link” name=”checkout.cart.methods.multishipping” template=”checkout/multishipping/link.phtml”/>
</block>

<block type=”checkout/cart_coupon” name=”checkout.cart.coupon” as=”coupon” template=”checkout/cart/coupon.phtml”/>
<block type=”checkout/cart_shipping” name=”checkout.cart.shipping” as=”shipping” template=”checkout/cart/shipping.phtml”/>
<block type=”checkout/cart_crosssell” name=”checkout.cart.crosssell” as=”crosssell” template=”checkout/cart/crosssell.phtml”/>

<block type=”checkout/cart_totals” name=”checkout.cart.totals” as=”totals” template=”checkout/cart/totals.phtml”/>
</block>
</reference>
</checkout_cart_index>
</layout>

nnow in template
app/code/design/frontend/default/tierprice/template/tierprice/new.phtml

<?php
?>
<?php $_item = $this->getItem()?>
<?php $_product = Mage::getModel(‘catalog/product’)->load($this->getProduct()->getId()); ?>
<?php $res = $this->getTierPrices($_product);?>
<tr>
<td><a href=”<?php echo $this->getDeleteUrl() ?>”><img src=”<?php echo $this->getSkinUrl(‘images/btn_trash.gif’) ?>” width=”16″ height=”16″ alt=”<?php $this->__(‘Remove item’)?>” /></a></td>
<td><a href=”<?php echo $this->getProductUrl() ?>”><img src=”<?php echo $this->getProductThumbnail()->resize(75); ?>” alt=”<?php echo $this->htmlEscape($this->getProductName()) ?>” width=”75″ /></a></td>
<td>
<h4><a href=”<?php echo $this->getProductUrl() ?>”><?php echo $this->getProductName() ?></a></h4>
<!– item custom options –>
<?php if ($_options = $this->getOptionList()):?>
<dl>
<?php foreach ($_options as $_option) : ?>
<?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
<dt><?php echo $this->htmlEscape($_option[‘label’]) ?></dt>
<dd<?php if (isset($_formatedOptionValue[‘full_view’])): ?><?php endif; ?>><?php echo $_formatedOptionValue[‘value’] ?>
<?php if (isset($_formatedOptionValue[‘full_view’])): ?>
<div>
<dl>
<dt><?php echo $this->htmlEscape($_option[‘label’]) ?></dt>
<dd><?php echo $_formatedOptionValue[‘full_view’] ?></dd>
</dl>
</div>
<?php endif; ?>
</dd>
<?php endforeach; ?>
</dl>
<?php endif;?>
<!– / –>

<?php if ($messages = $this->getMessages()): ?>
<?php foreach ($messages as $message): ?>
<div>
* <?php echo $message[‘text’] ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</td>
<?php if ($this->helper(‘wishlist’)->isAllowInCart()) : ?>
<td>
<input type=”checkbox” value=”1″ name=”cart[<?php echo $_item->getId() ?>][wishlist]” />
</td>
<?php endif ?>
<?php if ($this->helper(‘tax’)->displayCartPriceExclTax() || $this->helper(‘tax’)->displayCartBothPrices()): ?>
<td>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘eunit-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<?php else: ?>
<div>
<?php endif; ?>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(0, 1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
<?php else: ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_item->getCalculationPrice()) ?>
<?php endif; ?>

</div>

<?php if (Mage::helper(‘weee’)->getApplied($_item)): ?>
<div id=”eunit-item-tax-details<?php echo $_item->getId(); ?>” style=”display: none;”>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 1, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘amount’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><small><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘amount_incl_tax’],true,true); ?></small></span><br />
<?php endforeach; ?>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 4, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘amount_incl_tax’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php endif; ?>
</div>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘eunit-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<span><?php echo Mage::helper(‘weee’)->__(‘Total’); ?>:<br /> <?php echo $this->helper(‘checkout’)->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($this->helper(‘tax’)->displayCartPriceInclTax() || $this->helper(‘tax’)->displayCartBothPrices()): ?>
<td>
<?php $_incl = $this->helper(‘checkout’)->getPriceInclTax($_item); ?>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘unit-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<?php else: ?>
<div>
<?php endif; ?>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(0, 1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?>
<?php else: ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_incl-$_item->getWeeeTaxDisposition()) ?>
<?php endif; ?>

</div>
<?php if (Mage::helper(‘weee’)->getApplied($_item)): ?>

<div id=”unit-item-tax-details<?php echo $_item->getId(); ?>” style=”display: none;”>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 1, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘amount’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><small><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘amount_incl_tax’],true,true); ?></small></span><br />
<?php endforeach; ?>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 4, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘amount_incl_tax’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php endif; ?>
</div>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘unit-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<span><?php echo Mage::helper(‘weee’)->__(‘Total incl. tax’); ?>:<br /> <?php echo $this->helper(‘checkout’)->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
</td>
<?php endif; ?>
<td>
<input name=”cart[<?php echo $_item->getId() ?>][qty]” value=”<?php echo $this->getQty() ?>” size=”4″ maxlength=”8″ />
</td>
<?php if ($this->helper(‘tax’)->displayCartPriceExclTax() || $this->helper(‘tax’)->displayCartBothPrices()): ?>
<td>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘esubtotal-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<?php else: ?>
<div>
<?php endif; ?>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(0, 1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?>
<?php else: ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_item->getRowTotal()) ?>
<?php $qty = $this->getQty();?>
<?php   $temp = ”;

foreach ($res as $value)
{
if($qty >= $value[‘price_qty’])
{
$temp =  $value[‘savePercent’]. ‘%’;
}
}
echo $temp;
?>

<?php endif; ?>

</div>
<?php if (Mage::helper(‘weee’)->getApplied($_item)): ?>

<div id=”esubtotal-item-tax-details<?php echo $_item->getId(); ?>” style=”display: none;”>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 1, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘row_amount’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><small><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘row_amount_incl_tax’],true,true); ?></small></span><br />
<?php endforeach; ?>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 4, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘row_amount_incl_tax’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php endif; ?>
</div>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘esubtotal-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<span><?php echo Mage::helper(‘weee’)->__(‘Total’); ?>:<br /> <?php echo $this->helper(‘checkout’)->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($this->helper(‘tax’)->displayCartPriceInclTax() || $this->helper(‘tax’)->displayCartBothPrices()): ?>
<td>
<?php $_incl = $this->helper(‘checkout’)->getSubtotalInclTax($_item); ?>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘subtotal-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<?php else: ?>
<div>
<?php endif; ?>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, array(0, 1, 4), ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_incl+$_item->getWeeeTaxAppliedRowAmount()); ?>
<?php else: ?>
<?php echo $this->helper(‘checkout’)->formatPrice($_incl-$_item->getWeeeTaxRowDisposition()) ?>
<?php endif; ?>

</div>

<?php if (Mage::helper(‘weee’)->getApplied($_item)): ?>

<div id=”subtotal-item-tax-details<?php echo $_item->getId(); ?>” style=”display: none;”>
<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 1, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘row_amount’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><small><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘row_amount_incl_tax’],true,true); ?></small></span><br />
<?php endforeach; ?>
<?php elseif (Mage::helper(‘weee’)->typeOfDisplay($_item, 4, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<small>
<?php foreach (Mage::helper(‘weee’)->getApplied($_item) as $tax): ?>
<span><?php echo $tax[‘title’]; ?>: <?php echo Mage::helper(‘checkout’)->formatPrice($tax[‘row_amount_incl_tax’],true,true); ?></span><br />
<?php endforeach; ?>
</small>
<?php endif; ?>
</div>

<?php if (Mage::helper(‘weee’)->typeOfDisplay($_item, 2, ‘sales’) && $_item->getWeeeTaxAppliedAmount()): ?>
<div onclick=”taxToggle(‘subtotal-item-tax-details<?php echo $_item->getId(); ?>’, this, ‘cart-tax-total-expanded’);”>
<span><?php echo Mage::helper(‘weee’)->__(‘Total incl. tax’); ?>:<br /> <?php echo $this->helper(‘checkout’)->formatPrice($_incl+$_item->getWeeeTaxAppliedRowAmount()); ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>

// now here our desing part is complete and our theme is ready to apply it go to admin side and in system in design in theme give your folder name         as in my case tierprice. Now for coding part go to local folder.

app/code/local/New/TierPrice/etc/config.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<New_TierPrice>
<version>1.0</version>
</New_TierPrice>
</modules>
<global>
<models>
<tierprice>
<class>New_TierPrice_Model</class>
</tierprice>
</models>
<blocks>
<tierprice>
<class>New_TierPrice_Block</class>
</tierprice>
<checkout> // most important is this. here in this we want to use block file of core folder i mean to say to use default file but we can’t make any changes in that, so for that we have to create our new file and overwrite it with that so for that use <rewrite> and use block tag name and give our file name with block class , thus you can overwrite model and controller also..
<rewrite>
<cart_item_renderer>New_TierPrice_Block_New</cart_item_renderer>
</rewrite>
</checkout>
</blocks>
<helpers>
<tierprice>
<class>New_TierPrice_Helper</class>
</tierprice>
</helpers>
</global>
<frontend>
<routers>
<tierprice>
<use>standard</use>
<args>
<module>New_TierPrice</module>
<frontName>tierprice</frontName>
</args>
</tierprice>
</routers>
<layout>
<updates> // this is again imp.. in that we have to specify that which .xml file will take our module and for make our .phtml file to display use this tag..
<tierprice>
<file>tierprice.xml</file>
</tierprice>
</updates>
</layout>
</frontend>
</config>

Now go to.. app/code/local/New/TierPrice/Block/New.php and in that use extend class of our <rewrite> tag’s block fiile..
<?php
class New_TierPrice_Block_New extends Mage_Checkout_Block_Cart_Item_Renderer
{
public function getTierPrices($product = null)
{
if (is_null($product)) {
$product = $this->getProduct();
}
$prices  = $product->getFormatedTierPrice();

$res = array();
if (is_array($prices)) {
foreach ($prices as $price) {
$price[‘price_qty’] = $price[‘price_qty’]*1;

if ($product->getPrice() != $product->getFinalPrice()) {
$productPrice = $product->getFinalPrice();
} else {
$productPrice = $product->getPrice();
}

if ($price[‘price’]<$productPrice) {
$price[‘savePercent’] = ceil(100 – (( 100/$productPrice ) * $price[‘price’] ));
$price[‘formated_price’] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper(‘tax’)->getPrice($product, $price[‘website_price’])));
$price[‘formated_price_incl_tax’] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper(‘tax’)->getPrice($product, $price[‘website_price’], true)));

$res[] = $price;
}
}
}

return $res;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: