Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kingandy’s picture

Category: support » task
Status: Needs work » Active
earthangelconsulting’s picture

subscribe

czarphanguye’s picture

sub

RikiB’s picture

subscribe

ronline’s picture

subscribe

aaronortega’s picture

subscribing

j0rd’s picture

I think Ryan is the only maintainer on this module and his efforts are going towards Drupal Commerce these days.

I think he'll need to give this module to someone else, or someone else will need to create a new version.

It's also the worlds smallest module and could get ported very easily with a developer who wants to spend 1-2 hours doing it. Aka, you'll probably spend more time talking in this issue queue, than it would take to port the module.

theunraveler’s picture

Status: Active » Needs work
FileSize
6.05 KB

Here's a stab.

I'm not sure about all the JS, but things seem to work well enough.

rszrama’s picture

If someone wants to take this over, just say the word. ; )

And in case anyone is interested... checkout and payment are improved in Drupal Commerce such that a module like this would no longer be necessary.

rickmanelius’s picture

Subscribing

miiimooo’s picture

It seems to work though I haven't tried with discounts etc.

I have a project that requires this so if you want me to be co-maintainer I can commit theunraveler's patch and start looking at the JavaScript and if you have any comments or second thoughts on the general approach let me know.

EDIT: just realised the JavaScript in the 6.x version makes use of the hidden input #edit-panes-payment-current-total but that isn't anywhere in the 7.x version. Is there anything else similar (I couldn't find anything) or could it be included in ubercart core?

miiimooo’s picture

FileSize
7.82 KB

Here is my first stab at this based on the patch from #1016690-4: Drupal 7 Support. Ignore the javascript. All it does is check whether the order total is 0 and disable either free_order or all other payment methods. This will not work with anything that modifies the total on the checkout form or review form as they need dynamic checking (but I don't need that at the moment). Maybe I could add an ajax handler but not really sure where to attach it to.

Note: version of this issues needs changing to 7.x

Anonymous’s picture

I tried applying this patch and got a failure at each hunk. I applied the first one with success.

Really need this module, so I'm happy to help debug.

Thanks,

Drew

EDIT: I'm not sure completing a checkout with the 'free order' payment updates the order status to 'completed'. I've been testing the feature and it keeps it at 'pending'

miiimooo’s picture

You need to patch from the 6.x-1.x version:

git clone --branch 6.x-1.x http://git.drupal.org/project/uc_free_order.git
wget http://drupal.org/files/drupal7-1016690-12.patch
cd uc_free_order/
patch < ../drupal7-1016690-12.patch 
patching file uc_free_order.info
patching file uc_free_order.js
patching file uc_free_order.module
albertokarri’s picture

i got an error when try to execute the first line
git clone --branch 6.x-1.x http://git.drupal.org/project/uc_free_order.git
fatal: http://git.drupal.org/project/uc_free_oreder.git/info/refs not found: did you run git update-server-info on the server?

what must i do?
Thanks.

kingandy’s picture

Wild stab in the dark, but: git update-server-info?

albertokarri’s picture

Ok i have run: git init
and then: git update-server-info
but still continue the problem

Something more to try??
thank you!

miiimooo’s picture

fatal: http://git.drupal.org/project/uc_free_oreder.git/info/refs not found

Typo! - uc_free_oreder

albertokarri’s picture

ok...no words...

thank you! now i'm proving this module for Drupal 7!

EDIT: i have proved the module but got a little problem. I want to sell a "download file" product, and after doing the checkout process the status order is "Pending" and not "Complete", and i have no access to the download file. I have changed the status order to "complete" with admin permissions, but still have no access to the file.

someone knows why I can't to access the file?

Poieo’s picture

Seems to be working well. A couple issues:

#1 - The Free Order method is always present, even if the order total is not $0.00, unless you have 'Test Free Order Functionality' permissions.

#2 - The order status is not updated from pending after checkout. I tried several rule combinations to switch it to payment received, but it seems as though this method skips over all the triggers. I couldn't get it to work with 'customer completes checkout' or 'payment gets entered for an order'. The second makes sense, the first doesn't.

Thanks for your work so far!

Poieo’s picture

Appears as though the following was not updated in the provided patch which could be the source of the problem. Looking at a free order that was placed, no payment is recorded. I believe the module was designed to record a payment of $0 which would trigger the normal rules (CA in D6).

/**
 * Implementation of hook_order().
 */
function uc_free_order_order($op, &$arg1, $arg2) {
  // During checkout, if the free order payment method is used, log a $0.00
  // payment for the order to trigger any necessary predicates.
  if ($op == 'submit' && $arg1->payment_method == 'free_order') {
    uc_payment_enter($arg1->order_id, 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
  }
}

There is no record of this line item in D7 free orders.

Poieo’s picture

Seems like this should work but it's not:

/**
 * Implementation of hook_order().
 */
function uc_free_order_order($op, &$order) {
  // During checkout, if the free order payment method is used, log a $0.00
  // payment for the order to trigger any necessary predicates.
  if ($op == 'submit' && $order->payment_method == 'free_order') {
    uc_payment_enter($order->order_id, 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
  }
}
Poieo’s picture

hook_order() changed to hook_uc_order() in D7. Here is the fix:

/**
* Implementation of hook_uc_order().
*/
function uc_free_order_uc_order($op, &$order) {
  // During checkout, if the free order payment method is used, log a $0.00
  // payment for the order to trigger any necessary predicates.
  if ($op == 'submit' && $order->payment_method == 'free_order') {
    uc_payment_enter($order->order_id, 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
  }
}
Poieo’s picture

The next issue is interference with saved addresses. The D7 version seems to cause "an illegal choice has been detected" error when choosing a saved address at checkout, but only when the order is not free. If the order is free, no error.

Poieo’s picture

I'm not sure why the patch changed the weight of function uc_free_order_uc_payment_method() to '-10', but that seems to be the issue with saved addresses. Changing the function to the following, in addition to the fix in #23, seems make this module 100%.

/**
 * Implementation of hook_uc_payment_method().
 */
function uc_free_order_uc_payment_method() {
  $methods[] = array(
    'id' => 'free_order',
    'name' => t('Free order'),
    'title' => t('Free order - payment not necessary.'),
    'desc' => t('Allow customers with $0 order totals to checkout without paying.'),
    'callback' => 'uc_payment_method_free_order',
    'checkout' => TRUE,
    'no_gateway' => TRUE,
    'weight' => 10,
  );

  return $methods;
}
minnur’s picture

Subscribing

Poieo’s picture

@minnur - Stop subscribing, start following: http://drupal.org/node/1306444

jo1ene’s picture

I have the free order method showing up at all times as well. It seems to have nothing to do with permissions in my cases - having them or not. Other than that, it seems to work as expected.

EDIT: I get the aforementioned "illegal choice" error (#20) popping up when the order total is NOT $0. (Nothing to do with saved addresses or the weight of the free payment method in my case.) If you click "review order" it will refresh the checkout page with the other payment options and you can redo the process successfully. Maybe to do with the "dynamic checking" issue in #12?

jo1ene’s picture

In function uc_free_order_form_uc_cart_checkout_form_alter, the if statement isn't working. I was able to determine this by doing hard-coded tests like this:

  $subtotal = 19;
  if ($subtotal >= 0.01) {
    unset($form['panes']['payment']['payment_method']['#options']['free_order']);
    return;
  }
  $free_order = $form['panes']['payment']['payment_method']['#options']['free_order'];
  $form['panes']['payment']['payment_method']['#options'] = array('free_order' => $free_order);
}

This $order->order_total doesn't appear to be getting the order total and seems to always be zero. This fixes the problem:

/**
 * Implementation of hook_form_FORM_ID_alter().
 */
function uc_free_order_form_uc_cart_checkout_form_alter(&$form, &$form_state, $form_id) {
  if (!user_access('test free order')) {
    return;
  }
  $order = $form['panes']['payment']['line_items']['#order'];
  $subtotal = $order->line_items[0]['amount']; //gets the order total, $order->order_total is always 0
  if ($subtotal >= 0.01) {
    unset($form['panes']['payment']['payment_method']['#options']['free_order']);
    return;
  }
  $free_order = $form['panes']['payment']['payment_method']['#options']['free_order'];
  $form['panes']['payment']['payment_method']['#options'] = array('free_order' => $free_order);
}
longwave’s picture

Would be happy to get this into Ubercart 7.x core if anyone wants to write a patch for core itself. Seems like it would be easier and better to handle it there than in a contrib module.

Poieo’s picture

Per #11

EDIT: just realised the JavaScript in the 6.x version makes use of the hidden input #edit-panes-payment-current-total but that isn't anywhere in the 7.x version. Is there anything else similar (I couldn't find anything) or could it be included in ubercart core?

@longwave - There is no input with ID #edit-panes-payment-current-total in D7 on the checkout page. This module currently works with products priced at $0, but not with coupons that make the price equal $0. Any ideas how we can get this working with coupons in D7? We can possibly provide a patch for core, but need to get this working first.

PetarB’s picture

I can't do patches, sorry!
Can anyone provide a complete module download, or even just the patched file to test? I'd love to help out.
I think until this is done, modules like "Ubercart Discount Coupons" are very much diminished in usefulness!

Poieo’s picture

FileSize
8.62 KB

Here is a 'working' D7 version of the module. It works with free products and/or discount coupons. However, it only works with discount coupons if the coupon is applied on the cart page. You would need to remove the coupon pane from the checkout page to prevent issues.

Hope to have a fully functioning version some time next week.

PetarB’s picture

Thank Poieo

I downloaded and gave it a go, I'm on ubercart 7.x-3.0-rc2

I still have the issue where the 'Free Order' appears on the /cart/checkout page as a selectable payment method, regardless of the total order being $0.00 or not. Perhaps I have set something up incorrectly, or perhaps this is a remaining issue?

Poieo’s picture

Give all roles the 'test free order functionality' permission. That should solve the issue. Don't think that's the correct functionality...but it works for now.

PetarB’s picture

Thank you, I can confirm this now works as described.

There's one oddity on the Checkout page - the Free Payment option is the only one available for a $0.00 order, which is as expected - however it's a radio button that's off by default.

I would suggest it would be on by default, or even better, no radio button at all. If you try and advance without clicking the radio button, you get 'an illegal choice has been made' dialog. I think this is a critical issue to fix, although perhaps there's something I'm missing in setup?

Otherwise seems to be fine. Would be great to get the coupon entry working on the checkout page though! Cart entry is fine.

Thanks to everyone's hard work on this one.

rickmanelius’s picture

Hey PeterB. Do the issues in #36 (free option not set by default) occur when you add the coupon on the checkout page versus the cart page? That might be the feature not yet implemented from the notes in #33.

christelle41’s picture

No, it doesn't occur only when you add a coupon on the checkout page. I can confirm that when you add a price 0 product and when you checkout, the radio button is not checked. So it is a real problem. Thanks for helping.

rickmanelius’s picture

To get the default option to appear on the checkout page, you need to add the following line in function uc_free_order_form_uc_cart_checkout_form_alter
$form['panes']['payment']['payment_method']['#default_value'] = 'free_order';

Working on the checkout page updating next. Hopefully a patch in the next few hours.

rickmanelius’s picture

Sorry I haven't gotten to this yet. Pinging to put at the top of my issue queue so I can work and complete this remaining item.

stealthtech1’s picture

I think i found a bug:

Free order enables even though shipping is still required to be paid. In other words, cart total is 0.00 but weight based shipping fee of let say $7 must still be paid. So checkout summary shows:

Subtotal: $18.00
Coupon CWHFZ: -$16.65
Coupon CUYFI: -$1.35
Postage & Packaging: $7.00
Order total: $7.00

Free order then hides Paypal payment option and forces only free order option...

stealthtech1’s picture

I fixed this as such:

uc_free_order.module - function uc_free_order_form_uc_cart_checkout_form_alter

$subtotal = $order->order_total;

change to:

$last_item = end($order->line_items);
$subtotal = $last_item['amount'];
rickmanelius’s picture

I spent some time trying to get the ajax functionality into this module. I'm thinking the behavior should be this:
- Add the "free_order" method here /admin/store/settings/payment, which then adds the radio button option via uc_free_order_uc_payment_method()
- If a person is on /cart/checkout and the total hits zero (e.g. coupon), hide all other payment methods and set free_order.
- If the coupon is removed and/or shipping/tax causes the subtotal goes above 0, hide free_order option and default to one of the other methods.

Currently, the uc_free_order module uses hook_form_FORM_ID_alter(). While this function is accessed via the ajax callbacks, the current strategy of unsetting all other payment options on page load means that it can't switch back to credit cards upon page load. However, if you comment out everything in uc_free_order_form_uc_cart_checkout_form_alter, you'll be given each enabled payment option and can toggle between them correctly (e.g. picking credit reloads the credit card fields, etc).

I notice there is a uc_free_order.js file that is no longer used. But a lot of JS code is no longer used in the D7 version of ubercart because of the new Form API ajax features. So while this isn't the preferred way to do things in Drupal 7, it would allow us to toggle the selected options (e.g. hiding and showing free payment method and setting the default option).

The preferred way is to use the #states or #ajax properties. As far as I've been able to determine, we cannot use #states as it's meant to toggle on individuals form items and not the list options within a form item (such as the radio buttons). This leaves us with the approach of using #ajax to recreate and inject the new payment options into the $form[panes][payment][payment_method] array as well as into the DOM at #payment-pane.

The problem I see is that _uc_payment_method_list is a private function and thus to reload all the payment methods and either hide the free payment or other options based on the subtotal doesn't appear possible without access to that function.

So the way I see it we either:
A) Make _uc_payment_method_list -> uc_payment_method_list, use uc_free_order_form_uc_cart_checkout_form_alter to add in the ajax behavior, and inject free order OR all payments but free order based on the current subtotal.

OR

B) Use the non-D7 approach of using uc_free_order.js to toggle the different payment options based on a subtotal field comparison (e.g. == "$0.00"). The security checks of whether someone is trying to use the free payment on orders greater than $0 would still be applied via uc_free_order_form_uc_cart_checkout_review_form_alter, so I'm not worried about a security breach.

If I'm missing something obvious that could make this a quicker fix or an easier option C, please let me know. I think short term it's easiest to use option B until we know from an ubercart maintainer about whether or not we can change the base function package or find some other means to change the radio options array via an #ajax property.

Thoughts?

longwave’s picture

I still think the best and simplest solution here is to merge this functionality into Ubercart core.

Now #1332194: Payment method conditions is in core, it should be possible to define a simple new payment method that does nothing, and add a condition to it for order total <= 0 which would cover the simplest cases here. #1373236: Allow multiple modules to react on checkout Ajax events should then hopefully solve the remaining cases where the order total changes depending on selections made on the checkout page.

rickmanelius’s picture

Cool. So basically if order total <=0, only #ajax back something like #markup => "no payment necessary". If the order > 0 return the normal payment methods?

With the best/simplest solution... how many lines of code do you think the changes are? I'm willing to spend time researching this new direction, but I may not be able to complete is quicker than someone who already knows a 1-3 line fix :)

Imper1um’s picture

I can confirm that the last .zip code works on Drupal 7.

While the clicking of the Radio button is annoying, its only annoying, and I am deploying it for my code base.

Thanks!

wodenx’s picture

Please see http://drupal.org/project/uc_custom_payment for a generic solution. Still depends on #1373236: Allow multiple modules to react on checkout Ajax events and related issues for ajax functionality to work properly.

rickmanelius’s picture

FYI, with [#137326] in place, this only requires the following modification:

// Handles the free order payment method.
function uc_payment_method_free_order($op, &$order) {
  if ($op == 'cart-details') {
    $details = array(
      'uc_free_order_cart_details' => array(
        '#markup' => t('Continue with checkout to complete your free order.'),
      ),
    );
    return $details;
  }
}

Before it was just a string, which caused a WSOD when uc_payment_checkout_pane.inc runs $contents['details'] += $details;

coolestdude1’s picture

@longwave You have mentioned that the simplest solution would be to implement into UC core. I agree and wanted to know has that happened yet?

@wodenx Generic solutions that require an extra module seem wrong and although that module supports custom payment methods I don't see it as a good long term solution for this issue.

Workflow wise we need to lay this out proper for development.

Questions that need to be asked,

Should the free order payment method only show up during checkout? (then also on order review)
Should the payment method switch on form reload? (aka you apply the coupon while in checkout)
If the product has a price of 0, should free payment be the only allowable processor?

Moving forward I want to get this built into UC, longwave, can we get in touch with each other? I don't see this taking very long after we can agree on the workflow. I can make that patch for you then we can stab at it together.

coolestdude1’s picture

Project: UC Free Order Payment Method » Ubercart
Version: 6.x-1.x-dev » 7.x-3.x-dev
Component: Code » Payment
Status: Needs work » Needs review

Heads up Longwave and all others
I am switching the project so that the tests go in the right place.

Patch based highly off of #33.

I have created a patch against Drupal 7 Ubercart 7.x-3.x and tested the module.

I have integrated #39 and then some for the form alter. This is similar in functionality to how free_order addon module for UC worked for Drupal 6.

#42 Did not work for me so it is not in this patch. I do not have products that have quite the workflow so that needs to be tested and most likely rewritten to allow for that workflow.

I have added some much needed comments to the module.

I have removed the permission because this is a payment method that should just be generically available. The permission was also setup to be the inverse which was weird. Also the permission in the Drupal 6 version was supposed to present a button to the privileged user which allowed you to add the free order no matter what but coupons do this and do tracking so I opted for that workflow since it was removed from #33.

I did not see the need for the javascripting since ubercart reloads where needed and this module just uses the form_alters.

Lets get this rolling!

coolestdude1’s picture

Oh of course forget the patch I shall.

longwave’s picture

Project: Ubercart » UC Free Order Payment Method
Version: 7.x-3.x-dev » 6.x-1.x-dev
Component: Payment » Code

Thanks for working on this.

There's already an issue for this in the Ubercart queue, #420980: No payment/billing should be required when order total is $0 - let's work on Ubercart core there, and keep this in UC Free Order so others may find it here as well.

Marcelo Amaro’s picture

subscribe