Discussions

Data model, read orders by third party tool.

Hello,

i want to poll the Drupal Commerce database periodically for new orders and import them to a backend system for processing.

The data i need for backend processing is, the order including the order lines, the information of the customer and the payment information.

I queried the database but i can not find the line items of the orders. The commerce_order table contains the orders, but where are the line items of that order? In this cryptic 'data' column? Or does the field_data_line_items table map the line_items to the commerce_order entities? Which seem to not be a 'strange' relational database design ;)

And what are the tables 'commerce_order_state' and 'commerce_order_status' for? Both tables are empty in my installation.

thanks

Chris

Posted: Feb 19, 2011

Comments

Ryan Ryan Szrama on February 19, 2011

Hey Chris, those order state / status tables were removed... they were leftovers from a previous iteration of the module. I'd suggest you do your testing and development on the latest dev version of Commerce, specifically my GitHub repo if you want the absolutely latest commits.

http://github.com/rszrama/drupalcommerce

For exporting, I'd recommend you load the order and wrap it with entity_metadata_wrapper(). Then it will be much easier to traverse order information, especially the entities that are only referenced by an order but not inherent to the order itself.

<?php
$wrapper
= entity_metadata_wrapper('commerce_order', $order);
foreach (
$wrapper->commerce_line_items as $delta = > $line_item_wrapper) {
 
// Export line item stuff...
}
?>

Orders, line items, and customer profiles are all separate entities joined through reference fields right now. Payment transactions are separate as well but actually just have a one way relationship from the transaction entity to the order. You'll need to load those separately, perhaps using EntityFieldQuery.