Post by Qphoria » Tue Apr 12, 2011 12:08 pm

Shipping extensions can be created by cloning an existing one that does something similar to what you want.

For Example, If you want to make DHL shipping rates mod using live rate lookup from the DHL site, I would start with the existing UPS shipping extension. If creating a special case scenario based on static table rates, then try cloning the weight based shipping. For this example I will use the UPS files for a new DHL extension.

1. Clone the Files
Shipping extensions in their MVC layout have a minimum of 5 files:

Code: Select all

Copy all the UPS files and name the new ones dhl.php. Be sure you have the same folder structure

2. Global Replaces:
In most cases, you can usually use a good editor like notepad++ to do a "Replace in Files" and simply run that twice for lower and uppercase wording separately:
- replace the word "ups" with "dhl"
- replace the word "UPS" with "DHL"
The upper case only applies to the main class extends (e.g. ModelShippingUPS). In some cases where there are underscores in the main name, like "royal_mail", note that the uppercase version will NOT likely have the underscore. e.g. replace "royal_mail" with "my_mod" but replace "RoyalMail" with "MyMOD"

3. Setup the Admin side
I always start on the admin side first...
- Setup the username/password/developer keys etc fields that the extension will need to access the API
- Setup any fees or special settings for things like insurance, discounted rates, detailed origin information, etc
The admin/controller/shipping/dhl.php file handles all the form and variable control.
The admin/language/english/shipping/dhl.php file shows the text values for the different fields. You can clone and translate this file for any language.
The admin/view/template/shipping/dhl.tpl file is the html file that shows the actual form for configuring the extension settings. These all work together to form the page. You should be able to follow the existing ups code and modify only parts of it to make it work for dhl

4. Setup the Catalog side
After the admin is setup and working, it is easier to test as you code on the catalog side. The catalog/language/english/shipping/dhl.php file will have mainly special error scenarios and the title of the shipping extension as you want to show it in which ever languages you support. The catalog/model/shipping/dhl.php file will have all the code logic. Use your shipping company's API document to set up what you need for the extension here. It will of course require you know some advanced php at this point.

That's it. Step 4 is where most of the work gets done, but with the first 3 steps done, it makes it easier to test as you go.

If you have other advice to make this tutorial clearer and easier to understand, or if you think I missed a step, please PM me with tips.

OpenCart 2.0.x Mod Update Info

Donate!|OpenCart Basics|GeoZones

User avatar


Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 2 guests