Magento - Adding Files to Local/Mage has no Effect - magento

I would like to make changes to some Magento core files. To make sure the changes are future proof I copy the file from code/core/Mage to code/local/Mage.
I keep the file structures and file names consistent. The problem is when I do this the changes have no effect (I've refreshed the cache)
Any ideas where I'm going wrong? If I edit the core files directly the changes take place.

You should create a new local module and define rewrites in the config.xml file:
Create app/code/local/MyCompany/MyModule directory. Add subfolders etc and model.
Now create etc/config.xml file containing:
<?xml version="1.0" encoding="utf-8?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<global>
<models> <!-- type of class to rewrite -->
<catalog> <!-- base module to rewrite -->
<rewrite>
<product>MyCompany_MyModule_Model_Product</product>
</rewrite>
</catalog>
</models>
</global>
</config>
Implement model/Product.php with your changes. Easiest way is to inherit from the base class and rewrite the metho.
Also remember to activate your module in app/etc/modules.

The above poster is correct in that the preferred way to edit core functionality is to use rewrites. In some cases, though, this isn't possible, in which case you should be able to place core files into the /app/code/local/Mage directory to get them to work. Block and Model files should work immediately in this way, as should controllers if I remember correctly. Other files (such as config files) may not be automatic.
Could you post the details of a particular file that doesn't respond as you expect? It's easier to debug particulars than generalities. Also, make sure that you have shut off any opcode cache that you have installed on the server in addition to flushing the normal cache.
Thanks,
Joe

You can easily overwrite xml settings using local.xml. So, if you want to overwrite/add to app/code/core/Mage/Customer/etc/config.xml you just add it to app/etc/local.xml.

Related

Magento rewrite extension controller

I am trying to do small change in community module MDN_Organizer in Magento 1.9 and it is turning out to be nightmare for me.
I need to change also one Grid so I created in code/local folders MDN / Organizer / Block / Task and new file Grip.php
For that, I have to rewrite one Action in controller TaskController which is in folder MDN / Organizer / Controllers / TaskController.php
Is it possible to rewrite that controller in local MDN / Organizer folder? Or Do I need to put controller to my own modules?
Can controller have the same name?
How etc/config should looks?
Controller is for admin.
You need to create new module you can keep in local or community it is not matter
But add code in you file
app\etc\modules\Mycompany_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Modulename>
<active>true</active>
<codePool>local</codePool>
<depends>
<MDN_Organizer/>
</depends>
</Mycompany_Modulename>
</modules>
</config>

Magento - how to rewrite an extension model, which has rewritten a core model?

i'm writing an extension, which needs to overwrite the Mage_Core_Model_Order-Class. I know how that works. The problem now is, that there´s another Extension (Webshopapps_Dropship), which also overrides/extends this class. Now, if i try to override the Class from the Dropship-Extension, it won´t work.
This is what i inserted in my config.xml
<global>
<models>
<dropship>
<rewrite>
<sales_order>My_Module_Model_Sales_Order</sales_order>
</rewrite>
</dropship>
</models>
</global>
I also try to depend my module from the Dropship-extension. But this also doesnt work.
Please help me, i can´t find, what is wrong.
Everytime i create the class via
$myOrderClass = Mage::getModel("sales/order");
i will get the Dropship-Class and not the one from my own extension.

how to change email format from html to text in magento for admin?

in magento on order confirmation email is sent to admin in HTML format,
but i want to change it to plain text format so how and from where i can change that format only for admin, customer should get email in HTMl format as it is.
Can anyone please give me solution for this?
Thanks.
For future readers, do not edit core files as others suggest. You can achieve this in config alone with a tiny custom module.
I have AheadWorks' blog module installed, you may not, or you may have other modules that need their email format overridden. So, adjust accordingly.
Create app/etc/modules/YourNameSpace_EmailFormat.xml and add to <depends>, so your config is loaded last:
<?xml version="1.0"?>
<config>
<modules>
<YourNameSpace_EmailFormat>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Contacts/>
<AW_Blog/>
</depends>
</YourNameSpace_EmailFormat>
</modules>
</config>
Create app/code/local/YourNameSpace/EmailFormat/etc/config.xml, adding elements for all the templates you wish to override:
<?xml version="1.0"?>
<config>
<modules>
<YourNameSpace_EmailFormat>
<version>1</version>
</YourNameSpace_EmailFormat>
</modules>
<global>
<template>
<email>
<customer_create_account_email_template>
<type>text</type>
</customer_create_account_email_template>
</email>
</template>
</global>
</config>
That's it. I needed the reverse, so I had <type> set to html. This goes very well with Yireo's Email Override module so you can easily customise your templates. If converting plain text emails to HTML, be sure to change template tags like {{var foo.bar}} to {{htmlescape var=$foo.bar}} to prevent malicious code injections.
First create custom email template from Transactions emails and text type set as plain. Note down that template Id. and use in below file.
At \app\code\local\Mage\Sales\Model\Order.php sendNewOrderEmail() load manually template is and sent variables to that and send email.
you have to override and extend the Mage_Core_Model_Email_Template model to achieve this and set the correct header from there and you can't separate those by user and you ahve to build your own logic for that

Magento - Clean custom Account/Registration Fields

I followed this tutorial to add fields in the registration form of a customer under Magento, I succeed to run the example, but I know that It is not clean, for upates later...
What' the best way to rewrite all the files used in the tutorial, in a clean way :
app/design/frontend/default/yourtheme/template/customer/form/register.phtml
app/design/frontend/default/yourtheme/template/customer/form/edit.phtml
app/code/core/Mage/Customer/Model/Entity/Setup.php
app/code/core/Mage/Customer/etc/config.xml
app/code/core/Mage/Customer/controllers/AccountController.php
Thanks a lot
You need to create your own module. Never edit files in app/code/core/ folder. If you want to add functionality to Magento, you need to rewrite the base classes.
Alan Storm has good tutorials to follow:
How to create a simple 'Hello World' module in Magento?
To rewrite a controller (AccountController in your case), and after you create you own module, you can follow this tutorial.
Configure the Layout
In your app/code/local/MyCompany/Module/etc/config.xml:
<?xml version="1.0"?>
<config>
<frontend>
<layout>
<updates>
<mydesign>
<file>myfile.xml</file>
</mydesign>
</updates>
</layout>
(...)
Then you could update your layout in app/design/frontend/default/mydesign/layout/myfile.xml.

Adding Block in existing module of magento

I have customized customer module to meet my requirement. I am able to rewrite block classes of customer module. I am trying to add one custom block class in this module which is not exists in existing customer module but I don't know how to accomplish this.
my code looks like in config.xml
<blocks>
<customer>
<rewrite>
<widget_name>Mynamespace_Customer_Block_Widget_Name</widget_name>
<form_register>Mynamespace_Customer_Block_Form_Register</form_register>
<form_edit>Mynamespace_Customer_Block_Form_Edit</form_edit>
</rewrite>
</customer>
</blocks>
I created a new block class under the Form directory of customer module called 'Test.php'
And customer layout file looks like
<reference name="my.account.wrapper">
<block type="customer/form_test" name="customer_test" template="customer/form/test.phtml"/>
</reference>
But it is not executing the block class file.
Is there anything should be added in config.xml file of this module?
Please help how this block can be integrated with existing module.
Thanks.
You shouldn't really be adding blocks to the customer module, you should be adding them to your own module. If you want to keep on w/ the customer module, check to make sure that your block is named as Mage_Customer_Block_Form_Test and extends Mage_Core_Block_Template. Otherwise, create the class as Mynamespace_Customer_Block_Form_Test and keep it in your module directory. Then, add a block definition for your class in config.xml:
<blocks>
<mynamespace_customer>
<class>Mynamespace_Customer_Block</class>
</mynamespace_customer>
</blocks>
Then you should be able to load the block as mynamespace_customer/form_test.
It may be easier to debug your problem if you use a module name other than customer. Generally speaking, that is a bad idea and will likely cause bugs in the system.
Hope that helps!
Thanks,
Joe
You may already be aware of this but think about checking LayoutViewer to see what the layout thinks it is using.
Although I'm sure your example config.xml is just an example please make sure that you've remembered to create a rewrite for form_test and that there is a valid blocks section for your own module.
BTW, LayoutViewer could really do with being packaged properly for Magento Connect. The linked file lacks the necessary config to enable the module and it would be much more useful if accessible from PEAR.

Resources