Zen Cart Logo

Disable COD Payment

Views: 2,389

Results 1 to 13 of 13
14 Jun 2014, 11:54 AM
#1
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Disable COD Payment

I am wondering if it is possible to disable the COD Payment method for some customers.
For example, I stand a code at some shipping method so it is not visible when a particular item is in your shopping cart.
I did this with the following code:

      // disable one product for shipping
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','144') > 0)) { 
          $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'False') ? true : false);
      }

Is it possible to use this code in the payment methods?
So that i select on a customers_id.
And I do not want to select a product, but a logged customer.

Is this possible ?

14 Jun 2014, 3:56 PM
#2
yaritai avatar

yaritai

Zen Follower

Join Date:
Apr 2014
Posts:
154
Plugin Contributions:
0

Re: Disable COD Payment

mdo82:

I am wondering if it is possible to disable the COD Payment method for some customers.
For example, I stand a code at some shipping method so it is not visible when a particular item is in your shopping cart.
I did this with the following code:

  // disable one product for shipping
  if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','144') > 0)) { 
      $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'False') ? true : false);
  }
> 
> Is it possible to use this code in the payment methods? 
> So that i select on a customers_id.
> And I do not want to select a product, but a logged customer.
> 
> Is this possible ?

Yes anything is possible with the code.  But you won't use that same code if what you were asking.  You would want to check for "$_SESSION['customer_id']".  If you have alot of customers to do this for then use "in_array($_SESSION['customer_id'], explode(',', 'the,customer,ids,here'))".  And if you wanted to get admin level control, you could add a define in your configuration table so you wouldn't have to go in the files to add more ids or remove some.
14 Jun 2014, 7:02 PM
#3
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

yaritai:

Yes anything is possible with the code. But you won't use that same code if what you were asking. You would want to check for "$_SESSION['customer_id']". If you have alot of customers to do this for then use "in_array($_SESSION['customer_id'], explode(',', 'the,customer,ids,here'))". And if you wanted to get admin level control, you could add a define in your configuration table so you wouldn't have to go in the files to add more ids or remove some.

I did it as follows:

	if (strstr($_SESSION['customers_id'],'3739')){
      $this->enabled = ((MODULE_PAYMENT_COD_STATUS == '') ? true : false); 
	}

This is unfortunately not succeed.
If someone has an idea.
I do want to disable this shipping method for 1 customer

15 Jun 2014, 12:46 PM
#4
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Disable COD Payment

mdo82:

I did it as follows:

if (strstr($_SESSION['customers_id'],'3739')){
  $this->enabled = ((MODULE_PAYMENT_COD_STATUS == '') ? true : false); 
}
> 
> This is unfortunately not succeed. 
> If someone has an idea. 
> I do want to disable this shipping method for 1 customer

Easy fix:  Change
  $this->enabled = ((MODULE_PAYMENT_COD_STATUS == '') ? true : false); 
to 
$this->enabled = false ;  
(leave the rest of you code as-is) 

 
Cheers
RodG
15 Jun 2014, 3:15 PM
#5
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

RodG:

Easy fix: Change
$this->enabled = ((MODULE_PAYMENT_COD_STATUS == '') ? true : false);
to
$this->enabled = false ;
(leave the rest of you code as-is)

Cheers
RodG

Thanks for the information.
Unfortunately will not succeed me.

I change the file /httpdocs/includes/modules/payment/cod.php, but the option remains.
I work probably in the wrong file?

Thanks for the info so far.

15 Jun 2014, 3:42 PM
#6
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Disable COD Payment

mdo82:

Thanks for the information.
Unfortunately will not succeed me.

I change the file /httpdocs/includes/modules/payment/cod.php, but the option remains.
I work probably in the wrong file?

Thanks for the info so far.

It's the right file.

Q1. Where in the code are you placing your additions?

Q2. Have you verified that the check for the customerID is matching? (I suggest changing
if (strstr($_SESSION['customers_id'],'3739')){
to
if (!strstr($_SESSION['customers_id'],'3739')){

.... This will/should cause the opposite to what you want... In other words if the code is working it will disable COD for everyone except customer with the id '3739'

This will verify that the toggle/switch itself is working, which in turn means there is something not working with your customerID check.

Cheers
RodG

15 Jun 2014, 4:03 PM
#7
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

Perhaps I did not quite clearly explained my story.
I want to all have the ability to choose for COD.
However, I want to disable it for one customer with id specified.

In answer to your question, I place it in the next place in my file:

  // $this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);
  // only show COD if Store Pickup
  if (strstr($_SESSION['shipping']['id'],'storepickup')){
  $this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false); 
}
if (strstr($_SESSION['shipping']['id'],'freeshipper')){
  $this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false); 
}

Line 23 - 30 in my file. After this i place my code.

Question 2:
I have verify my customer_id because i use my test-account in the store.

15 Jun 2014, 5:00 PM
#8
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

I see that I have called the wrong file.
It is not the COD, but it is the moneyorder.php.
My mistake, but when I use the following code:

  ```

if (!strstr($_SESSION['customers_id'],'3739')){
$this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'False') ? true : false);
}


With the ! than the option is not showing at all
17 Jun 2014, 7:15 AM
#9
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

mdo82:

I see that I have called the wrong file.
It is not the COD, but it is the moneyorder.php.
My mistake, but when I use the following code:

  ```

if (!strstr($_SESSION['customers_id'],'3739')){
$this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'False') ? true : false);
}

> 
> With the ! than the option is not showing at all

Does anyone have any idea how I can do this?
17 Jun 2014, 9:00 AM
#10
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Disable COD Payment

mdo82:

Does anyone have any idea how I can do this?

I believe that you have us all confused with what you are now trying to achieve and/or where you are headed.

You've told us that you wish to disable the COD module for one customer only, and then you tell us that you've been changing the wrong file and that you are now editing the moneyorder.php file because the cod.php file was a 'mistake'.

And finally you tell us the "the" option isn't showing at all, without any clue as to whether you are still referring to the COD option of the moneyorder option.

The cod.php file controls the COD options.
The moneyorder.php file controls the Money Order options.

Either one of these files will not affect the options provided by the other (which is what you are implying is happening).

What the "!" does is "reverse" the results of any given test or comparison, So

if (!strstr($_SESSION['customers_id'],'3739')){
Do Something
}

Is stating: if customerID isn't '3739' then run the code "Do Something"

and

if (strstr($_SESSION['customers_id'],'3739')){
Do Something
}

Is stating: If customerID iS '3739' then run the code "Do Something"

This means that you'll need to either set the $this->enabled to either 'true' or 'false' (in the "do something" area, depending on your needs).

The code that reads like
$this->enabled = ((MODULE_PAYMENT_XXXXX_STATUS == 'false') ? true : false);

is stating: If the STATUS is set to "false" then set it to "true", otherwise set it to "false".

If you change this to
$this->enabled = ((MODULE_PAYMENT_XXXXX_STATUS == 'false') ? false : true);

is stating: If the STATUS is set to "false" then leave it "false", otherwise set it to "true".

If you change this to
$this->enabled = ((MODULE_PAYMENT_XXXXX_STATUS == 'true') ? false : true);

is stating: If the STATUS is set to "true" then set it to "false", otherwise set it to "true".

and finally:
$this->enabled = ((MODULE_PAYMENT_XXXXX_STATUS == 'true') ? true : false);

is stating: If the STATUS is set to "true" then leave it as "true", otherwise set it to "false".

I realise that this can all be a little confusing if you aren't familiar with the syntax, which is why I suggested that in your case, simply setting
$this->enabled = 'true' or $this->enabled = 'false' (depending on the results of your customerID check) would perhaps be a little easier to understand.

Cheers
RodG

17 Jun 2014, 3:17 PM
#11
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

Thanks for your detailed explanation.
I am indeed begun wrong with this topic.
Now I had my information in the first post to fit, but it will be even more confusing.
Maybe I should start a new topic for clarity?

I will briefly explain what I want to do anything to summarize.
I want to remove the moneyorder option for a customer.

In the beginning of the topic I started about cod, but I had the wrong translation for myself.
The change I would therefore run the file moneyorder.php

If I put the following code in my file:

      if (strstr($_SESSION['customers_id'],'3739')){
	$this->enabled = false;
      }

The option for selecting "moneyorder" is not showing at all if i put (!strstr in the code.
Without the !strstr the option is showing for everyone.
Including for customer 3739.

I hope that now have more clearly put down.
Problem for me also is the translation.

18 Jun 2014, 10:02 AM
#12
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Disable COD Payment

mdo82:

Maybe I should start a new topic for clarity?

No, it's probably best to leave it here,

mdo82:

If I put the following code in my file:

  if (strstr($_SESSION['customers_id'],'3739')){
$this->enabled = false;
  }
> 
> The option for selecting "moneyorder" is not showing at all if i put (!strstr in the code.
> Without the !strstr the option is showing for everyone.
> Including for customer 3739. 

This is telling me that the 'if' check isn't functioning as expected.  

Try this: 
Find the line of code that reads: 
    ```
  $this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'True') ? true : false); 

Then add the following code immediately after it

if(($_SESSION['customer_id']) == "3739")  $this->enabled = false ;  

I've confirmed/verified that this works. There is no need to use 'strstr' because you are looking for an exact match. If you do use the 'strstr' ) and assuming it works) it would also match customerID's '123739' and '3739123' as well as all other customers with '3739' as part (substring) of their Id, which isn't what you want.

Cheers
RodG

18 Jun 2014, 12:18 PM
#13
mdo82 avatar

mdo82

New Zenner

Join Date:
Apr 2010
Posts:
39
Plugin Contributions:
0

Re: Disable COD Payment

RodG:

No, it's probably best to leave it here,

This is telling me that the 'if' check isn't functioning as expected.

Try this:
Find the line of code that reads:
```
$this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'True') ? true : false);

> 
> Then add the following code immediately after it
>    ```
  if(($_SESSION['customer_id']) == "3739")  $this->enabled = false ;  

I've confirmed/verified that this works. There is no need to use 'strstr' because you are looking for an exact match. If you do use the 'strstr' ) and assuming it works) it would also match customerID's '123739' and '3739123' as well as all other customers with '3739' as part (substring) of their Id, which isn't what you want.

Cheers
RodG

Thank you for your clear explanation.
It now works as I want

Thank you!