8 replies [Last post]
fivepoints's picture
Offline
Getting busy with the Ubercode.
Joined: 09/26/2007
Juice: 258
Was this information Helpful?

hallo, I think I have the same problem of this guy:
http://www.ubercart.org/forum/development/3776/hook_order_pane_editprocess
but there's no answer.
the pane below is ok: it is shown under admin/store/orders/order-number and in admin/store/orders/order-number/edit
but I dont' understand why the query under case 'edit-process' doesn't work.

<?php
function uc_order_pane_vat_number($op, $arg1) {
  switch (
$op) {
        case
'customer':
         if (empty(
$arg1->billing_vat_number)) {
           
$vat_number = t('Non specificata.');
            }
            else if (!empty(
$arg1->billing_vat_number)) {
           
$vat_number = $arg1->billing_vat_number;
        }
            return
t('!vat_number', array('!vat_number' => $vat_number));    
    case
'view':
        if (empty(
$arg1->billing_vat_number)) {
           
$vat_number = t('Non specificata.');
            }
            else if (!empty(
$arg1->billing_vat_number)) {
           
$vat_number = $arg1->billing_vat_number;
        }
            return
t('!vat_number', array('!vat_number' => $vat_number));
    case
'edit-form':
     
$form['admin_vat_number_field'] = array(
       
'#type' => 'textfield',
       
'#title' => t('Partita Iva'),
               
'#default_value' => $arg1->billing_vat_number,
      );
      return
$form;
        case
'edit-theme':
           
$output = drupal_render($arg1['admin_vat_number_field']);
      return
$output;
        case
'edit-process':
           
db_query("UPDATE {uc_order_billing_extend} SET vat_number = '%s' WHERE order_id = %d", $arg1['admin_vat_number_field'], $arg1['order_id']);
      return;
    }
}
?>

thanks
nicola

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: hook_order_pane

Is it just not getting called at all, or is the query itself bad?

fivepoints's picture
Offline
Getting busy with the Ubercode.
Joined: 09/26/2007
Juice: 258
the query is ok. it's just

the query is ok.
it's just not getting called at all.

thank you in advance
nicola

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: the query is ok. it's just

Weird... I don't have any magic answers... I'd just start by putting:

<?php
  drupal_set_message
($op .'<pre>'. print_r($arg1, TRUE) .'</pre>');
?>

at the top of your callback function to see what's being passed to your pane function when you submit the edit form.

fivepoints's picture
Offline
Getting busy with the Ubercode.
Joined: 09/26/2007
Juice: 258
hallo Ryan, thanks for your

hallo Ryan,
thanks for your reply.

yes, I've already tried it but I don't have a solution.
this is the code print_r() returns.
the value I want to insert into database is
[admin_vat_number_field] and into the query I use $arg1['billing_vat_number'] and $arg1['order_id'].

<?php
   
* edit-process

     

Array
      (
          [
order_id] => 181
         
[order_uid] => 1
         
[delivery_first_name] => nicola
         
[delivery_last_name] => sanino
         
[delivery_phone] =>
          [
delivery_company] =>
          [
delivery_street1] => Via Roma, 22
         
[delivery_city] => Roma
         
[delivery_country] => 380
         
[delivery_zone] => 102
         
[delivery_postal_code] => 12055
         
[billing_first_name] => nicola
         
[billing_last_name] => sanino
         
[billing_phone] =>
          [
billing_company] =>
          [
billing_street1] => Via Roma, 22
         
[billing_city] => Roma
         
[billing_country] => 380
         
[billing_zone] => 102
         
[billing_postal_code] => 12055
         
[uid] => 1
         
[uid_text] => 1
         
[primary_email_text] => nicola.nic@gmail.com
         
[primary_email] => nicola.nic@gmail.com
         
[admin_vat_number_field] => 02968470842
         
[payment_method] => cod
         
[li_type_select] => shipping
         
[submit] => Add line
         
[li_delete_id] =>
          [
line_items] => Array
              (
                  [
subtotal] => Array
                      (
                          [
li_id] => subtotal
                     
)

                  [

359] => Array
                      (
                          [
li_id] => 359
                         
[title] => Shipping
                         
[amount] => 3.60
                     
)

                  [

tax_subtotal] => Array
                      (
                          [
li_id] => tax_subtotal
                     
)

                  [

360] => Array
                      (
                          [
li_id] => 360
                         
[title] => IVA 20%
                          [
amount] => 31.11
                     
)

                  [

total] => Array
                      (
                          [
li_id] => total
                     
)

              )

          [

page] => order-edit
         
[quote_button] => Get shipping quotes
         
[add_quote] => Apply to order
         
[admin_comment] =>
          [
op] => Submit changes
         
[submit-changes] => Submit changes
         
[delete] => Delete
         
[form_token] => c7669bbfdef162debb8c575cd28f3705
         
[form_id] => uc_order_edit_form
     
)

    *

Order changes saved.
?>
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: hallo Ryan, thanks for your

Well, at the very least it looks like the callback function is being called properly with the appropriate data. I guess I'd now just suspect the query itself or your database structure. Has the table been created properly? Are all the field names right? I'm afraid I can't offer much more help than this little nudge.

fivepoints's picture
Offline
Getting busy with the Ubercode.
Joined: 09/26/2007
Juice: 258
Re: Re: hallo Ryan, thanks for your

I've done some tests: my table is named uc_order_billing_extend.
I think there are some name conflicts (but I don't know why) because if I rename the table with another name (for example uc_billing_extend) my query works.

thanks
nicola

fivepoints's picture
Offline
Getting busy with the Ubercode.
Joined: 09/26/2007
Juice: 258
Re: Re: Re: hallo Ryan, thanks for your

it seems my module has an interference between hook_order() case 'save': and hook_order_pane() case 'edit-process':.
I'm indagating.

nicola

pfournier@drupal.org's picture
Offline
Joined: 06/28/2009
Juice: 2
edit-process should return an array

In the 'edit-process' case, you only need to return an array of the changes made to your order, not to do the actual saving. In your case you should return array('vat_number' => $arg1['admin_vat_number_field']). Your hook_order function will take care of saving this to the database.