3 replies [Last post]
newbstah's picture
Offline
Joined: 07/04/2008
Juice: 90
Was this information Helpful?

Hi There -

Have installed userpoints_ubercart and would like userpoints to appear on the checkout pane before credit cards and to default to using userpoints for payment.

Have managed to default to userpoints using hook_form_alter() by using the following:

<?php
case 'uc_cart_checkout_form':
   
   
// reorder the payment choices and make dollhouse dollars default
   
$form['panes']['payment']['payment_method']['#default_value'] = 'points';
?>

It works! Yay!

However, when I try to change the weight of the form items, I get an error.
Here's what I'm using:

<?php
$form
['panes']['payment']['payment_method']['#default_value']['points']['#weight'] = -10;
$form['panes']['payment']['payment_method']['#default_value']['credit']['#weight'] = 0;
?>

I'm using the form_inspect module and what it's telling me is that the payment_method $options is an array with 2 elements: credit and points. When I try to assign weight to these, I get the error -

Fatal error: Cannot use string offset as an array in /Applications/MAMP/htdocs/etc./our_forms_altered.module on line 41

Have searched through the userpoints_ubercart module and its includes and think that the aggregation of payment methods is taking place somewhere in hook_payment_method() and that normal hook_form_alter() won't work in this case.

Something tells me I'm not in Kansas anymore with this. I'll take any suggestions.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Reordering payment options (Userpoints) in checkout pane usi

Ahh, I see what you're doing. Smiling I was curious why it should cause an error, and really it's because the options in that array don't have a weight. Drupal just renders them in the order they appear in the array. You can rearrange things in that array through various sorts, though I'm curious if you can't just use the payment methods settings form at /admin/store/settings/payment/edit/methods to accomplish what you're looking to do. Puzzled

fwiw, Ubercart will default to the first in the list (unless the customer has already specified another one), so that shouldn't be necessary either. Just reorder them how you need them.

newbstah's picture
Offline
Joined: 07/04/2008
Juice: 90
Wonderful Ryan! Thank you! I

Wonderful Ryan! Thank you!

I hunted all over for that page, and just couldn't find it. Thank you! Thank you! Thank you!

activelyOUT's picture
Offline
Joined: 04/20/2009
Juice: 70
Re: Reordering payment options (Userpoints) in checkout pane usi

This is great. I was trying to figure out how to make userpoints the default payment option.