6 replies [Last post]
mpalermo's picture
Offline
Joined: 01/20/2012
Juice: 22
Was this information Helpful?

I'm using Drupal 7 with the UC module.

Is there a way to disable all the checkout stuff if the users cart has items, but the total is ZERO? Basically, I'm setting up a software store and some products will be free and others won't. So if the user only selects free stuff, I don't want them to go through all the PayPal checkout stuff. I know that I could just create a "basic page" for the free products, but then it wouldn't be included in the store catalog. Is there a way to accomplish putting free products in the store without requiring checkout stuff?

Also, if I am only selling "downloadable" products and using the PayPal checkout method, how do I disable the form that collects the user's shipping address. I won't ever have shippable items, so I never need to collect the users shipping address. Is this doable somehow?

Visit us at: http://totaldev.com

end user's picture
Offline
Joined: 01/11/2008
Juice: 1728
Re: No checkout required for "free" items

Have you tried using the Payment method pack? There's a COD method but you could modify its name and change it to No Charge or Free Product and then set up rules to activate it if all products are free.

mpalermo's picture
Offline
Joined: 01/20/2012
Juice: 22
Re: Re: No checkout required for "free" items

I installed the Payments method pack and I see the COD option. But I don't see any place to rename it or change any rules to use it for free items. Where can I find that stuff?

Visit us at: http://totaldev.com

DanLanglois's picture
Offline
Joined: 01/10/2012
Juice: 48
I don't know if that'll work

Ubercart ships with some modules that define gateways for processing credit card payments, and if you're using one of those, my guess (I didn't write it, just a guess) is that when you use a gateway, for processing payments, Ubercart does not require a payment method. It might be relevant to know whether you are using (and already have this running) PayPal Website Payments Standard, or what. Maybe Ubercart just redirects to Paypal for payment submission, for example. We're talking about a special payments method, because you want to just mark the payment made, and have the transaction data stored, and there's a receipt. I mean, receipts are visible, right? An order has a payment tab, you want that receipt generated immediately. Now, I'm not looking at the interface, but isn't there a way for you as the administrator, to browse to an order’s Payment tab, and enter a payment--there's a form on that page? That form works, without calling the uc_payment_process_payment function, which is to say, without actually processing a payment through a payment gateway. So there's another function being used by the code there, that just enters a payment, inserts a row into a table. And that is the function that you want to use. Now, you probably have a headache--off the cuff, I'm thinking specifically, that you look in ubercart payment uc_credit uc_credit.module at the function that implements hook_uc_order(). That's function uc_credit_uc_order(). There's a 'submit' case. This is where the attempt to process a CC payment is made. Which is to say, that uc_payment_process_payment() is called. On line 252:

 251     $order->payment_details = uc_credit_cache('load');
 252      $pass = uc_payment_process_payment('credit', $order->order_id, $order->order_total, $data, TRUE, NULL, FALSE);

You don't probably want to mess w/this, lightly, but for your requirement, it seems to me like something needs to change before that line 252, to make it conditional, as in, if the price is zero, then don't call uc_payment_process_payment(). Rather than change this function(uc_credit_uc_order), it would be better to leave it, and avoid calling it. But, I'll say, hypothetically, that you could just check the order_total, and if it's zero, then just set $pass to TRUE and skip line 252. Might work. I won't write an if-statement for this, unless you beg me to, as it would be better, as I say, to leave this file alone, but I still think you have to change a line or two of PHP somewhere, if not here (you weren't planning to write a custom module, is my guess). Also, you can't just set $pass to TRUE, you need to call some other function, which I could figure out--a function that will update the order status and everything, this is why I was talking about the admin interface--I know or suspect? there's a form there for you to enter a payment, and that would be the way that I would figure out what is the right function.
Which, ok, I've looked in ubercart payment uc_payment uc_payment.module, here is line 365:

365 function uc_payment_process_payment($method, $order_id, $amount, $data = NULL, $default = FALSE, $selected = NULL, $redirect = TRUE) {

and the next function is on line 470:

470 function uc_payment_enter($order_id, $method, $amount, $uid = 0, $data = NULL, $comment = '') {

Now, the first function does this: 'Processes a payment through an enabled payment gateway'
And, the second function does this: 'Enters a payment for an order.'

That's the other function I'm referring to. Let me suggest, that you are not going to touch anything--let's talk further. But, what I've told you so far, is still looking promising 2 me.

Anyways, as to disabling the form that collects the user's shipping address, for this I don't think you'll need to pop the hood. Try here: http://www.ubercart.org/docs/user/3345/selling_files

DanLanglois's picture
Offline
Joined: 01/10/2012
Juice: 48
Re: I don't know if that'll work

found this: UC Free Order Payment Method

kind of not my approach (also it's ubercart 2.x), really I think this free orders idea could be in the official ubercart 3.x release. Love the question. Why send free orders off to a payment gateway? I'd bother w/an admin form to toggle/add more complicated rules than this, maybe?

Here's the idea that I was suggesting for ubercart payment uc_credit uc_credit.module (I haven't changed the first line, it's just there to get your bearings):

<?php
251       $order
->payment_details = uc_credit_cache('load');
252       $amount = $order->order_total;
253       if ($amount == 0) {
254         $order_id $order->order_id;
255         $method = 'credit';
256         uc_payment_enter($order_id, $method, $amount0 , '' , '' );
257         $pass = TRUE;
258       } else {
259         $pass = uc_payment_process_payment('credit', $order->order_id, $order->order_total, $data, TRUE, NULL, FALSE);
260       }
?>

I'd prefer that this code be taken as posted for discussion--it's not a patch. Let's get some eyeballs on the idea, though.

mpalermo's picture
Offline
Joined: 01/20/2012
Juice: 22
Re: Re: I don't know if that'll work

After thinking about it a bit more, it seems to make the most sense to disable the "Add To Cart" button on a product page that's free. I'd ideally like to remove the button and show the file download link right there on the page. That way the user doesn't need to bother adding items to their cart and going through a checkout for something that's free. Any ideas on how to accomplish this?

Visit us at: http://totaldev.com

mpalermo's picture
Offline
Joined: 01/20/2012
Juice: 22
Re: Re: Re: I don't know if that'll work

I ended up making a custom template file for the product page and replacing the "Add to cart" button with a download button for the free software instead. Using it at http://totaldev.com

Visit us at: http://totaldev.com