9 replies [Last post]
webmasterkai's picture
Offline
Uber DonorBug Finder
Joined: 08/09/2007
Juice: 302
Was this information Helpful?

Has anyone developed a way to create a new order from a user page or within a view? Perhaps a block snippet that has a "create a new order for this user" link. Or a view with a "Create order for node author" field. If not I'll make something next week.

Biodiesel * (ubercart + drupal) = Sundays Energy

webmasterkai's picture
Offline
Uber DonorBug Finder
Joined: 08/09/2007
Juice: 302
solved my own problem

I took a peek inside the uc_order module and noticed that going to example.com/admin/store/orders/create/1 would create an order for user one. 1 being the uid. I created a simple php block with this code. It provides a link on user profile pages to create an order for the user.

<?php
$user
= arg(0);
$uid = arg(1);
if (
is_numeric($uid) && ($user == 'user')) print(l('create order for this user', 'admin/store/orders/create/' . $uid));
?>

Biodiesel * (ubercart + drupal) = Sundays Energy

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15453
Re: solved my own problem

Good idea. Smiling

Sansui's picture
Offline
Joined: 06/05/2008
Juice: 154
Re: solved my own problem

This method no longers works in current version of ubercart Sad

Sansui's picture
Offline
Joined: 06/05/2008
Juice: 154
Re: Re: solved my own problem

Just can't puzzle out how to do this in current UC.

Looking at the order module :

/**
* @see uc_order_create_form()
*/
function uc_order_create_form_submit($form, &$form_state) {
  global $user;

  $order = uc_order_new($form_state['values']['uid'], 'post_checkout');
  uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');

  $form_state['redirect'] = 'admin/store/orders/'. $order->order_id .'/edit';
}

Would it be possible to add a condition to test if UID is passed in URL instead of the form state for uid? Is this where the modification should actually be made?

Sansui's picture
Offline
Joined: 06/05/2008
Juice: 154
Re: Create new order from user page

After looking at it for a while, I came up with adding this to uc_create_order

  if (arg(4))  {
    global $user;
    $uid = check_plain(arg(4));
    $order = uc_order_new($uid, 'post_checkout');
    uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');
    drupal_goto('admin/store/orders/'. $order->order_id .'/edit');
  }

Now I can finally create orders from links! This is exceptionally handy coupled with Views.

frishaynes's picture
Offline
Joined: 06/25/2009
Juice: 4
Re: Create new order from user page

Great stuff. Thanks guys, got it working, exactly what I needed. Now each user page has a "create new order for user" link available to authorised users.

Chris

Sansui's picture
Offline
Joined: 06/05/2008
Juice: 154
Re: Re: Create new order from user page

Awesome, glad you got it working Smiling

Rosso69's picture
Offline
Joined: 11/08/2010
Juice: 12
uc_order_create instead of uc_create_order

For me it works right now.

But i am not sure if it works ok. I still get the create order screen. When i click on create order i go to the new order. There i see the correct user.
Is it possible to skip the entire create order screen?

Rosso69's picture
Offline
Joined: 11/08/2010
Juice: 12
Fixed

I noticed that i had to put it in uc_order_create and not uc_order_create_form.

Sorry