Core overrides in Magento - magento

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!

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!

Related

Declare two custom blocks.

I know that in order to create a new custom block we have to add this part to the config.xml file:
<blocks>
<products1>
<class>Company_Namespace_Block</class>
</products1>
</blocks>
This goes for creating a single custom block.
But what if I want to create more than one custom blocks. How should I declare them then? Something like this?
<blocks>
<products1>
<class>Company_Namespace_Block</class>
</products1>
<products2>
<class>Company_Namespace_Block</class>
</products2>
</blocks>
<blocks>
<products1>
<class>Company_Namespace_Block</class>
</products1>
</blocks>
The above is:
Namespace for all of your Module's block classes.
Area where all of your block classes will reside.
(app/code/{codePool}/Company/Namespace/Block).
A sort of Prefix for all Block classes of your module (like
Company_Namespace_Block_Test, Company_Namespace_Block_Test2)
So, you don't need to replicate the block configuration, to declare more than one block classes. You can declare as many block classes under (app/code/{codePool}/Company/Namespace/Block).

How to override a camelCased model file in Magento?

I have a shipping community model that has a camel cased class/file witch I would like to override.
The original file/class is located under app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php and I would like to override a method of this file, or the whole class under app/code/local/Esmart/CorreiosImprovements/Model/Carrier/CorreiosMethod.php.
In the original module config file, I can see it's model declaration in config.xml as follows:
<global>
...
<models>
<pedroteixeira_correios>
<class>PedroTeixeira_Correios_Model</class>
</pedroteixeira_correios>
</models>
...
<sales>
<shipping>
<carriers>
<pedroteixeira_correios>
<class>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</class>
</pedroteixeira_correios>
</carriers>
</shipping>
</sales>
</global>
At my module config.xml I've declared the override this way:
<global>
<models>
<esmart_correiosimprovements>
<class>Esmart_CorreiosImprovements_Model</class>
</esmart_correiosimprovements>
<pedroteixeira_correios>
<rewrite>
<carrier_correiosMethod>Esmart_CorreiosImprovements_Model_Carrier_CorreiosMethod</carrier_correiosMethod>
</rewrite>
</pedroteixeira_correios>
</models>
</global>
Usually the model file isn't camel cased, so I guess it's easier. Or am I missing something here?
Any help is appreciated.
The class group (<pedroteixeira_correios>) to use in your rewrite syntax depends on the class group declaration in the module's config.
The class ID (<carrier_correiosMethod>) to use in your rewrite syntax depends entirely on how the class is invoked in the code. For your example, the following would all instantiate the original class instance on case-sensitive filesystems:
pedroteixeira_correios/carrier_correiosMethod
pedroteixeira_correios/Carrier_correiosMethod
pedroteixeira_correios/carrier_CorreiosMethod
pedroteixeira_correios/Carrier_CorreiosMethod
On case-insensitive filesystems, any combination of casing for the class ID part would yield the model instance. Hopefully the extension vendor followed a consistent pattern when specifying their class in code/markup, but you can specify multiple xpaths using the list above to handle all permutations.

overriding class first to second working but overriding second to third not working

I am overriding AW_Blog_Block_Cat and it is working good.
<global>
<blocks>
<blog>
<rewrite>
<cat>King_Ring_Block_Updates_Cat</cat>
</rewrite>
</blog>
</blocks>
</global>
Now I want to override the above class King_Ring_Block_Updates_Cat in other module and it's not overriding. Still showing the above class(King_Ring_Block_Updates_Cat), not showing the below one(Cat_Rat_Block_Updates_Bat). Can anyone please tell me why is that?
config is:
<global>
<blocks>
<ring>
<rewrite>
<updates_cat>Cat_Rat_Block_Updates_Bat</updates_cat>
</rewrite>
</ring>
</blocks>
</global>
Class definition
Cat_Rat_Block_Updates_Bat extends King_Ring_Block_Updates_Cat
Check your XML for second rewrite.
You are starting the module name as <ring> and ending it with </blog> instead of ring itself.
Another issue, you are starting the tag <updates_cat>, and ending it with </cat>.
Do you want developers here to parse your XML and check your typos?
Check your code thoroughly before posting things here.
Change the required things as I said, clear cache, and it should work.
I found it in the end. Nothing was wrong with the configuration or paths.
It was In my Layout.xml, as I was kept on calling the wrong block type to override. I was kept on calling the same parent block type which had already been overridden by second block, that is why it never rendered.
Now in order to override the second block I specify that block type and obviously it works!!
<block type="rat/updates_bat" name="N" template="whatever temp"/>.

Magento - Can you use more than one <routers> in the confix.xml of custom module

I'm trying to modify two similar custom modules to combine them into 1 custom module. However, both of these modules use the <routers> tag in the confix.xml. I've searched and searched for a way to do this but no luck.
For example:
Custom Module 1
<admin>
<routers>
<Namespace_Module1>
<use>admin</use>
<args>
<module>Namespace_Module1</module>
<frontName>frontname</frontName>
</args>
</Namespace_Module1>
</routers>
</admin>
Custom Module 2
<admin>
<routers>
<Namespace_Module1>
<use>admin</use>
<args>
<module>Namespace_Module2</module>
<frontName>namefront</frontName>
</args>
</Namespace_Module2>
</routers>
</admin>
I think this is the only thing stopping me from being able to combine the two similar modules together. Can this be done? If so, how (an example)?
Im not entirely sure what you are trying to achieve. Are you looking for two different routers i.e. two distinct front names, defined from within a single module?. If so, read on - if not, can you clarify things a little further please.
Firstly, you have a tag mismatch in the xml you have provided in Custom Module 2. You are opening <Namespace_Module1> and closing with </Namespace_Module2> - so as it stands, this code will not work.
Secondly, to define a router, you must use the <routers> tag - so there is no issue with this. The nodes directly underneath it must be unique though.
So, assuming I have read your question correctly and you want to merge these two router nodes but still have two distinct front names, the following would work:
<admin>
<routers>
<namespace_module1>
<use>admin</use>
<args>
<module>Namespace_Module1</module>
<frontName>frontname</frontName>
</args>
</namespace_module1>
<namespace_module2>
<use>admin</use>
<args>
<module>Namespace_Module2</module>
<frontName>namefront</frontName>
</args>
</namespace_module2>
</routers>
</admin>
Though, if there was a particular reason that these have to be separate routers, then I would offer the following as better alternative: use a single router but multiple controllers. So your xml would just be:
<admin>
<routers>
<namespace_module>
<use>admin</use>
<args>
<module>Namespace_Module</module>
<frontName>frontname</frontName>
</args>
</namespace_module>
</routers>
</admin>
Create two controllers in your modules controller directory, say Module1Controller.php and Module2Controller.php.
Then you would be able to access them (the index actions) via /frontname/module1/ and /frontname/module2.
This feels like a much cleaner solution.
As I understand, you are trying to match controllers for 2 modules through one frontName.
This is perfectly possible by using the 'modules' node in your second module. Keep your configuration for the first module, but use this for the second one:
<admin>
<routers>
<Namespace_Module1>
<args>
<modules>
<Namespace_Module2>Namespace_Module2</Namespace_Module2>
</modules>
</args>
</Namespace_Module1>
</routers>
</admin>
No need to specify 'use' or 'frontName', those XML files are merged anyway. Magento will first try to find a matching controller in the first module, and then in the second one.

Magento - how to declare multiple helper classes in the same config

Could someone please tell me how I can declare multiple helpers within the same config file for the same module?
I've been using helper utility files for awhile now, but as my utility method is becoming increasingly long, with many functions, I'd like to split it up into seperate helper utility classes based on the functionality. So I'd have a class called Categoryhelper and one called Attributehelper. Obviously this step I can do, but I'm not sure how to declare these in the config.xml.
I've tried messing around with the config, doing trial and error but cant seem to get anything to work.
Here's what I originally had, using the default helper:
(note - my custom module name is called 'Helper'
<global>
...
<helpers>
<helper>
<class>GPMClient_Helper_Helper</class>
</helper>
</helpers>
...
and here's what I've tried:
<helpers>
<helper>
<class>GPMClient_Helper_Helper/Categoryhelper</class>
</helper>
<helper>
<class>GPMClient_Helper_Helper/Attributehelper</class>
</helper>
and:
<helpers>
<helper>
<class>GPMClient_Helper_Helper/Categoryhelper</class>
<class>GPMClient_Helper_Helper/Attributehelper</class>
</helper>
Should the helper classes go into their own xml fragment or should both be grouped together?
If anyone could please post a sample config with multiple helper classes declared, I'd be most grateful.
Thanks,
Ian
Seems like you got wrong how it works. When you add next lines to your GPMClient_Helper module config.xml
<helpers>
<helper>
<class>GPMClient_Helper_Helper</class>
</helper>
</helpers>
you define class prefix for all your helpers. So, now in your GPMClient/Helper/Helper directory you should create file Data.php with GPMClient_Helper_Helper_Datacode inside and any number of classes named GPMClient_Helper_Helper_*.

Resources