Forums / Built-in Shipping and Payment Modules / Enable PayPal but Only when Product ID 1234 is in cart?

Enable PayPal but Only when Product ID 1234 is in cart?

Started by limelites on 26 Apr 2012, 10:37 PM · Views: 6,147

Results 1 to 20 of 47
26 Apr 2012, 10:37 PM
#1
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Enable PayPal but Only when Product ID 1234 is in cart?

We don't use PayPal generally. However, we would like PayPal to be an option when customers have a specific product ID in their cart. Is there a way to customise the code for this?

Maybe a tweak I could make to \includes\modules\payment\paypalwpp.php ?

27 Apr 2012, 5:52 AM
#2
rodg avatar

rodg

Deceased

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

limelites:

We don't use PayPal generally. However, we would like PayPal to be an option when customers have a specific product ID in their cart. Is there a way to customise the code for this?

There's always a way to customise code :)

limelites:

Maybe a tweak I could make to \includes\modules\payment\paypalwpp.php ?

I can't see why that wouldn't work.

Do a search for threads discussing how to enable/disable specific shipping methods based on particular products. (There are serveral of them).

The same principles would apply for the payment methods... Essentially it involves just setting the "$this->enabled" to be true or false on demand.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

27 Apr 2012, 7:37 AM
#3
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

RodG:

There's always a way to customise code :)

I can't see why that wouldn't work.

Do a search for threads discussing how to enable/disable specific shipping methods based on particular products. (There are serveral of them).

The same principles would apply for the payment methods... Essentially it involves just setting the "$this->enabled" to be true or false on demand.

Cheers
Rod

Hi Rod,

I've searched prior to posting and there's one thread in particular that's useful but it's a closed thread so I can't post a reply there and it's sort of doing the opposite of what I need:

http://www.zen-cart.com/showthread.php?120145-Can-I-restrict-certain-payment-methods-for-certain-products

In the thread above, they're de-activating PayPal on certain products. My problem is that as soon as I activate the PayPal module, it will be active for all 1100 products on the site. I want to activate the PayPal module but immediately have it disabled for all products, unless the product ID is 1234.

So I'm struggling to find a way. Any help would be greatly appreciated.

27 Apr 2012, 8:50 AM
#4
rodg avatar

rodg

Deceased

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

limelites:

it's sort of doing the opposite of what I need:
they're de-activating PayPal on certain products.

My problem is that as soon as I activate the PayPal module, it will be active for all 1100 products on the site. I want to activate the PayPal module but immediately have it disabled for all products, unless the product ID is 1234.

So I'm struggling to find a way. Any help would be greatly appreciated.

It is exactly the same principle, but the logic needs to be reversed.

Near the start of the code wil lbe something like
$this->enabled = ((MODULE_PAYMENT_PAYPAL_STATUS == 'True') ? true : false);

What this is doing is reading the admin configuration setting for the module to set the 'default'. IOW, if MODULE_PAYMENT_PAYPAL_STATUS == 'True' then $this->enabled will be set to 'true'. Otherwise it will be set to false.

Changing $this->enabled at some point after the code above will act as an over-ride for this setting. So, a single line like

$this->enabled = false ;

Will have the same effect as if you had disabled the module from your admin settings.

Now all you need to as add your product check, and if found, set $this->enabled = true ;

Something like:

// enable if products_id 1234 is in the cart
if ($_SESSION['cart']->in_cart_check('products_id','1234') > 0) { $this->enabled = true;}

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

27 Apr 2012, 9:42 AM
#5
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Hi Rod,

I don't have time to try this at the moment as we're just about to leave for the weekend but thank you for the very clear and concise tutorial with a breakdown of the logic and syntax required. You've been really helpful. Thank you!

27 Apr 2012, 10:01 AM
#6
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Update.... Ten minute delay so I gave it a whil but it doesn't seem to work. I enabled PayPal Express in admin, then edited /includes/modules/payment/paypalwpp.php with this:

function paypalwpp() {
include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
global $order;
$this->code = 'paypalwpp';
$this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
$this->codeVersion = '1.3.8a';
$this->enableDirectPayment = (MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED == 'True');
$this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
// disable, (even when admin has it switched on):
$this->enabled = false;
// enable if products_id XXXX is in the cart:
if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) { $this->enabled = true;}

It doesn't seem to do anything, PayPal express is enabled no matte what's in the cart. I think something's missing or not quite right.

27 Apr 2012, 2:31 PM
#7
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Try changing the code for line:

// disable, (even when admin has it switched on):
    $this->enabled = false;
if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) { $this->enabled = true;}

to read:

if (!IS_ADMIN_FLAG) {
  // disable, (even when admin has it switched on):
  $this->enabled = false;
  if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) { 
    $this->enabled = true;
  }
}

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 Apr 2012, 4:11 PM
#8
rodg avatar

rodg

Deceased

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

limelites:

Update.... Ten minute delay so I gave it a whil but it doesn't seem to work..

Please follow any and all suggestions provided by [IMG]http://www.zen-cart.com/image.php?u=5&dateline=1325513042[/IMG] **Ajeh**

The info I gave was 'off the top of my head' with a couple of 'crude' cut and pastes to demonstrate what would be required.

Ajeh on the other hand is the real expert in this type of modification and her advice and suggestions usually produce something fully functional :)

I bow to her expertise every time, without question :)

Cheers
Rod

ps. Thanks for stepping in Ajeh.

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

27 Apr 2012, 4:14 PM
#9
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Always easy to clean up other's code ... especially when pretty close ... :cool:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 Apr 2012, 8:30 AM
#10
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

I've tried and it doesn't work. PayPal option comes up regfardless of the product ID. Here's the link of code:

  function paypalwpp() {
    include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
    global $order;
    $this->code = 'paypalwpp';
    $this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
    $this->codeVersion = '1.3.8a';
    $this->enableDirectPayment = (MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED == 'True');
    $this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
	// disable, even when admin has it switched on:
if (!IS_ADMIN_FLAG) {
  // disable, (even when admin has it switched on):
  $this->enabled = false;
  global $cart;
  if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0) { 
    $this->enabled = true;
  }
}

Maybe I'm editing the wrong file?

30 Apr 2012, 12:46 PM
#11
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Are you having an issue of seeing PayPal in the checkout or on the shopping cart?

This only works in the checkout not the shopping cart ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 Apr 2012, 12:51 PM
#12
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Ajeh:

Are you having an issue of seeing PayPal in the checkout or on the shopping cart?

This only works in the checkout not the shopping cart ...

It's PayPal Express but the issue is on both the login page (where the PPE button appears) **and **on the order confirmation page where the PP radio button appears. So, it's as though the code is not doing anything at all.

30 Apr 2012, 1:31 PM
#13
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Are you trying to make PayPal work when products_id **1395 **is the ONLY product in the cart? Or, when this is one of several Products in the cart?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 Apr 2012, 1:54 PM
#14
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Ajeh:

Are you trying to make PayPal work when products_id **1395 **is the ONLY product in the cart? Or, when this is one of several Products in the cart?

Ideally, when it's the only product in cart. So, if any other product was in the cart, PayPal would not be an option.

30 Apr 2012, 2:02 PM
#15
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Aha! a clue ...

Try this code instead so it checks against the total quantity of Products in the cart to ensure they are all products_id 1395 ...

if (!IS_ADMIN_FLAG) {
  // disable, (even when admin has it switched on):
  $this->enabled = false;
  if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0 && $_SESSION['cart']->count_contents() == $_SESSION['cart']->in_cart_check('products_id','1395')) {
    $this->enabled = true;
  }
}

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 Apr 2012, 2:29 PM
#16
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Hi Linda,

Getting there. It works on main_page=checkout as it takes away the PayPal radio buttonh for all products except 1395. It' s not working on main_page=shopping_cart or main_page=login though. These still give the PayPal Express yellow button. Is there a simple way to apply the same logic to these pages?

30 Apr 2012, 3:40 PM
#17
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Customize the shopping cart template using your templates and overrides with similar code to hide the button based on a similar check ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 Apr 2012, 3:55 PM
#18
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Ajeh:

Customize the shopping cart template using your templates and overrides with similar code to hide the button based on a similar check ...

Thanks Linda. I'll get a look at that later on but thank you for the coding as it's really useful to me.

30 Apr 2012, 4:31 PM
#19
ajeh avatar

ajeh

Oba-san

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

Re: Enable PayPal but Only when Product ID 1234 is in cart?

Thanks for the update ... let us know the final results on this ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

4 May 2012, 9:24 PM
#20
ryanloop avatar

ryanloop

New Zenner

Join Date:
Apr 2012
Posts:
12
Plugin Contributions:
0

Re: Enable PayPal but Only when Product ID 1234 is in cart?

RodG:

Please follow any and all suggestions provided by [IMG]http://www.zen-cart.com/image.php?u=5&dateline=1325513042[/IMG] **Ajeh**

Ajeh on the other hand is the real expert in this type of modification and her advice and suggestions usually produce something fully functional :)

Thanks for the suggestion, I have been following this thread because I have exactly the same problem ... or rather I need to do exactly the same ...

I hope Ajeh can help us... :D

Thanks and regards!