Adding Block in existing module of magento - 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.

Related

How do I add javascript tracking code to all magento pages?

I need to add java script tracking code to all pages of my magento store just before the closing "body" tag. Does anyone know what file I need to put this in? And do I have to modify the JavaScript at all for Magento or just paste it in?
To answer your question: How do I add javascript to every page
Within the template, typically you load a footer block on every page, so go and find the phtml file here;
app/design/frontend/XXX/YYY/template/page/html/footer.phtml
Where xxx/yyy is your theme directory. Add the tracking code here and it will load on every page.
Regarding whether it needs modification - that really depends what you expect to do. If you need to insert variables such as basket values, customer number (if present) etc, then yes you will need to add those php variables to it, and here is where you could run into trouble. If you are using caching, then the footer may not be the best place as you could end up with cached variable values in the snippet. If it dynamically pulls it values for things such as page url, then you'll be ok.
The other problem is that this will load in your checkout pages - so if it calls a js file from an http:// location, your page will fail SSL validation.
You can do this by adding a layout file to your module configuration:
<config>
...
<frontend>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
...
</config>
Add the mymodule.xml file into the app/design/frontend/base/default/layout/ folder and put the following content in there:
<layout version="1.0.0">
<default>
<reference name="before_body_end">
<block type="core/template" name="mytracking.block" after="-" template="mynamespace/mymodule/tracking.phtml">
<action method="setCacheLifetime"><s>0</s></action>
</block>
</reference>
</default>
</layout>
Now you can add your tracking javascript code in this template file app/design/frontend/base/default/template/mynamespace/mymodule/tracking.phtml. It will be printed in all Magento pages.
EDIT
I've added a piece of code that disables the cache for your tracking block, thanks to #PixieMedia for letting me know.
Easiest way - via the backend, there is a config section specifically for this need.
System -> Configuration -> General -> Design Section -> Footer Tab -> Miscellaneous HTML
It relies on your theme calling the getAbsoluteFooter() method in your main template files right before the closing body tag, just be aware of that.
<?php echo $this->getAbsoluteFooter() ?>
</body>

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.

Magento: Custom module not working on magento 1.3.2.3

I have designed a custom magento extension. It has custom menus on magento admin panel. I have tested it on magento 1.5. But when I tested it on magento 1.3.2.3 it didn't show any menu. I have checked module status from System->Configraion->Advanced and it is enabled there. What could be the possible problems here??? Why my module is not working on magento1.3.2.3??
Please help.
Clean cache.
Try to remove ACL(if any) from config.xml.
As already suggested: Log out and Log in.
Check logs in (mage root)/var/logs/ system.log and exception.log
Check config.xml structure of any default module. For example, check
(mage root)/app/code/core/Mage/Catalog/etc/config.xml
I suppose there should be something useful for you.
I think you need your Helper->Data.php in place and also have the entry for the helper in your config.xml, sth like:
<global>
<helpers>
<Mymodule>
<class>Myspace_Mymodule_Helper</class>
</Mymodule>
</helpers>
</global>

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.

Magento - Adding Files to Local/Mage has no Effect

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.

Resources