extending a tax class into an existing company extension - magento

I have extended Magento core files before but in this case wish to extend a class
//app/code/core/Mage/Tax/Model/Calculation.php
i.e. Mage_Tax_Model_Calculation
into an existing component my company had:
//app/code/local/Mycompany/Model/Companytaxrate.php
i.e. Mycompany_Companytaxrate_Model_Companytaxrate
The module Companytaxrate is already in place as is this file. How would I do this?

You can extend Mage_Tax_Model_Calculation from your new model:
class Mycompany_Companytaxrate_Model_Companytaxrate extends Mage_Tax_Model_Calculation
{
}
From there, you'd rewrite the model inside your /etc/config.xml file:
<global>
<models>
<tax>
<rewrite>
<calculation>Mycompany_Companytaxrate_Model_Companytaxrate</calculation>
</rewrite>
</tax>
</models>
</global>

Related

On clicking a custom tab in Magento admin,Invalid config field backend model

I have module a module as Mak_Gift there I am creating a custom tab.(Mak is namespace and Gift is module name.)
When I click the tab created in the Magento admin, I am getting following error
Invalid config field backend model: gift/system_config_backend_date
I have created the system.xml file with following code
....
<backend_model>gift/system_config_backend_date</backend_model>
....
I have the Date.php file at following location
app\code\local\Mak\Gift\Model\System\Config\Backend\Date.php
class Mak_Gift_Model_System_Config_Backend_Date extends Mage_Core_Model_Config_Data
{
protected function _beforeSave()
{
}
}
config.xml
<global>
<models>
<mak_gift>
<class>Mak_Gift_Model</class>
</mak_gift>
</models>
</global>
What is wrong with my code?
Declare your backend model like this:
<backend_model>mak_gift/system_config_backend_date</backend_model>
Or else you change
<global>
<models>
<mak_gift>
<class>Mak_Gift_Model</class>
</mak_gift>
</models>
</global>
To
<global>
<models>
<gift>
<class>Mak_Gift_Model</class>
</gift>
</models>
</global>

override class in core magento

I need to override class Mage_Paypal_Model_Ipn.
class Budsies_Budsie_Paypal_Model_Ipn extends Mage_Paypal_Model_Ipn
{
protected function _processOrder()
{
Mage::log('Budsies_Budsie_Paypal_Model_Ipn', null, 'processOrder.log');
$orderState = $this->_order->getState();
if ($orderState != Mage_Sales_Model_Order::STATE_COMPLETE &&
$orderState != Mage_Sales_Model_Order::STATE_HOLDED) {
parent::_processOrder();
}
}
}
I added config.xml to my module в global section:
<global>
<models>
<paypal>
<rewrite>
<ipn>Budsies_Budsie_Paypal_Model_Ipn</ipn>
</rewrite>
</paypal>
</models>
</global>
But it doesn't work. What should be config file to make my class to rewrite core class. Could you please tell me what's the problem?
I corrected it, simply it's this section is larger and I made copy paste. But it doesn't work.
Thank you for your help. My rewrite works. The problem was that ipn for that account were not configured, there were not ipn, so this method wasn't called.
If this is really what your XML looks like then it's this:
<global>
<models>
<paypal>
<rewrite>
<ipn>Budsies_Budsie_Paypal_Model_Ipn</ipn>
</rewrite>
</paypal>
</models>
</global>
You had </models> in there twice and didn't have your </global> tag closed.

Magento - rewrite hierarchy

What is the config required to rewrite a class that is already rewriting another class in magento?
For example, There is a community module doing the following:
<models>
<modulea>
<adminhtml>
<rewrite>
<session>CompanyA_ModuleA_Model_Adminhtml_Session</session>
</rewrite>
</adminhtml>
</modulea>
</models>
I want to rewrite the community module and I am trying the following code which is not working:
<models>
<moduleb>
<class>CompanyB_ModuleB_Model</class>
</moduleb>
<modulea>
<rewrite>
<adminhtml_session>CompanyB_ModuleB_Model_Adminhtml_Session</adminhtml_session>
</rewrite>
</modulea>
</models>
What is wrong with this
Be carefull at your rewrite XML syntax, you have an error. It should like :
<modulea>
<adminhtml>
<rewrite>
<adminhtml_session>CompanyA_ModuleA_Model_Adminhtml_Session</session>
</rewrite>
</adminhtml>
</modulea>
and
<moduleb>
<adminhtml>
<rewrite>
<adminhtml_session>CompanyB_ModuleB_Model_Adminhtml_Session</session>
</rewrite>
</adminhtml>
</moduleb>
Next you'll need to extends the Good PHP class in the good order. FOr example if you want CompanyA extending/rewriting CompanyB :
CompanyA file :
class CompanyA_ModuleA_Model_Adminhtml_Session extends Mage_Adminhtml_Model_Session {
CompanyB Model php file :
class CompanyB_ModuleB_Model_Adminhtml_Session extends CompanyA_ModuleA_Model_Adminhtml_Session {
Last thing, to be sure that the rewrite is done in the good order (when doing a Mage::getModel('adminhtml/session') you want to retrieve the CompanyB class and not the COmpanyA one), you'll need to define which module depends on which. YOu do that in the app/etc/modules/Company_Module.xml file.
add for Company A :
<depends>
<Mage_Adminhtml />
</depends>
add for Company B :
<depends>
<CompanyA_ModuleA />
</depends>

Rewriting Magento Gift Card observer function

When I need to rewrite a function in an observer located in the Enterprise section, how will that rewrite bit look like on config.xml.
is it something like this?
<global>
<models>
<enterprise>
<rewrite>
<giftcard>Custom_GiftCard_Model_Observer</giftcard>
</rewrite>
</enterprise>
</models>
</global>
My class is declared as follow:
class Custom_GiftCard_Model_Observer extends Enterprise_GiftCard_Model_Observer {
.....
}
I don't have an enterprise development environment setup at the moment, so this is untested, but it should work as described.
If you look at the Gift Card configuration in
app/code/core/Enterprise/GiftCard/etc/config.xml
You can grep about and discover the class alias for the gift card observer
<class>enterprise_giftcard/observer</class>
So, with a class alias of enterprise_giftcard/observer you have a model group name of enterprise_giftcard, and a model class name of observer.
In your module's configuration file, first you'll create an area for model configuration
<global>
<models>
</models>
</global>
Then, you'll add the group name of the class you want to rewrite, enterprise_giftcard
<global>
<models>
<enterprise_giftcard>
</enterprise_giftcard>
</models>
</global>
Then, you'll add a node saying you want to rewrite the a single class in this group
<global>
<models>
<enterprise_giftcard>
<rewrite>
</rewrite>
</enterprise_giftcard>
</models>
</global>
The, you'll add a node indicating WHICH class in the group you wish to rewrite, using the name portion of the class alias (observer)
<global>
<models>
<enterprise_giftcard>
<rewrite>
<observer></observer>
</rewrite>
</enterprise_giftcard>
</models>
</global>
And finally, within this node, you'll add a text node that's the name of your new class.
<global>
<models>
<enterprise_giftcard>
<rewrite>
<observer>Custom_GiftCard_Model_Observer</observer>
</rewrite>
</enterprise_giftcard>
</models>
</global>
You can test your rewrite by instantiating the observer directly, and checking its class name
$model = Mage::getModel('enterprise_giftcard/observer');
var_dump(get_class($model));

Magento event observer for bulk import for products

Is there any event for "bulk import of products/customers"?
I intend to make a module for my vendors to upload their product information in xml/csv through the backend. When they upload, I need to update my Solr records.
Thanx
You can override the Mage_Catalog_Model_Convert_Adapter_Product::saveRow() as:
1> in config.xml
<global>
<models>
...
<catalog>
<rewrite>
<!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
<convert_adapter_product>MagePsycho_Productimport_Model_Convert_Adapter_Product</convert_adapter_product>
</rewrite>
</catalog>
...
</models>
</global>
2> create class file as
class MagePsycho_Productimport_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
{
public function saveRow(array $importData)
{
parent::saveRow($importData);
//do your extra stuffs here..
}
}
Note: This is just an idea, you need to develop full working module by yourself.
Thanks
Regards
MagePsycho

Resources