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 21 to 40 of 47
4 May 2012, 10:14 PM
#21
ajeh avatar

ajeh

Oba-san

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

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

See post #15 for how to do this ...

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!

8 Apr 2013, 6:23 PM
#22
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?

If you're still watching this Ajeh, I have a quick question for you.

This works a treat when I just want PayPal to show when only product ID 1395 is in the cart and nothing else:

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 && $_SESSION['cart']->count_contents() == $_SESSION['cart']->in_cart_check('products_id','1395')) {
    $this->enabled = true;
  }
}

How would I tweak this code so that PayPal becomes an option when product ID 1395 is in the cart and any other product is also in the cart alongside it?

8 Apr 2013, 7:04 PM
#23
drbyte avatar

drbyte

Sensei

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

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

limelites:

If you're still watching this Ajeh, I have a quick question for you.

This works a treat when I just want PayPal to show when only product ID 1395 is in the cart and nothing else:

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 && $_SESSION['cart']->count_contents() == $_SESSION['cart']->in_cart_check('products_id','1395')) {
$this->enabled = true;
}
}

> 
> How would I tweak this code so that PayPal becomes an option when product ID 1395 is in the cart and any other product is also in the cart alongside it?
This part, when added in conjunction with the first half of the conditions, forces that the ONLY thing in the cart is that product number; so remove it if you don't care what else is in the cart with it: ```
&& $_SESSION['cart']->count_contents() == $_SESSION['cart']->in_cart_check('products_id','1395')

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

8 Apr 2013, 7:06 PM
#24
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 think I may have figured it out. I just changed this:

  if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0 && $_SESSION['cart']->count_contents() == $_SESSION['cart']->in_cart_check('products_id','1395')) {

To this:

  if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0 ) {
29 Apr 2013, 1:51 PM
#25
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'd like to take this in a slightly different direction by changing the logic to a customer ID instead of a product ID. What would I need to change this to?

if ($_SESSION['cart']->in_cart_check('products_id','6251') > 0 ) {

29 Apr 2013, 7:10 PM
#26
drbyte avatar

drbyte

Sensei

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

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

The logged-in customer number is in $_SESSION['customer_id']. Check against that.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 Apr 2013, 7:24 PM
#27
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?

DrByte:

The logged-in customer number is in $_SESSION['customer_id']. Check against that.

Thank you Dr. Byte. I'm afraid the syntax and the general terms just let me down every time. I've no idea how to write it. This would probably just white screen the site:

if ($_SESSION['cart']->in_cart_check('customer_id','') = 4959 ) {

What do you change 'cart' to and what do you change ->in_cart_check to and I'm guessing the ('customer_id','') = 4959 is probably wrong too? I don't know how you gurus just know all that stuff :)

29 Apr 2013, 7:27 PM
#28
drbyte avatar

drbyte

Sensei

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

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

Forget any of the previous code posted. Instead, please write in english the logic you want turned into code. What do you want to do and why?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 Apr 2013, 7:32 PM
#29
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?

If user ID (or is it customer ID) is logged into her account then enable the PayPal payment module for her. Her customer ID is 4959

We don't like to take PayPal but on special request we will take it. So, if a customer asks us to take PayPal then it's good to be able to switch it on for them only.

29 Apr 2013, 7:44 PM
#30
drbyte avatar

drbyte

Sensei

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

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

Then change this (from your previous post awhile back):```
if ($_SESSION['cart']->in_cart_checkCOLOR=#007700 > 0 ) {


to this:

```php
   if ($_SESSION['cart']->in_cart_check('products_id','1395') > 0  || $_SESSION['customer_id'] == 4959) {  
```[/COLOR]

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 Apr 2013, 7:47 PM
#31
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?

Does the product_id have to be there though? What if I've no way of knowing what they're intending to buy?

29 Apr 2013, 7:48 PM
#32
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?

Would this work on it's own?

if ($_SESSION['customer_id'] == 4959) {
30 Apr 2013, 4:00 AM
#33
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?

limelites:

Would this work on it's own?

if ($_SESSION['customer_id'] == 4959) {

Confirmed, this does work well. Can I pick your brains one last time on this topic and ask, what is the correct syntax for this?

if ($_SESSION['customer_id'] == 4959 AND 1234 AND 2345 AND 3456)   .... . .. . etc?

So, if I want to enable PayPal for three or four customers at a time?

30 Apr 2013, 5:27 AM
#34
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:

Confirmed, this does work well. Can I pick your brains one last time on this topic and ask, what is the correct syntax for this?

if ($_SESSION['customer_id'] == 4959 AND 1234 AND 2345 AND 3456)   .... . .. . etc?

So, if I want to enable PayPal for three or four customers at a time?

There are several way of doing this, but this is probably the easiest to follow/understand:

if ( ($_SESSION['customer_id'] == 4959)  ||   ($_SESSION['customer_id'] == 1234)    ||   ($_SESSION['customer_id'] == 3456) ) { 

Do stuff ;

}  

If there are a LOT of customers you wish to check for, then placing them in an array and using a loop structure would be a better solution:

$customerIDs = array(4959, 1234, 4567, 9999) ;

$i = 0 ; $flag = 0 ; 
while ($i < sizeof($customerIDs)) { 

if ($_SESSION['customer_id'] == $customerIDs[$i])  $flag = 1 ; 

$i++ ; 

}

if ($flag == 1)  { 

echo "We have a match" ; 
}

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.

30 Apr 2013, 5:41 AM
#35
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

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

or you could try...

if (in_array($_SESSION['customer_id'], array(4959, 1234, 4567, 9999))) {

do something;

}
30 Apr 2013, 6:11 AM
#36
drbyte avatar

drbyte

Sensei

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

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

limelites, why do you keep changing the rules? First it was a certain product, then it was a certain product with another certain product, now it's for a certain customer.

If the rules keep changing, why not just have NO rules, and turn the module off when you're not needing it, and turn it back ON again for a few hours when you've got a certain customer who needs/wants to use it?

It seems like you're making your business far more complicated than it needs to be.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

30 Apr 2013, 6:31 AM
#37
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?

Thanks RodG and Gilby. Both solutions work well and have been implemented on the website. Perfect!

It's complicated Dr.Byte, I know. The rules change usually as the situation changes. At first we had customers wishing to pay for specific items with PayPal so my initial thought was obviously enabling PayPal for a certain product only. Yesterday, I had one individual customer wanting to pay with PayPal on an unkonwn product. Now, at this moment in time I have three new customers wanting to pay with PayPal. My thoughts have obviously now moved towards allowing specific customers to use it (which in hindsight would have been best anyway).

I'd hate to enable PayPal on the off chance that a customer is going to be online at any give time. When a customer asks to pay with PayPal then there's no telling when they'll actually be there, ready to proceed to the checkout. If I were to enable it on the off-chance that they're likely to checkout in the next hour then who's to say other customers won't use it too? What if it takes the customer a few days to get back? By that time dozens of customers have used it. It's much better this way as I really hate PayPal and we only take PayPal payments if we're specifically asked. Their fees are outrageous and I've had bad experiences with them in the past when we traded on eBay. I don't like giving them any of our business as I'd be quite happy if everyone else did the same.

Anyway, look on the bright side. Now anyone searching this forum will find how to enable PayPal for either/or specific products or specific customers :)

30 Apr 2013, 6:39 AM
#38
drbyte avatar

drbyte

Sensei

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

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

limelites:

I really hate PayPal and we only take PayPal payments if we're specifically asked.
...
I don't like giving them any of our business ...
Those statements sound like you're focused on what you want instead of what your customers want. That's a delicate line to walk. Most professionals would advise you to openly offer the options that your customers want to use, not to penalize your customers because you have a certain bent against a particular thing your customers happen to prefer. After all, isn't one of your goals to get your customers to pay as easily and conveniently as is possible for them?

NOTE: I am NOT inviting a philosophical debate here on whether one should accept PayPal or not. And I don't think the rest of the world needs you to post any of the gory details of your bad experiences. Please don't do that.
I'm merely pointing out what feels like a flaw in your focus. Take it or leave it. I don't care which way you choose ... just wanted to draw your attention to it from the customers' angle. Don't take this discussion in the direction of hating/loving certain providers. That doesn't do anybody any good. Again, I was ONLY pointing out an observation.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

30 Apr 2013, 6:53 AM
#39
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?

gilby:

or you could try...

if (in_array($_SESSION['customer_id'], array(4959, 1234, 4567, 9999))) {

do something;

}


I like this one better than both mine. :)   

This reminds me a little of my very early days in computing, where we used to have little competitions to see who could write the most efficient or interesting code for a very specific task.  

My best effort was a **one line **code of BASIC on a CommodoreC128 that produced a TV style test pattern on screen (consisting of a square grid background, with a circle overlay, and the 7 standard color bars). 

My things have changed since then.  :) 

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.

30 Apr 2013, 6:58 AM
#40
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?

Thanks Dr.Byte and don't worry, I won't be opening that can of worms. I appreciate what you're saying but it's not a decision I took lightly. We take all major credit/debit cards which seems to work well as we're super busy and sales are really pouring in so there are no complaints in that department. If someone has a PayPal account then the chances are they'll have a debit or credit card too :)

I have my own personal reasons for not taking PayPal but I also have good, business reasons. (1) I don't like their outrageous fees. (2) I don't like leaving my company open to fraudsters who use PayPal rules to their benefit and run PayPal reversals on us whenever they think they'll get away with it. (3) I don't like the stigma associated with PayPal as soon as customers see it they assume you're some shoddy eBay seller with a website.

PayPal has a bad reputation amongst buyers as well as sellers. I don't think I'm the only consumer who assumes that a website taking PayPal is usually a website that's been put together by a less than professional company. Most large companies **don't **take PayPal. You ever asked yourself why?

Like you, I don't really want to get into a big debate about the pros and cons of taking PayPal but I thought I'd let you know my professional reasons. Personal reasons aside :)