Zen Cart Logo
Forums / General Questions / Display one payment option based on shipping

Display one payment option based on shipping

Views: 878

Results 1 to 10 of 10
23 Jun 2013, 9:11 AM
#1
coopco avatar

coopco

New Zenner

Join Date:
Jun 2006
Location:
Sea Lake, Australia
Posts:
81
Plugin Contributions:
0

Display one payment option based on shipping

I have modified check/money order as a payment option (called pickupnpay) and want it to be the only payment option to display when a customer selects opts to order on line and pay in store (shoppickup) as a shipping method?

For all other shipping options, I still require all payment options to appear (paypal and check/money order).

Is there a way of using something like conditional statements (or another way) in the new shipping or payment module to prevent the other payment modules from being displayed as options without having to edit the other payment modules?

Alternatively, can the pickupnpay module be coded to skip the payment stage of the check out process?

Any help or tips would be appreciated.

23 Jun 2013, 9:54 PM
#2
torvista avatar

torvista

Totally Zenned

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

Re: Display one payment option based on shipping

The key to disabling/hiding a payment method is making $this->enabled = false in the module you want to hide.
This example is from the cod payment module.

if ($check_flag == false) {
$this->enabled = false;
}

Stuff your conditional code in there to make it false when you want to hide it.

For example I use COD as shipping option as it incurs extra shipping charges by the courier so I only allow the COD payment option (and no others) to show up when COD has been selected for shipping on the payment page:

if (IS_ADMIN_FLAG == false && $_SESSION['payment'] == 'cod') {
$this->enabled = true;
} else {
$this->enabled = false;
}
24 Jun 2013, 5:12 AM
#3
coopco avatar

coopco

New Zenner

Join Date:
Jun 2006
Location:
Sea Lake, Australia
Posts:
81
Plugin Contributions:
0

Re: Display one payment option based on shipping

Thanks for replying Torvista. Not quite what I need.

I have the Shop Pickup disabled for all but certain post codes that entered via admin. When a customer selects the Shop Pickup shipping option if it is available for their post code, I want to have only one payment option available to them (ie pay by cash or cheque or by card), which they do when they pick up the item ordered.

25 Jun 2013, 4:03 AM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Display one payment option based on shipping

This should turn off a payment module if a given payment module is set ...

This examples is for the shipping module Store Pickup being picked and wanting the Money Order disabled by adding the code in RED:

      $this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'True') ? true : false);

      if ((int)MODULE_PAYMENT_MONEYORDER_ORDER_STATUS_ID > 0) {
        $this->order_status = MODULE_PAYMENT_MONEYORDER_ORDER_STATUS_ID;
      }

      if (is_object($order)) $this->update_status();
[B]// bof: turn off payment module if store pickup is enabled
echo 'Payment Module sees: ' . $_SESSION['shipping']['id'] . '<br>';
if (!IS_ADMIN_FLAG && $_SESSION['shipping']['id'] == 'storepickup_storepickup') {
  $this->enabled = false;
}
// eof: turn off payment module if store pickup is enabled
[/B]
      $this->email_footer = MODULE_PAYMENT_MONEYORDER_TEXT_EMAIL_FOOTER;
25 Jun 2013, 4:32 AM
#5
coopco avatar

coopco

New Zenner

Join Date:
Jun 2006
Location:
Sea Lake, Australia
Posts:
81
Plugin Contributions:
0

Re: Display one payment option based on shipping

Thanks for replying Linda.

I used

  if (is_object($order)) $this->update_status();
  
  if (strstr ($_SESSION['shipping']['id'], 'shoppickup')) {
    $this->enabled = ((MODULE_PAYMENT_PICKUPNPAY_STATUS == 'True') ? true : false);
  }  

  $this->email_footer = MODULE_PAYMENT_PICKUPNPAY_TEXT_EMAIL_FOOTER;
}

To turn on the new payment module when my shop pickup shipping module is selected. That works well.

I am just after a way to hide all other payment options and use only my pick up and pay module.

Now I have been thinking that if the pickup and pay could automatically be selected and the process moves to the checkout confirmation page without the customer seeing the payment page, then I would not have to hide all of the other payment options (although this would not enable the customer to use any discount coupons).

25 Jun 2013, 5:54 AM
#6
coopco avatar

coopco

New Zenner

Join Date:
Jun 2006
Location:
Sea Lake, Australia
Posts:
81
Plugin Contributions:
0

Re: Display one payment option based on shipping

OK, this seems to work.

Edited includes/classes/payment.php

to be

    // Pickup N Pay Payment Only shows
    if (zen_get_configuration_key_value('MODULE_PAYMENT_PICKUPNPAY_STATUS') and (strstr ($_SESSION['shipping']['id'], 'shoppickup'))) {
      $this->selected_module = $module;
      if (file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . '/payment/' . 'pickupnpay.php')) {
        $include_modules[] = array('class'=> 'pickupnpay', 'file' => 'pickupnpay.php');
      }
    } else {
    // Free Payment Only shows

and just added another closing curly bracket.

Does this look like an ok option?

25 Jun 2013, 2:43 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Display one payment option based on shipping

Could you zip your payment module and attach it, as it would be easier to be able to see the whole file than just a piece ...

26 Jun 2013, 2:01 AM
#8
coopco avatar

coopco

New Zenner

Join Date:
Jun 2006
Location:
Sea Lake, Australia
Posts:
81
Plugin Contributions:
0

Re: Display one payment option based on shipping

No problems Linda. Thanks for your interest.

There are 2 Shipping Modules and one Payment Module.

The plan is to have customers in the local area order on-line and pay and pick-up in the physical shop, and customers from further away can order and pay on-line and pick-up from the physical shop.

All other shipping options and payment options are still available, unless the customer chooses (if it is available for them, decided by their post code) to order on-line and pay and pick-up in the shop.

26 Jun 2013, 2:53 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Display one payment option based on shipping

Usually I do not touch the payment class and just control everything in the payment modules ...

You have in your payment module for picknpay,php

      if (is_object($order)) $this->update_status();
      
[B]      if (strstr ($_SESSION['shipping']['id'], 'shoppickup')) {
        $this->enabled = ((MODULE_PAYMENT_PICKUPNPAY_STATUS == 'True') ? true : false);
      }  
[/B]
      $this->email_footer = MODULE_PAYMENT_PICKUPNPAY_TEXT_EMAIL_FOOTER;

For example. in the Payment module for moneyorder.php more or less you then use similar logic in your other payment modules but reverse the logic ...

      if (is_object($order)) $this->update_status();
[B]// bof: turn off payment module if shoppickup is enabled or picknpay
//echo 'Payment Module sees: ' . $_SESSION['shipping']['id'] . '<br>';
      if (!IS_ADMIN_FLAG && strstr ($_SESSION['shipping']['id'], 'shoppickup')) {
        $this->enabled = false;
      }  
      if (!IS_ADMIN_FLAG && strstr ($_SESSION['shipping']['id'], 'picknpay')) {
        $this->enabled = false;
      }  
// eof: turn off payment module if store pickup is enabled
[/B]

NOTE: this is without using any changes to the payment.php class file ...

28 Jun 2013, 1:43 AM
#10
coopco avatar

coopco

New Zenner

Join Date:
Jun 2006
Location:
Sea Lake, Australia
Posts:
81
Plugin Contributions:
0

Re: Display one payment option based on shipping

Thanks again Linda for your wonderful input.

I can understand why you are reluctant to change the payment class.

I will leave it at that for now. I have more pressing issues ATM.