How to create a new custom payment module/extension in opencart

It is very rare that this will be needed. Even when you think you have to duplicate a module like “flat rate”, it is actually best done using one of the zone based options like weight-based or zone plus.

But in any case, for those that are hell bent on duplicating existing sideboxes, payment, or shipping modules. This hi-level breakdown should get you going.

1. CHOOSE THE FILES
First think of which module you new module is most similar too. In this example, we will make a clone of the “Cash on Delivery” payment module and name it “Cash on Pickup”.

There are generally 6-8 files that need to be cloned for each module, and they follow a similar structure:
1. admin/controller/payment/cod.php
2. admin/language/english/payment/cod.php
3. admin/view/template/payment/cod.tpl
4. catalog/controller/payment/cod.php
5. catalog/language/english/payment/cod.php
6. catalog/model/payment/cod.php
7. catalog/view/theme/default/template/payment/cod.tpl

2. CLONE & EDIT THE FILES
Use your favorite FTP client (like ftp wanderer)
1. Goto the path for each file above
2. download the cod.* file to your local pc (e.g. c:\cop)
3. rename it to “cop” (be sure to note the extension as either .php or .tpl)
4. Use a good (free) text editor like notepad++ to edit the file.
5a. In the notepad++ menu, Goto “Search->Replace…”
– Find what: cod
– Replace with: cop
Click “REPLACE ALL”
5b. For language files, be sure to change wording as appropriate. Example “Cash on Delivery” should be changed to “Cash on Pickup”.
5c. For modules that use underscores (i.e. pp_standard) You must ensure that the class name at the top of the controller & model files does NOT have this _ after doing the replace all.
Correct: class ControllerPaymentPPStandard extends
Incorrect: class ControllerPaymentPP_Standard extends
6. Save the file.
7. Now reupload the new file to the same directory path. Now you should have a cod and cop file next to it.
8. Delete the local file in c:\cop
9. Repeat for each file, one by one.

3. INSTALL THE NEW FILES
Now that we have the new files uploaded, they should likely be seen by the OpenCart payment module system.
1. In the OpenCart Admin section, goto Extension->Payment
2. If everything is right so far, you should see the new “Cash on Pickup” module waiting to be installed
3. Click Install
4. Click Edit. If there are no errors then configure it appropriately. If there are errors, you likely missed a step in the edit. Note what file the error is in and check that file, tracing back your edit steps above
5. Save the configuration
6. Goto the customer checkout process and verify there are no errors. You should see a new Cash on Pickup payment option.

Source: http://forum.opencart.com/viewtopic.php?t=6696

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s