How to modify a grid in adminhtml in Magento? - magento

I'm trying to modify the app/code/core/Mage/Adminhtml/Block/Customer/Grid.php file with my own grid, which is located at app/code/local/MyCompany/MyModule/Block/Adminhtml/Customer/Grid.php
I tried to add this code in my config.xml :
<blocks>
<adminhtml>
<rewrite>
<customer_grid>MyCompany_MyModule_Block_Adminhtml_Customer_Grid</customer_grid>
</rewrite>
</adminhtml>
</blocks>
but it didn't work, can somedboy help me?
[edit] I updated my code with the help of the first answer but this didn't work either, I've got a server error. My grid file works well if I replace my core file [/edit]

The config maps rewrites through the class group ("adminhtml" in this case):
<blocks>
<adminhtml>
<rewrite>
<customer_grid>Tegeso_Codepromo_Block_Adminhtml_Customer_Grid</customer_grid>
</rewrite>
</adminhtml>
</blocks>
See Mage_Core_Model_Config::getGroupedClassName() to see exactly how this works.

Related

Magento Module rewrite

I have a Magento extension with custom product type that in config.xml use this action:
<routers>
<catalog>
<rewrite>
<product>
<to>custom-product-module/index</to>
<override_actions>true</override_actions>
<actions>
<view>
<to>custom-product-module/index/view</to>
</view>
</actions>
</product>
</rewrite>
</catalog>
</routers>
The problem is that this rewrite action affect also all the other product types like simple product, virtual product etc. What I want is to bring Magento to use this rewrite action only for the custom product type used from my extension.
Any help please? best regards

starting with Magento Backend

Since a couple of days I´m looking at the behaviour of the Magento backend. To comprehend I made a new grid to see a table of the bbdd. After finishing this grid I can see that I have a 404 error when try I to add a widget in a CMS page:
Debugging I can see that the error disappears if I comment this out of my custom module
<admin>
<routers>
<giftrouter>
<use>admin</use>
<args>
<module>Wpr_Giftproducts_Adminhtml</module>
<frontName>admin</frontName>
<modules>
<sintax after="Wpr_Giftproducts_Adminhtml">Mage_Adminhtml</sintax>
</modules>
</args>
</giftrouter>
</routers>
</admin>
Concretely I think that the error was caused by this:
<sintax after="Wpr_Giftproducts_Adminhtml">Mage_Adminhtml</sintax>
But I don´t understand how this config works.
How can I set a custom route to avoid conflict with the widget?
I think you have your routers in reverse.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<sintax before="Mage_Adminhtml">Wpr_Giftproducts_Adminhtml</sintax>
</modules>
</args>
</adminhtml>
</routers>
</admin>
This way the Giftproducts controller is part of the adminhtml router, whereas the old way was reassigning admin controllers to giftrouter.

Magento block override from two different modules

Hi I have some issues in overriding a magento core block. In my module I need to override Mage_Catalog_Block_Navigation
<blocks>
<catalog>
<rewrite>
<navigation>Mycompany_Mymodule_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
but this is already overridden by another magento extension from another company:
<blocks>
<catalog>
<rewrite>
<navigation>Othercompany_Othermodule_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
Both extension overrides different methods and they don't know abut each other, but magento reads the second company overrides and not my. I don't want to use module dependencies. Is there any way to not break the two extensions functionality.
Yes, you have to decide which one officially overwrites the core Block. Have that one inherit the one that isn't doing the override, and have that one inherit the core one.
My_Custom_Block extends Other_Custom_Block
Other_Custom_Block extends Mage_Core_Block
Mage_Core_Block extends Whatever_Magento_Wants
Edit the config.xml files so that only My_Custom_Block is the one that is overriding the core Block.
EDIT
Here's the XML you need:
<blocks>
<catalog>
<rewrite>
<navigation>Mycompany_Mymodule_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
Thx Max.
I think, like your example, that the "My_Custom_Block" should be the last hierarchic class, so you don't touch anythings in "Other_Custom_Block" class.
Then you have only to comment the rewrite rule in "Other Company" config.xml.

Rewriting Mage_Paypal_Model_Express_Checkout

I have run into a problem where shipping options are not making it to the PayPal Express review page. If the buyer enters a free shipping coupon and then uses PayPal Express, when they return from the PP website, the review page where the submit the order doesn't have the free shipping option.
I found a thread where this was answered by adding code to the Mage_Paypal_Model_Express_Checkout class. This change works, but modifying core code is a no-no, so I'm trying to rewrite the class and I'm having trouble. I've rewritten core classes before, but this one is different somehow and I can't figure it out. Can someone point me in the right direction?
here's the contents of my config.xml. Does this look right?
<config>
<modules>
<VPS_Paypal>
<version>0.1.0</version>
</VPS_Paypal>
</modules>
<global>
<models>
<paypal>
<rewrite>
<express_checkout>
<class>VPS_Paypal_Model_Express_Checkout</class>
</express_checkout>
</rewrite>
</paypal>
</models>
</global>
</config>
I haven't tested this, but based on the class name I would think that adding this to the section of your config would work:
<paypal>
<rewrite>
<express_checkout>Your_Model_Class_Here</express_checkout>
</rewrite>
</paypal>
Your custom class should extend Mage_Paypal_Model_Express_Checkout and only override the method you want to change.

custom attribute UI in Magento admin

I'm trying to change the way Magento shows options of an attribute with multiple select.
I have 10K options for this attribute.
How can I override the UI and use an Ajax based UI?
The admin will be able to filter options and present only ~20 each time.
I know how to use js and php for this but not in Magento.
Thanks
You can try to rewrite block class responsible for this attribute.
<global>
<blocks>
<adminhtml>
<rewrite>
<catalog_product_edit_tabs_price>Company_Module_Block_Adminhtml_Tabs_Price</catalog_product_edit_tabs_price>
</rewrite>
</adminhtml>
</blocks>
</global>
Then in your Company_Module_Block_Adminhtml_Tabs_Price you can re-declare function responsible for logic for price attribute (for example).
You should have a good knowledge of Magento for this.

Resources