Tutorial : How to add custom shipping module VirtueMart
by toy
Do you wan to customize your VirtueMart? I use virtuemart quite a lot, not just because it’s free but also it’s good for Joomla. However, when it comes to customize things, there are very little documentation about this. I have been scouting all over the Internet to find a way to customize the shipping module to suit my customers needs. I have found very little details about this. So I decided to do it myself with trials-and-errors method.
Finally, I successfully integrated my customized shipping module for the delivery charge. So I would like to memorise it in my blog.
There is a documentation about this by Virtuemart by it won’t go into any details
http://virtuemart.net/documentation/Developer_Manual/Shipping_Modules.html
First, what you need is a Joomla with virtuemart successfully installed. Then decide what do you want for a delivery charge.
I used I use POSTCODE as an indicator, e.g if the postcode begins with CT it will be £5 other than that will be £10. This is just to start with.
There are many points where you can start but I will start with implementing the shipping module first.
In $JOOMLA_PATH/administrator/components/com_virtuemart/classes/shipping create two files I will name it zone_city_shipping.php and zone_city_shipping.ini.
I suggest you to copy the file zone_shipping.php and zone_shipping.ini and change the file names as above. It will be easier to start with and you can just delete the methods you don’t need.
What you need to change is just the list_rates method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | function list_rates( &$d ) { global $CURRENCY_DISPLAY; $db = new ps_DB; $q = "SELECT city,zip FROM #__{vm}_user_info WHERE "; $q .= "user_info_id='". $d["ship_to_info_id"] . "'"; $db->query($q); $db->next_record(); $city = $db->f("city"); $zip = $db->f("zip"); $first_two_zip = strtolower( substr($zip, 0,2) ); $first_three_zip = strtolower( substr($zip, 0,3) ); $first_four_zip = strtolower( substr($zip, 0,4) ); $message = ""; if($first_three_zip == 'ct5' || $first_three_zip == 'ct6' || $first_three_zip == 'ct2' || $first_three_zip == 'ct4') { $rate = 5.0; $zone_name = ""; $the_zone = "0"; $message = ""; } else if( $first_four_zip == 'me13') { $rate = 5.0; $zone_name = ""; $the_zone = "0"; $message = ""; } else if( $first_two_zip == 'ct') { $rate = 5.0; $zone_name = ""; $the_zone = "0"; $message = "Next day delivery but the order must be placed before 2pm and only Tuesday - Friday"; if( date("D") == 'Sat') { $rate = 25.0; $message = "Saturday delivery but the order must be placed before 2pm on Friday"; } } else { $rate = 10.0; $zone_name = ""; $the_zone = "0"; $message = "Next day delivery but the order must be placed before 2pm and only Tuesday - Friday"; } $rate = $GLOBALS['CURRENCY']->convert( $rate ); // THE ORDER OF THOSE VALUES IS IMPORTANT: // carrier_name|rate_name|totalshippingcosts|rate_id $value = urlencode(__CLASS__."|Zone City Shipping $city|".$rate."|".$the_zone); $_SESSION[$value] = "1"; $string = "<input type=\"radio\" checked=\"checked\" name=\"shipping_rate_id\" value=\"$value\" />"; $string .= "Delivery charge : <strong>". $CURRENCY_DISPLAY->getFullValue($rate )."</strong><br/>"; $string .= "Note: ". $message."<br/>"; $string .= "Sorry we cannot do Sunday delivery for Nation wide delivery"; echo $string; } |
Other method descriptions are described here already
Next go back to folder classes and copy ps_zone.php and change the file name to ps_zone_city. This is the class where you can connect to the database. And change method add, update and delete to suit your requirements. All the examples please have a look at the file I made below.
All the label names and messages are in the folder languages.
The most important thing is don’t forget to create a module and add all of the functions in Virtuemart administrator.
1. In Virtuemart administrator go to Admin -> List Modules and click New to create a new module. Insert module name and click ok.
2. Then click Function Lists behind the module you just created. The functionName should correspond to the method name in file ps_zone_city.php in classes folder. as show in the image below.
File http://www.noppanit.com/code/ps_zone_city.zip


Twitter
Facebook