Override Product Price Template In Magento - magento

I'm trying to hide the price for all products in Magento for both the Product and Grid page. I created a custom module to update the layout, the config.xml is as follows:
<config>
<modules>
<ABC_XYZ>
<version>1.0</version>
</ABC_XYZ>
</modules>
<frontend>
<layout>
<updates>
<killprice>
<file>killprice.xml</file>
</killprice>
</updates>
</layout>
</frontend>
</config>
I added the killprice.xml as follows:
<layout>
<default>
<block type="catalog/product_price_template" name="catalog_product_price_template" template="killprice/price.phtml" />
</default>
<killprice_index_index>
<block type="catalog/product_price_template" name="catalog_product_price_template" template="killprice/price.phtml" />
</killprice_index_index>
</layout>
But the killprice/price.phtml is not being rendered and I get the normal price template. I am a bit suspicious about the tags in killprice.xml layout file, am I overriding the price template the right way?

This should be what you are looking for…
<layout>
<default>
<reference name="catalog_product_price_template">
<action method="addPriceBlockType"><type>simple</type><block>catalog/product_price</block><template>killerprice/price.phtml</template></action>
<!-- duplicate for each product type you need to handle i.e. change the value of the <type> node" -->
</reference>
</default>
</layout>
Have a look in Mage_Catalog_Block_Product_Abstract to see why this works

Related

How to remove tabs from customer edit page in Magento backend?

In magento, by default 11 tabs are displayed in the customer edit page in the back end. How can I remove tabs from the default list of tabs. What I have done so far:
Created a class to override Mage_Adminhtml_Block_Customer_Edit_Tabs class and then overrode the _beforeToHtml() method.
tried to remove the tabs using
$this->removeTab('addresses');
Removing Customer tabs
a) You have to override Mage_Adminhtml_Block_Customer_Edit_Tabs because the Magento guys did a small typo there: they are adding tabs in _beforeToHtml() method instead of _prepareLayout(). So first you have to modify your config.xml and add:
<global>
<blocks>
<adminhtml>
<rewrite>
<customer_edit_tabs>Yourmodule_Customer_Block_Edit_Tabs</customer_edit_tabs>
</rewrite>
</adminhtml>
</blocks>
</global>
In Yourmodule_Customer_Block_Edit_Tabs just copy and paste the Mage_Adminhtml_Block_Customer_Edit_Tabs contents (don’t forget to change the class name!), and rename _beforeToHtml() method to _prepareLayout()
b) Add the removeTab action into your layout xml (default: customer.xml):
<adminhtml_customer_edit>
<reference name="left">
<block type="adminhtml/customer_edit_tabs" name="customer_edit_tabs">
<action method="removeTab">
<name>NAME_OF_TAB</name>
</action>
</block>
</reference>
</adminhtml_customer_edit>
You can find out the NAME_OF_TAB, by inspecting the tab’s anchor () and looking for the “name” attribute.

how to remove categories from left column in customer account page in magento?

I don't want to show categories in left column in customer account page.I have tried but didnot find the solution to solve this problem.I want any condition to remove categories only from customer acoount page.
If anyone have any idea,please help me.
Thanks!
You can do this by xml
create a local.xml under app/design/frontend/youpackage/youtemplate/layout/
if you left panel category alias name is "alias_name_of_left" then you can do this by
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="left">
<action method="unsetChild"><name>alias_name_of_left</name></action>
</reference>
</default>
</layout>
More Details at http://magentist.com/magento_help/remove-sidebar-blocks-with-layout-update-xml/
In you local.xml file of your theme add as follow,
Path: app/design/frontend/default/mytheme/layout/local.xml
<customer_account handle is used for only customer account pages
<layout>
<customer_account translate="label">
<reference name="left">
<remove name="catalog.leftnav"/>
</reference>
</customer_account>
</layout>
Flush caches and check.
You can remove block form customer.xml also for that first off all copy xml into you current theme. I have define the path.
Path: app/design/frontend/default/mytheme/layout/customer.xml
Under customer_account handle.
<customer_account translate="label">
<reference name="left">
<remove name="catalog.leftnav"/>
</reference>
</customer_account>

Magento block per action

I am trying to create a custom collection page with pagination. I have created the code for the pagination in the block and can output it in the template.
However the module that I am creating has pages that have other templates with no pagination.
How it works: User goes to index.php/styles/choose/items and selects the attributes/categories of the products he wants to display. He clicks on submit and is redirected to index.php/styles/choose/products where he can see the products and pagination.
In my styles.xml I have
<styles_choose_items>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="styles/styles" name="styles" template="styles/styles.phtml"/>
</reference>
</styles_choose_items>
<styles_choose_products>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="styles/products" name="products" template="styles/products.phtml"/>
</reference>
</styles_choose_products>
In config.xml I have :
<blocks>
<styles>
<rewrite>
<styles>Nuvo_Styles_Block_Styles</styles>
</rewrite>
<rewrite>
<products>Nuvo_Styles_Block_Products</products>
</rewrite>
</styles>
</blocks>
In the controller :
public function itemsAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function productsAction()
{
$this->loadLayout();
$this->renderLayout();
}
I would really like to know what I am doing wrong. The index.php/styles/choose/items page displays correctly, however the index.php/styles/choose/products show only the template and if I try to add anything to the Products.php block it goes blank with no error.
Any help is appreciated.
Thank you!
Thank you for your feedback. I've enabled line 77 in index.php ini_set('display_errors', 1); to see the errors.
I was actually very close. There was just an error in the Products.php block file. It now works correctly.
the declaration of blocks in your config is wrong, you are not rewriting blocks, as far as I can tell. Try this:
<blocks>
<styles>
<class>Nuvo_Styles_Block</class>
</styles>
</blocks>
Also it would be useful to see Nuvo_Styles_Block_Products

Layout Cache Issue

I have a custom module I wrote that is pretty basic...it just adds a small block to the footer for tracking using Media Forge. The tag it adds is different depending on whether you're on a product view page or not. This worked GREAT....until I turned on caching. Now, if you flush the cache and load a product view page, you get the correct block for the product view page. If you then go to another page (home, for instance), it still uses the product view page's block. If I flush the cache and reload the home page, it's now using the right one, but if I go to a product page now, it's using the wrong one there. So it's definitely a cache issue, I just don't understand how I'm supposed to correct this problem.
I'll paste the contents of my files below. I look forward to any responses!
Layout XML file:
<layout version="0.1.0">
<!-- DEFAULT TAG -->
<default>
<reference name="footer">
<block type="core/template" name="mediaforge_footer" as="mediaforge_footer" template="tracking/mediaforge_default.phtml"/>
</reference>
</default>
<!-- PRODUCT VIEW PAGES -->
<catalog_product_view>
<reference name="mediaforge_footer">
<action method="setTemplate"><template>tracking/mediaforge_product.phtml</template></action>
</reference>
</catalog_product_view>
</layout>
config.xml for my custom module:
<config>
<modules>
<VPS_Tracking>
<version>0.1.0</version>
</VPS_Tracking>
</modules>
<frontend>
<layout>
<updates>
<vps_tracking>
<file>vps_tracking.xml</file>
</vps_tracking>
</updates>
</layout>
</frontend>
</config>
Added this to the end of footer.phtml:
<?php echo $this->getChildHtml('mediaforge_footer'); ?>
The module definition is pretty basic and the two template files mediaforge_default.phtml and mediaforge_product.phtml are pretty simple so I won't bother including them.
Any ideas?
In a nutshell, you need to define a cache key for your block, which means you'll need to use something other than Mage_Core_Block_Template. When you create your own block, add this to the constructor:
protected function _construct() {
$this->addData(array(
'cache_lifetime' => 3600,
'cache_key' => $this->someMethodToDifferentiatePages(),
));
}
That last method needs to return a different string to every use case of the block (e.g. one for catalog pages, one for "other" if that's all you need). This will tell Magento which cached version to use
Hope that helps!
Thanks,
Joe

Override code-behind for a block in Magento

I am writing a module to extend the Core/Catalog/Product/View/Media.php class so I can expose new methods in my template. I followed a number of guides online, including Alan Storms excellent series, but have had little success. ( http://alanstorm.com/magento_config )
I posted my code on Github: https://github.com/razialx/Magento-Overwrite-Block
I am not getting any errors in the logs, it just isn't loading my class. Very perplexed.
One thought I had was that I may only be able to rewrite classes that are explicitly defined. I know the Mage_Catalog_Block_Product_View_Media class is never defined in a config file, though I assume it is referenced by the layout xml file catalog.xml
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
Your config.xml is slightly off. Give the following a try.
<config>
<modules>
<Test_Catalog>
<version>1.0.0.0.0</version>
</Test_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_view_media>Test_Catalog_Block_Product_View_Media</product_view_media>
</rewrite>
</catalog>
</blocks>
</global>
</config>
Your <blocks> node needs to be enclosed in a <global> node.

Resources