问题
So I found an answer for a question I had about dynamic option pricing, but that lead to me being stumped. I can understand the majority of the answer, but when it comes to the XML and module implementation, I'm lost.
Here's what I'm trying to do:
http://www.magentocommerce.com/boards/viewthread/260544/#t348802
Need to override the Mage_Catalog_Model_Product_Type_Price model and the Mage_Catalog_Block_Product_View_Options block.
Modified Price.php is located at
/app/core/local/rtega/dynamicPrice/Model/Product/Type/Price.php
Modified Options.php is located at
/app/core/local/rtega/dynamicPrice/Block/Product/View/Options.php
Have rtega_dynamicPrice.xml in
/app/etc/modules/
Below is current config.xml located in
/app/core/local/rtega/dynamicPrice/etc/
<?xml version="1.0"?>
<config>
<modules>
<rtega_dynamicPrice>
<version>1.0.0</version>
</rtega_dynamicPrice>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_view_options>rtega_dynamicPrice_Block_Product_View_Options</product_view_options>
</rewrite>
</catalog>
</blocks>
<catalog>
<product>
<type>
<configurable>
<price_model>rtega_dynamicPrice_Model_Product_Type_Price</price>
</configurable>
</type>
</product>
</catalog>
</global>
</config>
Any help is greatly appreciated!
回答1:
Three things to mention.
Firstly, I don't know how well Magento will handle your casing of "rtega" and "dynamicPrice". This might cause an issue either now or in the future. My recommended casing would be "Rtega" and "Dynamicprice". But it might be fine.
Secondly, your block rewrite xml looks fine, but the rewrite for the catalog Model is incorrect. I'd expect to see:
<config>
...
<global>
...
<models>
<catalog>
<rewrite>
<product_type_price>rtega_dynamicPrice_Model_Product_Type_Price</product_type_price>
</rewrite>
</catalog>
</models>
...
</global>
...
</config>
The best way to think about this is to break it down to how you instantiate the original model in the first place. In this case, we would call
Mage::getModel("catalog/product_type_price");
so the first xml node is "models", since this is a model, the next xml node is the portion before the slash (catalog), then add a rewrite tag, then after the slash becomes the next xml node, like so:
<models>
<catalog>
<rewrite>
<product_type_price>
Thirdly, in this instance it's important to see the files that you've mentioned are at:
/app/core/local/rtega/dynamicPrice/Model/Product/Type/Price.php and
/app/core/local/rtega/dynamicPrice/Block/Product/View/Options.php
If you're not already doing so, you need to define the classes like this:
class rtega_dynamicPrice_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price {
then just redefine the functions you want to modify.
I hope this helps you somewhat!
来源:https://stackoverflow.com/questions/11235679/core-overrides-in-magento