Magento Rewrite Block
来源:互联网 发布:网络语言黑洞的意思 编辑:程序博客网 时间:2024/05/04 16:37
When develop a site base on Magento. Everyone have to rewrite some block to customize the information which will display on template page.
Before start to make a sample, Some magento term will be introduce:
Namespace: The name of folder under the /app/code/core OR /app/code/local.
For example rewrite the product/view block display normal information on the product detail page.
1. Disable the cache
2. Create a new folder under /app/code/local/ named "Red"(Namespace), add new module structure:
/app/code/local/Catalog
/Catalog/Block
/Catalog/etc/config.xml
3. Changed the config.xml as following:
<?xml version="1.0"?>
<config>
<modules>
<Red_Catalog>
<version>0.1.1</version>
</Red_Catalog>
</modules>
</config>
4. Add module config file like /app/etc/modules/Red_All.xml as following:
<?xml version="1.0"?>
<config>
<modules>
<Red_Catalog>
<active>true</active>
<codePool>local</codePool>
</Red_Catalog>
</modules>
</config>
5. Go to admin panel, Enable the cache and then Refresh it. System->configuration->Advanced->Advanced ->Disable modules output
You will see a module named Red_Catalog Enable. Good lucky! Then Disable the cache.
6. Create new product/view block class:
Create a new file: /app/code/local/Catalog/Block/Product/View.php look like this:
<?php
class Red_Catalog_Block_Product_view extends Mage_Catalog_Block_Product_view
{
public function getMoreInfor()
{
return "The new promotion is on our site!";
}
}
7. Change the /app/code/local/Catalog/etc/config.xml like this:
<?xml version="1.0"?>
<config>
<modules>
<Red_Catalog>
<version>0.1.1</version>
</Red_Catalog>
</modules>
<global>
<blocks>
<catalog>
<product_view>Red_Catalog_Block_Product_View</product_view>
</catalog>
</blocks>
</global>
</config>
NOTE: <product_view>Red_Catalog_Block_Product_View</product_view> can't have any space. Except the space before the starting of this line. And can't divide this into many lines;
8. Change the template file under the theme you choosed as following:
9. Enabled cache. Go to the product detail page:
Under the head: you will see one line text with red color like this:
The new promotion is on our site!
So far: the catalog product view rewriting is finished, Good Lucky.
- Magento Rewrite Block
- magento Block
- Magento – Rewrite 运行机制
- Magento URL rewrite
- Magento Controller Rewrite - Magento 控制器重写
- enable URL Rewrite for magento
- Magento Rewrite Url的方法
- Magento block url
- Magento 移除block
- magento block和reference
- magento中的block
- magento static block
- Controller override and request rewrite in Magento
- Magento中Block的应用
- Magento的block重写规则
- Powerful block system in Magento
- Magento调用Block方法集合
- Magento Block的缓存机制
- java源码批量编译-javac、jar、java及其ANT使用
- STL--list
- 学习的正确心态
- 在linux终端模式下显示JPEG格式图片(参考了其他资料)
- [转] 用WWW-Authenticate实现登录验证
- Magento Rewrite Block
- CCNA 标准版本的基本配置
- Change the magento theme:
- Magento更改主题:
- The 'Microsoft.ACE.OLEDB.12.0' provider is not registered error with Vista 64bit
- 手机 : SyncML功能
- UNIX网络编程(一)
- Android 给Button加个监听
- 被鄙视了