mhsiao09 Posted February 6, 2008 Share Posted February 6, 2008 As the previous post states, you need to get the name from the class definiton in the module. Jack Sorry for my ignorance, but where can I get this class definition? I've looked at the admin, and it states the title of the payment module...I haven't seen anything that mentions a 'Class' Thanks Link to comment Share on other sites More sharing options...
Jack_mcs Posted February 7, 2008 Share Posted February 7, 2008 Sorry for my ignorance, but where can I get this class definition? I've looked at the admin, and it states the title of the payment module...I haven't seen anything that mentions a 'Class'Thanks Open the file for that module that is in includes/modules/payment/. Near the top will be a line that starts with class. The one for the Check/Money Order module appears asclass moneyorder { so the name of the class is moneyorder. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
mhsiao09 Posted February 7, 2008 Share Posted February 7, 2008 Open the file for that module that is in includes/modules/payment/. Near the top will be a line that starts with class. The one for the Check/Money Order module appears asclass moneyorder { so the name of the class is moneyorder. Jack Thanks, I got it to at least appear now on my checkout page. Now I have another problem that I hope you can help with also. I tested it out, and everything seemed to be working. My payment confirmation pages showed the order total, shipping costs, and then the shipping surcharge costs and then the grand total. Everything loooked good on this page. However, I checked to see if the amount was correct with my gateway credit card processing center, and I noticed that the shipping surcharge was not added on the total even though it showed up on payment confirmation page. I think its either how my sort order is setup or something with the Linkpoint API module. Here is how I have my sort order setup. Sub-total 1 Shipping 2 Tax 3 Discount Coupons 9 ( by the way, this does the same thing. discount is showing up, but doesn't reflect discount in my merchant/gateway account) Gift Vouchers 740 (this doesn't work either by the way) Total 900 Thanks for your help again. Link to comment Share on other sites More sharing options...
Jack_mcs Posted February 8, 2008 Share Posted February 8, 2008 It sounds like a problem in your Linkpoint code. A poster on the first page of this trhead said it works for him and that he uses Linkpoint. You may have a different or out-dated version of Linkpoint. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
Rezolles_Net Posted March 1, 2008 Share Posted March 1, 2008 Dear All, I've been using this contrib for the last few months.However, when I calculated the shipping surcharge (percentage) manually, I found that the amount is not correct. For example. Shipping cost $9 The surcharge is 20% ( so in the admin box write 0.2) But, the shipping surcharge $1.19 which is wrong.20% of $9 is $1.8...Where is other $0.61? FYI,I'm also using payment type charge & MVS with this contrib. Anyone know what exactly the problem?? Thx for the help :blush: Link to comment Share on other sites More sharing options...
sagannon Posted April 24, 2008 Share Posted April 24, 2008 Does this contribution add the surcharge directly into the shipping charge or does it appear separately on its own line on the order total page? Link to comment Share on other sites More sharing options...
HTMLguru2 Posted May 9, 2008 Share Posted May 9, 2008 Does this contribution add the surcharge directly into the shipping charge or does it appear separately on its own line on the order total page? It come set up to charge the fee based on the total. I changed this code to apply only to shipping: Find: function get_order_total() { global $order, $cart; $order_total = $order->info['total']; and change to: function get_order_total() { global $order, $cart; $order_total = $order->info['shipping_cost']; Link to comment Share on other sites More sharing options...
Jack_mcs Posted May 10, 2008 Share Posted May 10, 2008 Dear All, I've been using this contrib for the last few months.However, when I calculated the shipping surcharge (percentage) manually, I found that the amount is not correct. For example. Shipping cost $9 The surcharge is 20% ( so in the admin box write 0.2) But, the shipping surcharge $1.19 which is wrong.20% of $9 is $1.8...Where is other $0.61? FYI,I'm also using payment type charge & MVS with this contrib. Anyone know what exactly the problem?? Thx for the help :blush: I somehow missed this post but if it is still a problem for anyone, it is probably because the code was based on the payment surcharge and that code has a fee it adds. If you look in the includes/modules/order_total/ot_shipsurcharge.php file, you will see this code$od_amount = round($amount*10)/10*$od_pc/100 + .35;//percentage plus base fee Change that to $od_amount = round($amount*10)/10*$od_pc/100; Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
jessegour Posted June 11, 2008 Share Posted June 11, 2008 Hi, I just installed this contribution because I need to charge a surcharge to countries like Canada, Hawaii and Alaska. The rest of the world will be charged just a flat rate. I cant seem to get this working in any of my payment method. In admin I see "Shipping Surcharge" in order total I edit as follows: Display Total true Sort Order 3 Surcharge Percentage 2 Surcharge Flat Charge 10.00 Minimum Amount .01 Payment Type alertpay, moneyorder, banktransfer, paypal, cc Country United States, United Kingdom, Africa, Japan, Indonesia,( I have not added all the other countries; just testing with this) Actually I don't want to charge a surcharge percentage, can I leave it as 0? The files are added as per contribution. I would also prefer the surcharge to be displayed in the invoice so that my customers are aware of the payment before processing their cc. Can someone please help me Link to comment Share on other sites More sharing options...
navyhost Posted August 18, 2008 Share Posted August 18, 2008 Thank you Jack. Glad to talk with you again too, I've been real busy with our brick & mortar store and projects for my 2 sites :) Hope all is well with you and your family! 1st) What I would like to have is multiple surcharges depending on the country. Lets' say, England 10%, Ireland 12%, Spain 14%, Mexico 7% etc. I think this contrib would be over the edge to be able to have multiple countries and rates either by manually editing or even further thru the ACP (major cool!) 2nd) One more thing (sorry to be a pain), I look up to you as an awesome phper (you know way more than me!). Can you take a look at a simple contrib i made and see if there are some tips for it? sLOppY worDs CleaNeR (aka) Sloppy Words Cleaner THANK YOU, looking forward to your advancement on this Shipping Surcharge contrib and critiquing mine :) KJ (top_speed) I really like this idea. I need to add a surcharge to Canada of $9.95 and a surcharge of $35 to all countries except US and Canada. Were you able to complete this successfuly? If you were can I bum the files from you? thx I also noticed a glitch, I had a customer from Canada order, and when they got their receipt, the order total showed the "shipping surcharge" line which was $35. WHich they shouldn't have because it is in my country not to add the surcharge to. The surcharge however wasn't added when they went to pay. Just displayed on the invoice. Sincerely Mike Link to comment Share on other sites More sharing options...
chrish123 Posted March 13, 2009 Share Posted March 13, 2009 Hi Jack, I am in the UK, so instead of a by "country" based surcharge, I would ideally like to do it by "state/county" or first 3 letters of the delivery postcode, this would also mean entering only the states or postcodes I want to add a surcharge to separated by commas in the bottom box. Any idea on how to do this though? I've been trying to hack it the majority of the day, but am pulling my hair out now! ;) Kindest regards Chris Link to comment Share on other sites More sharing options...
Jack_mcs Posted March 13, 2009 Share Posted March 13, 2009 The charge is calcualted in the shipping module file. You will see where it checks for the country. You would have to alter that code to compare against the zip codes. The quick and easy way would be to change this line if (tep_get_country_name($order->delivery['country_id']) == $countries[$i]) to something like if (substr($order->delivery['postcode'], 3)) == $countries[$i]) Then change the countries entered in the module settings in admin to zip codes. I haven't checked that code but it might get you started. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
chrish123 Posted March 13, 2009 Share Posted March 13, 2009 The charge is calcualted in the shipping module file. You will see where it checks for the country. You would have to alter that code to compare against the zip codes. The quick and easy way would be to change this lineif (tep_get_country_name($order->delivery['country_id']) == $countries[$i]) to something like if (substr($order->delivery['postcode'], 3)) == $countries[$i]) Then change the countries entered in the module settings in admin to zip codes. I haven't checked that code but it might get you started. Jack Hi Jack, Thanks for the help! I'll probably try this out tommorow, if not then on monday! I'll report back if all is ok as ive had a few beers now...;) I did try to play with the line you mentioned, and changed to work with the function below but couldnt get it to work. In general.php i have a non standard function added from some addon, the function is called tep_get_zone_name, just a modified version of tep_get_zone_code as below: function tep_get_zone_name($country_id, $zone_id, $default_zone) { $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"); if (tep_db_num_rows($zone_query)) { $zone = tep_db_fetch_array($zone_query); return $zone['zone_name']; } else { return $default_zone; } } That would be ideal to get the name of the state... Thanks! Chris Link to comment Share on other sites More sharing options...
chrish123 Posted March 16, 2009 Share Posted March 16, 2009 The charge is calcualted in the shipping module file. You will see where it checks for the country. You would have to alter that code to compare against the zip codes. The quick and easy way would be to change this lineif (tep_get_country_name($order->delivery['country_id']) == $countries[$i]) to something like if (substr($order->delivery['postcode'], 3)) == $countries[$i]) Then change the countries entered in the module settings in admin to zip codes. I haven't checked that code but it might get you started. Jack Hiya, I took your advice, and I have been playing around with it a lot today, and I nearly have it working, except its only reading the first postcode correctly(if i enter ZE), and then applying the surcharge...then if i change postcode, any other postcode will not apply the surcharge which is good... However if I enter KA as the first 2 letters of the postcode, then it will not apply any surcharge, do you see what I mean? (example: KA comes after ZE) $countries = split("[,]" , "ZE,KA"); Here's what I changed so far: I changed the original function from: function calculate_fee($amount) { global $order, $customer_id, $payment; $countries = split("[,]" , MODULE_SHIPPING_COUNTRY); for ($i = 0; $i < count($countries); $i++) { if (tep_get_country_name($order->delivery['country_id']) == $countries[$i]) return 0; } To this: function calculate_fee($amount) { global $order, $customer_id, $payment; //2 hardcoded test postcodes for now i want to apply the surcharge to $countries = split("[,]" , "ZE,KA"); for ($i = 0; $i < count($countries); $i++) { //below commented line did not work as it complained about bracket placement //if (substr($order->delivery['postcode'], 2)) == $countries[$i]) //read first 2 letters of postcode - I had to modify this to 0, 2 (reads beginning to end) for it to semi work otherwise it dosent work at all if ((substr($order->delivery['postcode'],0 , 2) == $countries[$i])) { //return shipping surcharge if equal to counties array return MODULE_SHIPPING_FLATCHARGE; } else { //otherwise no surcharge... return 0; } } Any help greatly appreciated! Thanks Chris Link to comment Share on other sites More sharing options...
Jack_mcs Posted March 16, 2009 Share Posted March 16, 2009 You're comparing post code (numbers and letters) to countries (ZE, KA). I meant to not change the code for the countriies and just enter in the post code in the module settings, Then let the code break it up as usual. The comparison can then be made between the two. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
chrish123 Posted March 16, 2009 Share Posted March 16, 2009 You're comparing post code (numbers and letters) to countries (ZE, KA). I meant to not change the code for the countriies and just enter in the post code in the module settings, Then let the code break it up as usual. The comparison can then be made between the two. Jack Hi Jack! I'm thinking you may have hopefully read it wrong, as its a little confusing to read ;) The ZE, KA are the first 2 letters of the postcodes I want to exclude in the $countries variable, which could/should also be called $postcodes if you know what I mean! I was under the impression that I was comparing the first 2 letters of the delivery postcode such has "ZE1 2HN" to the $countries variable (which confusingly is now used for grabbing the first 2 letters of the postcode I want to apply the surcharge to). I will change it back to "$countries = split("[,]" , MODULE_SHIPPING_COUNTRY);" so it reads from the database instead of from the file direct, once working... In the original code, this field was used for excluding so instead (i would have to enter the first 2 letters of every postcode in the UK, except the ones I want to exclude.. I just tried to modify it so it only applies the surcharge to the postcodes found in that field. Thanks ;) Chris Link to comment Share on other sites More sharing options...
Jack_mcs Posted March 16, 2009 Share Posted March 16, 2009 Yes, you are correct. I thoughts those were countries. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
chrish123 Posted March 17, 2009 Share Posted March 17, 2009 Hi, Well I still have had no luck in hacking this, it will only read the first postcode successfully, then apply the surcharge, if second postcode one is entered its unrecognised and no surcharge applied <_< Does anyone have any more helpful hints or clues? Kind regards Chris Link to comment Share on other sites More sharing options...
chrish123 Posted March 17, 2009 Share Posted March 17, 2009 Nevermind I have figured it out! ;) It come to me after remembering a question I asked a long time ago and it was answered by FWRmedia here: http://www.ez-oscommerce.com/oscommerce-su...hp-t299278.html His code snippet works great for this purpose! So, Thank you Jack_mcs and Robert Fisher for the help! it was greatly appreciated! I'll upload it as a contribution when I have tweaked it, as it isnt ready just yet. I'm sure a lot of people would like this if based in the UK, as a surcharge can then be charged to the channel islands, ireland, isle of man, isles of scilly, sheland islands and other non uk mainland areas. Kindest regards Chris Link to comment Share on other sites More sharing options...
chrish123 Posted March 17, 2009 Share Posted March 17, 2009 Well I spoke to soon as I'm now getting this happening, even though its applying the surcharge correctly: Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 6 in C:\xampp\htdocs\www\includes\modules\order_total\ot_shipsurcharge.php on line 68 Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 5 in C:\xampp\htdocs\www\includes\modules\order_total\ot_shipsurcharge.php on line 68 Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 6 in C:\xampp\htdocs\www\includes\modules\order_total\ot_shipsurcharge.php on line 68 Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 6 in C:\xampp\htdocs\www\includes\modules\order_total\ot_shipsurcharge.php on line 68 If anyone wants to test, I changed in the original module: FIND: function calculate_fee($amount) { global $order, $customer_id, $payment; $countries = split("[,]" , MODULE_SHIPPING_COUNTRY); for ($i = 0; $i < count($countries); $i++) { if (tep_get_country_name($order->delivery['country_id']) == $countries[$i]) return 0; } REPLACE WITH: function calculate_fee($amount) { global $order, $customer_id, $payment; //start of mod $postcode = $order->delivery['postcode']; //postcode ranges to apply surcharge to $pre1 = "/JE[1-4]/"; //Jersey $pre2 = "/GY[1-9]/"; //Guernsey $pre3 = "/HS[1-9]/"; //Outer Hebrides $pre4 = "/IV[1-36]/"; //Inverness $pre5 = "/IV[40-56]/"; //Inverness continued $pre6 = "/KA[27-28]/"; //Kilmarnock postcode area $pre7 = "/KW[1-3]/"; //Kirkwall postcode area $pre8 = "/KW[5-17]/"; //Kirkwall postcode area continued $pre9 = "/PA[20-49]/"; //Paisley postcode area $pre10 = "/PA[60-78]/"; //Paisley postcode area continued $pre11 = "/PH[17-26]/"; //Perth postcode area continued $pre12 = "/PH[30-44]/"; //Perth postcode area continued $pre13 = "/PH[49-50]/"; //Perth postcode area continued $pre14 = "/ZE[1-3]/"; //Lerwick postcode area (shetland) continued $pre15 = "/BT[1-99]/"; //Belfast Northern Ireland postcode area $pre16 = "/IM[1-9]/"; //Isle of Man postcode area $pre17 = "/IM[86-87]/"; //Isle of Man postcode area $pre18 = "/IM[99-100]/"; //Isle of Man postcode area continued $pre19 = "/TR[21-25]/"; //Isles of Scilly postcode area //read first 3 letters of postcode if ( preg_match($pre1, strtoupper(substr($postcode , 0, 3))) || preg_match($pre2, strtoupper(substr($postcode, 0, 3))) || preg_match($pre3, strtoupper(substr($postcode, 0, 3))) || preg_match($pre4, strtoupper(substr($postcode, 0, 3))) || preg_match($pre5, strtoupper(substr($postcode, 0, 3))) || preg_match($pre6, strtoupper(substr($postcode, 0, 3))) || preg_match($pre7, strtoupper(substr($postcode, 0, 3))) || preg_match($pre8, strtoupper(substr($postcode, 0, 3))) || preg_match($pre9, strtoupper(substr($postcode, 0, 3))) || preg_match($pre10, strtoupper(substr($postcode, 0, 3))) || preg_match($pre11, strtoupper(substr($postcode, 0, 3))) || preg_match($pre12, strtoupper(substr($postcode, 0, 3))) || preg_match($pre13, strtoupper(substr($postcode, 0, 3))) || preg_match($pre14, strtoupper(substr($postcode, 0, 3))) || preg_match($pre15, strtoupper(substr($postcode, 0, 3))) || preg_match($pre16, strtoupper(substr($postcode, 0, 3))) || preg_match($pre17, strtoupper(substr($postcode, 0, 3))) || preg_match($pre18, strtoupper(substr($postcode, 0, 3))) || preg_match($pre19, strtoupper(substr($postcode, 0, 3))) ) { // True - then apply surcharge return MODULE_SHIPPING_FLATCHARGE; } // False - then dont apply surcharge return 0; //end of mod There seems to be a problem in how many " preg_match($pre1, strtoupper(substr($postcode , 0, 3))) " compares there are as it worked fine with only 2... As I said the code works, but that error message is driving me crazy! If anyone has any tips I'd be grateful! Kind regards Chris Link to comment Share on other sites More sharing options...
chrish123 Posted March 17, 2009 Share Posted March 17, 2009 There seems to be a problem in how many " preg_match($pre1, strtoupper(substr($postcode , 0, 3))) " compares there are.... as it worked fine with only 2... As I said the code works, but that error message is driving me crazy! It begins to error after 5 of the above "compares"... even though it works fine.. Link to comment Share on other sites More sharing options...
chrish123 Posted March 17, 2009 Share Posted March 17, 2009 It begins to error after 5 of the above "compares"... even though it works fine.. I managed to suppress the error messages as the code works fine (but why is it erroring?) I just changed the code from: function calculate_fee($amount) { global $order, $customer_id, $payment; //start of mod $postcode = $order->delivery['postcode']; //postcode ranges to apply surcharge to $pre1 = "/JE[1-4]/"; //Jersey $pre2 = "/GY[1-9]/"; //Guernsey $pre3 = "/HS[1-9]/"; //Outer Hebrides $pre4 = "/IV[1-36]/"; //Inverness $pre5 = "/IV[40-56]/"; //Inverness continued $pre6 = "/KA[27-28]/"; //Kilmarnock postcode area $pre7 = "/KW[1-3]/"; //Kirkwall postcode area $pre8 = "/KW[5-17]/"; //Kirkwall postcode area continued $pre9 = "/PA[20-49]/"; //Paisley postcode area $pre10 = "/PA[60-78]/"; //Paisley postcode area continued $pre11 = "/PH[17-26]/"; //Perth postcode area continued $pre12 = "/PH[30-44]/"; //Perth postcode area continued $pre13 = "/PH[49-50]/"; //Perth postcode area continued $pre14 = "/ZE[1-3]/"; //Lerwick postcode area (shetland) continued $pre15 = "/BT[1-99]/"; //Belfast Northern Ireland postcode area $pre16 = "/IM[1-9]/"; //Isle of Man postcode area $pre17 = "/IM[86-87]/"; //Isle of Man postcode area $pre18 = "/IM[99-100]/"; //Isle of Man postcode area continued $pre19 = "/TR[21-25]/"; //Isles of Scilly postcode area //read first 3 letters of postcode if ( preg_match($pre1, strtoupper(substr($postcode , 0, 3))) || preg_match($pre2, strtoupper(substr($postcode, 0, 3))) || preg_match($pre3, strtoupper(substr($postcode, 0, 3))) || preg_match($pre4, strtoupper(substr($postcode, 0, 3))) || preg_match($pre5, strtoupper(substr($postcode, 0, 3))) || preg_match($pre6, strtoupper(substr($postcode, 0, 3))) || preg_match($pre7, strtoupper(substr($postcode, 0, 3))) || preg_match($pre8, strtoupper(substr($postcode, 0, 3))) || preg_match($pre9, strtoupper(substr($postcode, 0, 3))) || preg_match($pre10, strtoupper(substr($postcode, 0, 3))) || preg_match($pre11, strtoupper(substr($postcode, 0, 3))) || preg_match($pre12, strtoupper(substr($postcode, 0, 3))) || preg_match($pre13, strtoupper(substr($postcode, 0, 3))) || preg_match($pre14, strtoupper(substr($postcode, 0, 3))) || preg_match($pre15, strtoupper(substr($postcode, 0, 3))) || preg_match($pre16, strtoupper(substr($postcode, 0, 3))) || preg_match($pre17, strtoupper(substr($postcode, 0, 3))) || preg_match($pre18, strtoupper(substr($postcode, 0, 3))) || preg_match($pre19, strtoupper(substr($postcode, 0, 3))) ) { // True - then apply surcharge return MODULE_SHIPPING_FLATCHARGE; } // False - then dont apply surcharge return 0; //end of mod To: function calculate_fee($amount) { global $order, $customer_id, $payment; //start of mod $postcode = $order->delivery['postcode']; //postcode ranges to apply surcharge to $pre1 = "/JE[1-4]/"; //Jersey $pre2 = "/GY[1-9]/"; //Guernsey $pre3 = "/HS[1-9]/"; //Outer Hebrides $pre4 = "/IV[1-36]/"; //Inverness $pre5 = "/IV[40-56]/"; //Inverness continued $pre6 = "/KA[27-28]/"; //Kilmarnock postcode area $pre7 = "/KW[1-3]/"; //Kirkwall postcode area $pre8 = "/KW[5-17]/"; //Kirkwall postcode area continued $pre9 = "/PA[20-49]/"; //Paisley postcode area $pre10 = "/PA[60-78]/"; //Paisley postcode area continued $pre11 = "/PH[17-26]/"; //Perth postcode area continued $pre12 = "/PH[30-44]/"; //Perth postcode area continued $pre13 = "/PH[49-50]/"; //Perth postcode area continued $pre14 = "/ZE[1-3]/"; //Lerwick postcode area (shetland) continued $pre15 = "/BT[1-99]/"; //Belfast Northern Ireland postcode area $pre16 = "/IM[1-9]/"; //Isle of Man postcode area $pre17 = "/IM[86-87]/"; //Isle of Man postcode area $pre18 = "/IM[99-100]/"; //Isle of Man postcode area continued $pre19 = "/TR[21-25]/"; //Isles of Scilly postcode area //read first 3 letters of postcode if ( @preg_match($pre1, strtoupper(substr($postcode , 0, 3))) || @preg_match($pre2, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre3, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre4, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre5, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre6, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre7, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre8, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre9, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre10, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre11, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre12, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre13, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre14, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre15, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre16, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre17, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre18, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre19, strtoupper(substr($postcode, 0, 3)))) { // True - then apply surcharge return MODULE_SHIPPING_FLATCHARGE; } // False - then dont apply surcharge return 0; //end of mod Link to comment Share on other sites More sharing options...
chrish123 Posted March 20, 2009 Share Posted March 20, 2009 Well I'm sorry, but the above code's regex syntax isnt right, it would not check the codes properly, so heres a almost perfect corrected version ,that seems to work fine except the: $pre19 = "/^IM[1-9]$/"; This seems to conflict with the IM Post code regex after ($pre17 to $pre18 which seems correct) unless I comment this line out!, but i need to have this line as i need to apply the surcharge to postcodes IM1 to 9. I checked the rest of the syntax and it works.. I'd also like to not apply the surcharge to these postcodes, if the order weight is below 3 kilo's, any ideas on how to go about this? function calculate_fee($amount) { global $order, $customer_id, $payment; //start of PC mod $postcode = $order->delivery['postcode']; //postcode ranges to apply surcharge to $pre1 = "/^JE[1-4]$/"; //Jersey $pre2 = "/^GY[1-9]$/"; //Guernsey $pre3 = "/^HS[1-9]$/"; //Outer Hebrides $pre4 = "/^IV[1-9]$/"; //Inverness $pre5 = "/^IV([1-3][0-6]|17|18|19|27|28|29)$/"; //Inverness 10-36 OK $pre6 = "/^IV([4-5][0-6]|47|48|49)$/"; //Inverness continued 40-56 //ok! $pre7 = "/^KA[2][7-8]$/"; //Kilmarnock postcode area 27-28 $pre8 = "/^KW[1-3]$/"; //Kirkwall postcode area $pre9 = "/^KW[5-9]$/"; //Kirkwall postcode area continued $pre10 = "/^KW[1][0-7]$/"; //Kirkwall postcode area continued 10-17 $pre11 = "/^PA[2-4][0-9]$/"; //Paisley postcode area 20-49 OK $pre12 = "/^PA([6-7][0-8]|69)$/"; //Paisley postcode area continued 60-78 should be ok $pre13 = "/^PH([1-2][0-6]|17)$/"; //Perth postcode area continued 17-26 should be ok $pre14 = "/^PH([3-4][0-4]|35|36|37|38|38|39)$/"; //Perth postcode area continued 30-44 $pre15 = "/^PH(49|50)$/"; //Perth postcode area continued 49-50 $pre16 = "/^ZE[1-3]$/"; //Lerwick postcode area (shetland) continued $pre17 = "/^BT[1-9]$/"; //Belfast Northern Ireland postcode area $pre18 = "/^BT[1-9][0-9][10-99]$/"; //Belfast Northern Ireland postcode area 10-99 $pre19 = "/^IM[1-9]$/"; //Isle of Man postcode area 1-9 wtf? this one causes the others below not to work correctly... $pre20 = "/^IM[8][6-7]$/"; //Isle of Man postcode area 86-87 $pre21 = "/^IM[9][9]$/"; //Isle of Man postcode area continued 99-100 $pre22 = "/^TR[2][1-5]$/"; //Isles of Scilly postcode area 21-25 //read first 3 or 4 letters of postcode if ( @preg_match($pre1, strtoupper(substr($postcode , 0, 3))) || @preg_match($pre2, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre3, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre4, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre5, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre6, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre7, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre8, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre9, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre10, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre11, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre12, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre13, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre14, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre15, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre16, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre17, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre18, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre19, strtoupper(substr($postcode, 0, 3))) || @preg_match($pre20, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre21, strtoupper(substr($postcode, 0, 4))) || @preg_match($pre22, strtoupper(substr($postcode, 0, 4))) ) { // True - then apply surcharge return MODULE_SHIPPING_FLATCHARGE_PCUK; } // False - then dont apply surcharge return 0; //end of PC mod If anyone at all can give me some pointers on the regex syntax, or the weight theory then It would be very much appreciated! Thanks Chris Link to comment Share on other sites More sharing options...
chrish123 Posted March 23, 2009 Share Posted March 23, 2009 The code above wasnt correct, I have fixed it today, and its all in working order! Please download at: http://addons.oscommerce.com/info/2677 Use at your own risk! Regards Chris Link to comment Share on other sites More sharing options...
catcher55 Posted July 11, 2009 Share Posted July 11, 2009 I think the name of this mod is wrong. It says shipping srucharge but it's based on payment method and not shipping method. How can I change code to charge fee based on shipping method? For example if shipping method DHL then add 20% surcharge? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.