Rewrite a controller of a magento Module

Source: Internet
Author: User

 

Rewrite a magento
A controller of the module

When you need
When a function is modified, a new module is created to override a controller of an existing module.
It is inevitable, because you only want to modify one of the methods, and do not need to change other Controller
, Other classes.

 

 

 

To override checkout

Module onepagecontroller. php

For example:

 

 

 

Step
One:
Create and register a new module

 

Needless to say, you can directly copy the file directory structure of an existing module, or create only the files you need to modify. Of course, you must maintain the directory structure level. And contain required files: the required files for each module are config. xml.
And then the file you want to modify.

 

Module file:

 

Magento/APP/code/local/Company/xcheckout/etc/config. xml

Magento/APP/code/local/Company/xcheckout/controllers/onepagecontroller. php

Note: In theory, we can also

Package
) Using checkout
As the module name, but this problem occurs during implementation, and even though I try to track the code to find out the cause, it seems like magento
This is the way it is handled. If it is correct, it may be a bug.
Bug
Right.

 

To magento
Register a new module file:

 

Magento/APP/etc/modules/company_all.xml

 

<Config>

<Modules>

<Company_xcheckout>

<Active> true </active>

<Codepool> core </codepool>

<Depends>

<Mage_checkout
/>

</Depends>

</Company_xcheckout>

</Modules>

</Config>

 

Note: depends is not specified.
Yes, but I think our module should be in the original checkout.
It is actually dependent on the modules. It is reasonable to add them.

 

 

 

Step 2:
Edit config. xml of the new module
File, configure the controller you want to override
.

 

<? XML
Version = "1.0" encoding = "UTF-8"?>

<Config>

<Modules>

<Company_xcheckout>

<Version> 0.1.0 </version>

</Company_xcheckout>

</Modules>

<Global>

<Rewrite>

//
I thought the name was case sensitive, but in fact it was not. Because magento
There is no reference document, and we can only verify it through code. But I found that this is not magento.
What they said on the forum is case sensitive. Of course, it must be unique.

<Company_xcheckout_onepage>

<From> <! [CDATA [# ^/Checkout/onepage/#]> </from>

<To>/xcheckout/onepage/</to>

</Company_xcheckout_onepage>

</Rewrite>

 

//
Override magento
Block

<Blocks>

<Checkout>

<Rewrite>

<Onepage> company_xcheckout_block_onepage </onepage>

<Onepage_billing> company_checkout_block_onepage_billing </onepage_billing>

</Rewrite>

</Checkout>

</Blocks>

</Global>

 

//
If you find your controlller
Not called, basically Router
The setting is unreasonable.

<Frontend>

<Routers>

<Company_xcheckout>

<Use> Standard </use>

<ARGs>

<Module> company_xcheckout </module>

<Frontname> xcheckout </frontname>

</Args>

</Company_xcheckout>

</Routers>

 

//
If you encounter issues such as blank pages during implementation, it is basically because of Layout
Caused

<Layout>

<Updates>

<Checkout>

<File> xcheckout. xml </File>

</Checkout>

</Updates>

</Layout>

</Frontend>

</Config>

 

 

 

Step
3:
Rewrite related Code

 

1
Rewrite Controller
Class

 

Require_once
"Mage/Checkout/controllers/onepagecontroller. php ";

 

Class
Company_xcheckout_onepagecontroller extends
Mage_checkout_onepagecontroller

{

// Do
What you want

 

//
Enjoy it

 

}

 

2
, Rewrite Block

 

Require_once
'Mage/CORE/Checkout/block/onepage. php ';

 

Class
Company_xcheckout_block_onepage extends
Mage_checkout_block_onepage_abstract

{

 

}

 

Note: In fact, many problems have been found and magento has been learned during code implementation and tracking.
Some of them have nothing in the document. You can only wait for a little time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.