Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Need some Help in COD. COD fee depending on order price

Need some Help in COD. COD fee depending on order price

Views: 2,830

Results 1 to 20 of 21
13 Aug 2012, 8:05 PM
#1
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Need some Help in COD. COD fee depending on order price

Hi,
I am new to zencart and need some help from Zencart gurus here. Pls help me.

I want to take some fees say $5 for COD for orders below 500 and above that COD fees will be free i.e. 0.

Pls help me in setting it. The COD fee (0 or the value $5) should be reflected in the order / invoice etc if the COD payment mode is used.

Now before that I need another check as I am planning to make COD available to only few zipcodes in a particular area.
I have a table with columns Sl,zipcodes, city,area, serviceable. the serviceable contains YES or NO.

Now I need to check first if the shipping (current address) zipcode is serviceable or not. if not it will just display "COD not available for your zipcode or the zipcode entered is wrong" (if the zipcode is not found in database). Also making the COD option read only. If the zipcode is serviceable the COD option will work normally.

Thankyou in advance.

15 Aug 2012, 6:21 AM
#2
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

pls help me friends

15 Aug 2012, 6:41 AM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need some Help in COD. COD fee depending on order price

The logic for handling zone validation is in the update_status() function/method of the COD module file.
You can add your additional logic for your custom zone restrictions and your pricing changes to that section as well.

15 Aug 2012, 11:59 AM
#4
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

its not about the zone.

I need to look up in the table for the zipcode entered during checkout in the shipping address and show the cod option after checking if the zipcode entered is serviceable or not. Actually, in a zone many zipcodes will not be serviceable.

16 Aug 2012, 2:40 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need some Help in COD. COD fee depending on order price

Right. But your specialized logic for certain zip codes is the exact same concept as the builtin broader zone-based restrictions. Thus adding your custom logic to that same section of the code would the logical way to implement it.

16 Aug 2012, 3:31 AM
#6
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

thanks buddy. Actually I am bit novice in programming, pls give me a refrence where I need to change the code. like the file name & code section. will give it a try.

16 Aug 2012, 4:08 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need some Help in COD. COD fee depending on order price

DrByte:

The logic for handling zone validation is in the update_status() function/method of the COD module file.
You can add your additional logic for your custom zone restrictions and your pricing changes to that section as well.
/includes/modules/payment/cod.php

17 Aug 2012, 4:31 AM
#8
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

should I edit that code with the zipcode database part

17 Aug 2012, 6:45 AM
#9
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,874
Plugin Contributions:
7

Re: Need some Help in COD. COD fee depending on order price

What I did was consider COD to be a shipping option, since the carriers (Postal Service, Couriers..) have different fee structures for the different shipping services and this is all easily managed by Advanced Shipper (comercial module) which will do the zipcode filtering you want.
Then, when a COD shipping service is selected, I disable the other payment options on the payment page to stop the idiots paying by another method again.

18 Aug 2012, 3:26 AM
#10
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

@torvista : thanks buddy for the much needed information. it really helped. God Bless

14 Sep 2012, 5:37 PM
#11
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

how do I disable other payment options when COD is enabled

14 Sep 2012, 7:09 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need some Help in COD. COD fee depending on order price

Just like you've made custom coding changes for your COD module, you'll need to make similar changes in all the other modules who you want to automatically alter their availability based on similar criteria.

14 Sep 2012, 9:53 PM
#13
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,874
Plugin Contributions:
7

Re: Need some Help in COD. COD fee depending on order price

Each payment module has a name ie: moneyorder.php
Near the start of the code in the file there is the declaration //class constructor followed by

function moneyorder() {
some code
}

Put this code just before that closing } to disable the payment for whatever reason you like
eg in this case when $_SESSION['payment'] == 'cod'.

if (IS_ADMIN_FLAG == false && $_SESSION['payment'] == 'cod') {$this->enabled = false;}

And to reiterate the previous post you'll need to put this into each of the payment modules you normally use and want to disable.

14 Sep 2012, 10:06 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need some Help in COD. COD fee depending on order price

torvista's right.
And I would add the following:

Note that $_SESSION['payment'] will only be set to 'cod' if something has taken place to cause it to be selected/set ... such as the customer arriving at the payment choices screen and choosing cod and submitting the form. Until then the variable won't be set, so other modules won't be able to respond to that ... which makes the whole exercise rather pointless unless you're regularly having customers returning to the payment-choices screen after they've already gone thru that stage ... which then begs the question of "why is that happening?".

14 Sep 2012, 10:43 PM
#15
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,874
Plugin Contributions:
7

Re: Need some Help in COD. COD fee depending on order price

Yes, somewhere in Advanced Shipper (a very long time ago) I added a hack to set the session payment variable to cod when a shipping option based on cod is selected, prior to getting to the payment selection screen....don't ask me to find where unless you are really stuck!

Note this thread is becoming a discussion of what I did, which may not be necessary for your needs.
I did it this way to be able to use the tremendous flexibility of Advanced Shipper to calculate the surcharge/commission charged by the courier for cod and have it show up in the shipping estimator.
Works for me, but may be too nitpicking for others.

15 Sep 2012, 8:57 AM
#16
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

@torvista: its the same for me, I used the advanced shipper as you had suggested.

My courier charges extra fees depending on COD address and that to limited pin codes. Now the problem is that after installing the advanced shipper and in shipping page the COD is selected, it again asks for payment in the next page. thus I want to disable only the payment part when COD is selected as shipping. cos disabling the total payment page, will disable coupon, gvs etc.

kindly help and my bad that I am weak in coding.

cant we use the session for shipping and check

15 Sep 2012, 2:53 PM
#17
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,874
Plugin Contributions:
7

Re: Need some Help in COD. COD fee depending on order price

You need to identify when a cod-based shipping method has been chosen on the shipping page so you can set the $_SESSION['payment'] variable as the payment page is loaded and then the payment methods self-disable.

This is what I did, not necessarily the best way...I vaguely remember having trouble getting this to work in multiple languages (it was early days for me and php...) as I was trying to trap the title of the method selected (since the shipping module is always Advanced Shipper).

So I added the check into /includes/modules/pages/checkout_payment/header_php.php/ just before this

// $_SESSION['comments'] = '';

if ((strlen(strstr(strtolower($_SESSION['shipping']['title']),MODULE_PAYMENT_COD_SHIPPING_KEYWORD_EN))>0)||(strlen(strstr($_SESSION['shipping']['title'],MODULE_PAYMENT_COD_SHIPPING_KEYWORD_ES))>0)) {
$_SESSION['payment'] = 'cod';
}
else {$_SESSION['payment'] = '';}

As $_SESSION['shipping']['title'] various between languages I added new defines with a keyword to look for
ie
for english (in \includes\languages\english\extra_definitions\my_extra_defines.php
define('MODULE_PAYMENT_COD_SHIPPING_KEYWORD_EN','cash')

for spanish (in \includes\languages\spanish\extra_definitions\my_extra_defines.php
define('MODULE_PAYMENT_COD_SHIPPING_KEYWORD_ES','reembolso');

Seems clumsy now, but its worked ok for two years.

15 Sep 2012, 7:25 PM
#18
bratsangels avatar

bratsangels

New Zenner

Join Date:
Jul 2012
Posts:
19
Plugin Contributions:
0

Re: Need some Help in COD. COD fee depending on order price

you mean to say that you ceated a new definition " define('MODULE_PAYMENT_COD_SHIPPING_KEYWORD_EN','cash') " and saved it as my_extra_defines.php

I did the same but " define('MODULE_PAYMENT_COD_SHIPPING_KEYWORD_EN','cash') " is shoed in the header part of the store.

15 Sep 2012, 7:32 PM
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need some Help in COD. COD fee depending on order price

If you created a new PHP file for it, you need to start that file with: <?php

16 Sep 2012, 6:56 AM
#20
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,874
Plugin Contributions:
7

Re: Need some Help in COD. COD fee depending on order price

you mean to say that you ceated a new definition " define('MODULE_PAYMENT_COD_SHIPPING_KEYWORD_EN','cash') " and saved it as my_extra_defines.php

I created the new constant in a new file with a personalised name to make it obvious when upgrading that its an additional file to the stock fileset. You can name it anything to make it stand out for you.

If you add your own constants in the language files there are usually several places you can put them and they will work. I prefer to put them all in one file: my_extra_defines.php

If you are still getting this error, copy any language file to the location I specified, rename it, delete the existing constants bar one, edit that one.