7 replies [Last post]
ragazzo's picture
Offline
Joined: 01/17/2008
Juice: 27
Was this information Helpful?

Hello guys!
I am currently working on a module that adds VAT-ID functionality to übercart. So I have added a field "VATID" to the uc_orders table.
Now I have realized that uc_order.module doesn't explicitely quote fieldnames when inserting data (line 2489):

db_query("INSERT INTO {uc_orders} VALUES (%d, %d, '%s', 0, '%s', '', '', '', "
."'', '', '', '', 0, '', 0, '', '', '', '', '', '', '', 0, 0, 0, '', "
."%d, %d)", $order->order_id, $uid, $order->order_status, $email, time(), time());

so i get an error (row count doesn't match...) after modifying table structure.

Perhaps it is not desired to alter existing table structures. Otherwise I would recommend to simply quote the fieldnames in the query.

INSERT INTO {uc_orders} (field1, field2, ...) VALUES (%d, %d, '%s', 0, ...)

regards

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: DB-Inserts: quoting of fieldnames requested

Hmm... maybe both should happen. Puzzled

The general practice is to not alter the core table structure, so I haven't bothered to put field names in the inserts. I'm a little curious... can the data you're trying to store be put into the $order->data array? Or will you need to do selects/order bys on the column?

ragazzo's picture
Offline
Joined: 01/17/2008
Juice: 27
Hello Ryan! A short

Hello Ryan!

A short explanation on EU-VAT-ID-system: If my customer is a company and thus has got a valid VAT ID, this number (e.g. ATU12345678) has to be annotated on every invoice. Hence this ID somehow sticks to the order/adress data and should be stored in the same record (to my opinion...).

The VAT ID has an influence on the calculation of VAT (->workflow_ng) and must be printed on various documents. There is no need to do selects/order-bys on that column. If it could easily retrieved from the $order->data array (newbee - not sure what this array does and where it can be accessed) this would doubtlessly be fine!

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Hello Ryan! A short

Yep, it can be easily saved/loaded to that array, and Ubercart takes care of the saving/loading. In other words, if at one point I do this:

<?php
  $order
->data['vat_id'] = 'ATU12345678';
?>

And the order gets saved, on subsequent loads, I can pull up that value with:

<?php
  $vat_id
= $order->data['vat_id'];
?>

The tricky part will be collecting this from the customer at checkout and displaying it on order screens. For that you need to use the checkout/order pane APIs. You might look into the lead tracker contribution for example code.

ragazzo's picture
Offline
Joined: 01/17/2008
Juice: 27
Re: Re: Hello Ryan! A short

Ryan, where do I assign these $order->data['vat_id'] values? I have tried to do it within my Implementation of hook_token_values() but my newly inserted values never show up when i do a print_r($order).
Which would be the perfect hook/function to write my data (retrieved from DB) to the array (object?).

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Hello Ryan! A short

You should look into hook_order().

ragazzo's picture
Offline
Joined: 01/17/2008
Juice: 27
Re: Re: Re: Re: Hello Ryan!

Ryan, you can't imagine how important your answers on my beginners'-questions are for me. Unfortunately they aren't as obvious to me as to an exerienced drupalist, but with each of your statements the whole system is getting clearer to me, and my enthusiasm grows. Thank you very much for your excellent work!

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

No problem, man. There's a lot here to take in... the project has grown quite large over the last year. Sticking out tongue

Let's just say that your profile pic inspires me, too. Eye-wink I can't wait to have hair that long! (Although mine will probably be a poofy mess with curls/waves.)