'admin/store/products/export', 'access' => user_access('export'), 'title' => t('Export products'), 'callback' => 'uc_importer_export_page', 'type' => MENU_NORMAL_ITEM, ); $items[] = array('path' => 'admin/store/products/import', 'access' => user_access('import'), 'title' => t('Import products'), 'callback' => 'uc_importer_import_page', 'type' => MENU_NORMAL_ITEM, ); $items[] = array('path' => 'admin/store/settings/importer', 'access' => user_access('import'), 'title' => t('Importer settings'), 'description' => t('Configure the importer settings.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_importer_admin_settings'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } /****************************************************************************** * Menu Callbacks * ******************************************************************************/ /** * Configure the importer behaviour when handling duplicate objects. * * @ingroup forms * @see uc_importer_admin_settings_validate * @see uc_importer_admin_settings_submit */ function uc_importer_admin_settings() { $form = array(); $options = array( UC_IMPORTER_DO_NOTHING => t('Do not save the new item.'), UC_IMPORTER_REPLACE => t('Overwrite the existing item.'), UC_IMPORTER_INCREMENT => t('Save the new item as a separate entity,'), ); $form['uc_importer_vocabulary_duplicates'] = array('#type' => 'radios', '#title' => t('How should similarly named vocabularies be handled during import?'), '#options' => $options, '#default_value' => variable_get('uc_importer_vocabulary_duplicates', UC_IMPORTER_DO_NOTHING), ); $form['uc_importer_category_duplicates'] = array('#type' => 'radios', '#title' => t('How should similarly named categories be handled during import?'), '#options' => $options, '#default_value' => variable_get('uc_importer_category_duplicates', UC_IMPORTER_DO_NOTHING), ); $form['uc_importer_class_duplicates'] = array('#type' => 'radios', '#title' => t('How should similarly named classes be handled during import?'), '#options' => $options, '#default_value' => variable_get('uc_importer_class_duplicates', UC_IMPORTER_DO_NOTHING), ); $form['uc_importer_attribute_duplicates'] = array('#type' => 'radios', '#title' => t('How should similarly named attributes be handled during import?'), '#options' => $options, '#default_value' => variable_get('uc_importer_attribute_duplicates', UC_IMPORTER_DO_NOTHING), ); $form['uc_importer_product_duplicates'] = array('#type' => 'radios', '#title' => t('How should similarly identified products be handled during import?'), '#options' => $options, '#default_value' => variable_get('uc_importer_product_duplicates', UC_IMPORTER_DO_NOTHING), ); $account = user_load(array('uid' => variable_get('uc_importer_user', 0))); $form['uc_importer_user'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $account ? $account->name : '', '#description' => t('The "author" of imported products. Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))) ); $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); if (!empty($_POST) && form_get_errors()) { drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); } return $form; } /** * Validation handler for uc_importer_admin_settings(). * * Allow only existing users to be authors of imported nodes. */ function uc_importer_admin_settings_validate($form_id, $form_values) { if (!empty($form_values['uc_importer_user']) && !($account = user_load(array('name' => $form_values['uc_importer_user'])))) { // The use of empty() is mandatory in the context of usernames // as the empty string denotes the anonymous user. In case we // are dealing with an anonymous user we set the user ID to 0. form_set_error('uc_importer_user', t('The username %name does not exist.', array('%name' => $form_values['uc_importer_user']))); } } /** * Submit handler for uc_importer_admin_settings(). */ function uc_importer_admin_settings_submit($form_id, $form_values) { if ($op == t('Reset to defaults')) { variable_del('uc_importer_handle_duplicates'); variable_del('uc_importer_user'); drupal_set_message(t('The configuration options have been reset to their default values.')); } else { if ($account = user_load(array('name' => $form_values['uc_importer_user']))) { variable_set('uc_importer_user', $account->uid); } else { variable_set('uc_importer_user', 0); } variable_set('uc_importer_vocabulary_duplicates', $form_values['uc_importer_vocabulary_duplicates']); variable_set('uc_importer_category_duplicates', $form_values['uc_importer_category_duplicates']); variable_set('uc_importer_class_duplicates', $form_values['uc_importer_class_duplicates']); variable_set('uc_importer_attribute_duplicates', $form_values['uc_importer_attribute_duplicates']); variable_set('uc_importer_product_duplicates', $form_values['uc_importer_product_duplicates']); drupal_set_message(t('The configuration options have been saved.')); } } /** * Wrapper function to generate a page to hold the export form. */ function uc_importer_export_page() { uc_add_js(drupal_get_path('module', 'uc_product') .'/uc_product.js', 'module'); $output = ''; $nids = array(); $args = func_get_args(); foreach ($args as $nid) { if (is_numeric($nid)) { $nids[] = (int)$nid; } } $settings = array( 'div' => '#products-selector', 'class' => 'product-ubrowser', 'vid' => variable_get('uc_catalog_vid', 0), 'filter' => implode(',', module_invoke_all('product_types')), 'search' => 'true', 'nids' => 'true', 'nodesg' => 'product', 'nodepl' => 'products', 'multi' => 'true', 'select' => 'buffer_products("'. file_create_url('') .'")', ); if (module_exists('uc_catalog') && variable_get('uc_catalog_vid', 0)) { $output .= ubrowser($settings, 'products-selector'); $output .= drupal_get_form('uc_importer_export_buffer_form', $nids); } else { $output .= drupal_get_form('uc_importer_export_form'); } return $output; } /** * Wrapper function to generate a page to hold the import form. */ function uc_importer_import_page() { return drupal_get_form('uc_importer_import_form'); } /****************************************************************************** * Module Functions * ******************************************************************************/ /** * Choose the nodes to export. * * @ingroup forms * @see uc_importer_export_form_submit */ function uc_importer_export_form() { $form = array(); $products = array(); $result = db_query(db_rewrite_sql("SELECT n.nid, p.model FROM {uc_products} AS p JOIN {node} AS n")); while ($product = db_fetch_object($result)) { $products[$product->nid] = $product->model; } $form['nids'] = array('#type' => 'select', '#multiple' => true, '#title' => t('Products'), '#options' => $products, '#description' => t('Hold "Ctrl" to select multiple items.'), ); $form['submit'] = array('#type' => 'submit', '#value' => t('Export')); return $form; } /** * Submit handler for uc_importer_form(). */ function uc_importer_export_form_submit($form_id, $form_values) { if (count($form_values['nids'])) { $xml = uc_importer_export((array)$form_values['nids']); if ($file = file_save_data($xml, file_directory_temp() .'/uc_export.xml', FILE_EXISTS_REPLACE)) { //drupal_set_message(print_r($file, true)); file_transfer($file, array( 'Content-Type: application/xml; charset=utf-8', 'Content-Length: '. filesize($file), 'Content-Disposition: attachment; filename="uc_export.xml"', )); } } } /** * Form to collect the id numbers of all the store components to be exported. * * @ingroup forms * @see uc_importer_export_buffer_form_submit */ function uc_importer_export_buffer_form($nids) { $form = array(); $buffer = ''; foreach ($nids as $nid) { $node = node_load($nid); $buffer .= theme('imagecache', 'uc_thumbnail', $node->field_image_cache[0]['filepath'], $node->field_image_cache[0]['alt'], $node->field_image_cache[0]['title']); } $form['#attributes'] = array('class' => 'product-buffer'); $form['thumbnails'] = array('#type' => 'markup', '#value' => '
', ); $form['products'] = array('#type' => 'hidden', ); $form['reset'] = array('#type' => 'submit', '#value' => t('Reset'), ); $form['submit'] = array('#type' => 'submit', '#value' => t('Export'), ); return $form; } /** * Submit handler for uc_importer_export_buffer_form(). * * Generate an XML file from the products listed and upload it to the user. */ function uc_importer_export_buffer_form_submit($form_id, $form_values) { $item = menu_get_item(menu_get_active_item()); //drupal_set_message(print_r($form_values, true)); if ($form_values['op'] == t('Reset')) { return $item['path']; } else { $products = array_filter(explode('/', $form_values['products'])); //drupal_set_message(''. print_r($products, true) .''); $xml = uc_importer_export($products); if ($file = file_save_data($xml, file_directory_temp() .'/uc_export.xml', FILE_EXISTS_REPLACE)) { //drupal_set_message(print_r($file, true)); file_transfer($file, array( 'Content-Type: application/xml', 'Content-Length: '. filesize($file), 'Content-Disposition: attachment; filename="'. $file .'"', )); } } } /** * Upload form for an XML file to be imported. * * @ingroup forms * @see uc_importer_import_form_submit */ function uc_importer_import_form() { $form = array(); $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['file'] = array('#type' => 'file', '#title' => t('Import XML File'), ); $form['directory'] = array('#type' => 'textfield', '#title' => t('Directory containing XML files'), ); $form['submit'] = array('#type' => 'submit', '#value' => t('Import'), ); return $form; } /** * Submit function for uc_importer_import_form(). */ function uc_importer_import_form_submit($form_id, $form_values) { $file = file_check_upload('file'); if ($file) { $file = file_save_upload($file); drupal_set_message(t('File uploaded successfully.')); //drupal_set_message('
'. print_r($file, true) .''); if ($xml = file_get_contents($file->filepath)) { uc_importer_import($xml); } } else if ($form_values['directory']) { file_scan_directory(file_directory_path() .'/'. $form_values['directory'], '.*\.xml$', array('.', '..', 'CVS'), 'uc_import_directory_parse'); }else { drupal_set_message(t('Error: File failed to upload.'), 'error'); } } /** * Constructs the XML representation of the store from the ids given. * * @param $nids * An array of product ids. * @return * XML data to be sent. */ function uc_importer_export($nids) { $data = array( 'vocabularies' => array(), 'categories' => array(), 'manufacturers' => array(), 'attributes' => array(), 'classes' => array(), 'products' => array(), ); foreach ($nids as $nid) { $data['products'][] = $nid; $node = node_load($nid); if (uc_product_class_load($node->type)) { $data['classes'][] = $node->type; } if (module_exists('taxonomy')) { foreach ($node->taxonomy as $tid => $term) { $data['vocabularies'][] = $term->vid; foreach (taxonomy_get_parents_all($term->tid) as $parent) { // First $parent is $term, so no special case needed $data['categories'][] = $parent->tid; } if (module_exists('uc_manufacturer') && $term->vid == variable_get('uc_manufacturer_vid', 0)) { $data['manufacturers'][] = $tid; } } } if (module_exists('uc_attribute')) { $data['attributes'] += array_keys(uc_product_get_attributes($nid)); } } foreach ($data as $type => $ids) { $data[$type] = array_unique($ids); } drupal_set_message('
'. print_r($data, true) .''); $xml = ''. "\n"; $xml .= '
'; $xml .= ''; if (!empty($order->line_items)) { $xml .= ''. $quote['method'] .' '; $xml .= ''. $quote['accessorials'] .' '; $xml .= ''. $quote['rate'] .' '; $xml .= ''. htmlspecialchars($quote['quote_form'], ENT_QUOTES, "UTF-8") .' '; $xml .= uc_importer_invoke('export', 'quote', $order_id); $xml .= '
'. print_r($product_data->unique_hash[0]->data(), true) .''); if (!isset($product_data->unique_hash)) { $product_data->addChild('unique_hash', md5((string)$product_data->model[0]->data() . (string)$product_data->list_price[0]->data() . (string)$product_data->cost[0]->data() . (string)$product_data->sell_price[0]->data() . (string)$product_data->weight[0]->data() . (string)$product_data->weight_units[0]->data() . (string)$product_data->default_qty[0]->data() . time()), $product_data->level() + 1); } // Try by unique_hash... if (!$nid = db_result(db_query("SELECT nid FROM {uc_products} WHERE unique_hash LIKE '%s'", (string)$product_data->unique_hash[0]->data()))) { // ...else try by product model. $nid = db_result(db_query("SELECT nid FROM {uc_products} WHERE model LIKE '%s'", (string)$product_data->model[0]->data())); } if ($nid) { switch (variable_get('uc_importer_product_duplicates', UC_IMPORTER_DO_NOTHING)) { case UC_IMPORTER_REPLACE: $product->nid = $nid; $product->revision = true; $product->unique_hash = db_result(db_query("SELECT unique_hash FROM {uc_products} WHERE nid = %d", $nid)); $id_map['products'][(string)$product_data->id[0]->data()] = $nid; break; case UC_IMPORTER_INCREMENT: unset($product_data->unique_hash); $id_map['products'][(string)$product_data->id[0]->data()] = $nid; break; case UC_IMPORTER_DO_NOTHING: $product->nid = $nid; $id_map['products'][(string)$product_data->id[0]->data()] = $nid; continue 2; } } else { $product->unique_hash = (string)$product_data->unique_hash[0]->data(); } $product->type = (string)$product_data->type[0]->data(); $product->uid = $user->uid; $product->log = t('Imported product from XML.'); $product->name = $user->name; $product->status = 1; $product->format = filter_resolve_format(FILTER_FORMAT_DEFAULT); if (module_exists('uc_catalog')) { if (isset($product_data->categories) && (count($product_data->categories) > 0)) { foreach ($product_data->categories[0]->category as $category_data) { $product->taxonomy[] = $id_map['categories'][(string)$category_data->id[0]->data()]; } } } $product->title = html_entity_decode((string)$product_data->name[0]->data(), ENT_QUOTES, "UTF-8"); $product->body = html_entity_decode((string)$product_data->description[0]->data(), ENT_QUOTES, "UTF-8"); $product->teaser = node_teaser($product->body, $product->format); $product->model = html_entity_decode((string)$product_data->model[0]->data(), ENT_QUOTES, "UTF-8"); /* if (module_exists('uc_manufacturer') && $manufacturer = variable_get('uc_manufacturer_vid', 0)) { $product->taxonomy['tags'][$manufacturer] = html_entity_decode((string)$product_data->manufacturer[0]->data(), ENT_QUOTES, "UTF-8"); } */ $product->list_price = (float)$product_data->list_price[0]->data(); $product->cost = (float)$product_data->cost[0]->data(); $product->sell_price = (float)$product_data->sell_price[0]->data(); $product->weight = (float)$product_data->weight[0]->data(); $product->weight_units = isset($product_data->weight_units) ? (string)$product_data->weight_units[0]->data() : variable_get('uc_weight_unit', 'lb'); if (isset($product_data->length, $product_data->width, $product_data->height)) { $product->length = (float)$product_data->length[0]->data(); $product->width = (float)$product_data->width[0]->data(); $product->height = (float)$product_data->height[0]->data(); $product->length_units = isset($product_data->length_units) ? (string)$product_data->length_units[0]->data() : variable_get('uc_length_unit', 'in'); } if (isset($product_data->pkg_qty)) { $product->pkg_qty = (int)$product_data->pkg_qty[0]->data(); } if (isset($product_data->default_qty)) { $product->default_qty = (int)$product_data->default_qty[0]->data(); } if (isset($product_data->shippable)) { $product->shippable = (int)$product_data->shippable[0]->data(); } $i = 0; if (module_exists('imagefield')) { if (isset($product_data->image)) { foreach ($product_data->image as $image) { $image_path = (string)$image->path[0]->data(); $path_info = pathinfo($image_path); $image_field = content_fields('field_image_cache', $product->type); $path = $image_field['widget']['image_path']; if (!($local_path = file_create_path($path))) { $local_path = file_check_directory($path, FILE_CREATE_DIRECTORY); } $local_path .= '/'. rawurldecode(basename($image_path)); $size = 0; if (!file_exists($local_path)) { $input = fopen($image_path, 'rb'); $output = fopen($local_path, 'wb'); while ($data = fread($input, 1024)) { $size += fwrite($output, $data, 1024); } fclose($input); fclose($output); } else { $size = filesize($local_path); } $product->field_image_cache[$i] = array( 'fid' => (file_exists($local_path) ? db_result(db_query("SELECT fid FROM {files} WHERE nid = %d AND filepath = '%s'", $nid, $local_path)) : 'upload'), 'title' => isset($image->title) ? html_entity_decode((string)$image->title[0]->data(), ENT_QUOTES, "UTF-8") : '', 'alt' => isset($image->alt) ? html_entity_decode((string)$image->alt[0]->data(), ENT_QUOTES, "UTF-8") : '', 'filename' => basename($image_path), 'filepath' => $local_path, 'filesize' => $size, 'filemime' => 'image/'. $path_info['extension'], ); $i++; } } } if (isset($product_data->fields)) { $fields = array(); foreach ($product_data->fields[0]->field as $field_data) { foreach ($field_data->delta as $delta) { $columns = array(); foreach ($delta->children() as $value_data) { $columns[$value_data->name()] = html_entity_decode((string)$value_data->data(), ENT_QUOTES, "UTF-8"); } $field_name = html_entity_decode((string)$field_data->name[0]->data(), ENT_QUOTES, "UTF-8"); if (!is_array($product->$field_name)) { $product->$field_name = array(); } array_push($product->$field_name, $columns); } } } //watchdog('importer', '
'. print_r($product_data, true) .''); //watchdog('importer', '
'. print_r($product, true) .''); node_save($product); if (!isset($product->nid)) { $product->nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = '{node}_nid'")); } $id_map['products'][(string)$product_data->id[0]->data()] = $product->nid; if (module_exists('uc_attribute')) { $attr_replace = array(); $attr_values = array(); $opt_replace = array(); $opt_values = array(); if (isset($product_data->attributes)) { foreach ($product_data->attributes[0]->attribute as $attribute_data) { if (!isset($id_map['attributes'][(string)$attribute_data->id[0]->data()])) { $attribute = new stdClass(); $attribute->name = html_entity_decode((string)$attribute_data->name[0]->data(), ENT_QUOTES, "UTF-8"); $attribute->ordering = isset($attribute_data->ordering) ? (int)$attribute_data->ordering[0]->data() : 0; drupal_execute('uc_attribute_form', (array)$attribute); $id_map['attributes'][(string)$attribute_data->id[0]->data()] = db_result(db_query("SELECT aid FROM {uc_attributes} WHERE name = '%s'", $attribute->name)); } $attr_replace[] = '%d,%d,%d,%d'; $attr_values[] = $product->nid; $attr_values[] = $id_map['attributes'][(string)$attribute_data->id[0]->data()]; $attr_values[] = isset($attribute_data->ordering) ? (int)$attribute_data->ordering[0]->data() : 0; if (isset($attribute_data->options)) { foreach ($attribute_data->options[0]->option as $option_data) { if (!isset($id_map['options'][(string)$option_data->id[0]->data()])) { $option = new stdClass(); $option->name = html_entity_decode((string)$option_data->name[0]->data(), ENT_QUOTES, "UTF-8"); $option->price = (float)$option_data->price[0]->data(); $option->weight = (float)$option_data->weight[0]->data(); $option->ordering = isset($option_data->ordering) ? (int)$option_data->ordering[0]->data() : 0; drupal_execute('uc_attribute_option_form', (array)$option, $id_map['attributes'][(string)$attribute_data->id[0]->data()]); $id_map['options'][(string)$option_data->id[0]->data()] = db_result(db_query("SELECT MAX(oid) FROM {uc_attribute_options}")); } $opt_replace[] = '%d,%d,%f,%f,%d'; $opt_values[] = $product->nid; $opt_values[] = $id_map['options'][(string)$option_data->id[0]->data()]; $opt_values[] = (float)$option_data->price[0]->data(); $opt_values[] = (float)$option_data->weight[0]->data(); $opt_values[] = isset($option_data->ordering) ? (int)$option_data->ordering[0]->data() : 0; module_invoke_all('xml_importer', 'product-option', $product->nid, $option_data, $store, $id_map); } } $default_option = isset($attribute_data->default_option) ? (string)$attribute_data->default_option[0]->data() : $attribute_data->options->option[0]->id[0]->data(); $attr_values[] = $id_map['options'][$default_option]; module_invoke_all('xml_importer', 'product-attribute', $product->nid, $attribute_data, $store, $id_map); } } if (count($attr_values)) { db_query("DELETE FROM {uc_product_attributes} WHERE nid = %d", $product->nid); db_query("INSERT INTO {uc_product_attributes} (nid, aid, ordering, default_option) VALUES (". implode('),(', $attr_replace) .")", $attr_values); } if (count($opt_values)) { db_query("DELETE FROM {uc_product_options} WHERE nid = %d", $product->nid); db_query("INSERT INTO {uc_product_options} (nid, oid, price, weight, ordering) VALUES (". implode('),(', $opt_replace) .")", $opt_values); } $adjustments = array('nid' => $product->nid, 'default' => $product->model, 'body' => array()); if (isset($product_data->adjustments)) { foreach ($product_data->adjustments[0]->adjustment as $adjustment_data) { $combination = array(); $old_combo = unserialize(html_entity_decode((string)$adjustment_data->combination[0]->data(), ENT_QUOTES, "UTF-8")); if (is_array($old_combo)) { foreach ($old_combo as $aid => $oid) { $combination[$id_map['attributes'][$aid]] = $id_map['options'][$oid]; } $adjustment = array( 'combo_array' => serialize($combination), 'model' => html_entity_decode((string)$adjustment_data->model[0]->data(), ENT_QUOTES, "UTF-8"), ); $adjustments['body'][] = $adjustment; module_invoke_all('xml_importer', 'adjustment', $adjustment, $adjustment_data, $store, $id_map); } } } if (count($adjustments['body'])) { uc_product_adjustments_form_submit('uc_product_adjustments_form', $adjustments); } } // Product-by-product hook call to try and improve efficency if 'uc_import' hook module_invoke_all('xml_importer', 'product', $product, $product_data, $store, $id_map); } // General hook call if data to import isn't too Product specific module_invoke_all('xml_importer', 'store', $store, $id_map); } //} //drupal_set_message('
'. print_r($id_map, true) .''); cache_clear_all(); //} if ($error) { drupal_set_message($error, 'error'); } } /** * Import XML data from a file. * * Callback for file_scan_directory. * * @see uc_importer_import_form_submit */ function uc_importer_directory_parse($filename) { if ($xml = file_get_contents($filename)) { uc_importer_import($xml); } } /** * Specific order importer for a certain osCommerce site. */ function uc_importer_orders($xml) { $id_map = array( 'statuses' => array( 1 => 'pending', 20 => 'in_checkout', 30 => 'pending', 40 => 'processing', 50 => 'processing', 60 => 'completed', 70 => 'completed', -20 => 'canceled', -10 => 'in_checkout', ), 'countries' => array( 38 => 124, // Canada 138 => 484, // Mexico 223 => 840, // United States 240 => 158, // Taiwan 241 => 826, // United Kingdom 242 => 276, // Germany ), 'orders' => array(), 'products' => array(), ); $store = simplexml_load_string($xml); foreach ($store->orders->order as $order_data) { $uid = 0; $user = user_load(array('mail' => (string)$order_data->primary_email)); if ($user) { $uid = $user->uid; } $status = $id_map['statuses'][$order_data->order_status]; $order = uc_order_new($uid, $status); $order_fields = array( 'order_status', 'order_total', 'primary_email', 'delivery_first_name', 'delivery_last_name', 'delivery_phone', 'delivery_company', 'delivery_street1', 'delivery_street2', 'delivery_city', 'delivery_zone', 'delivery_postal_code', 'billing_first_name', 'billing_last_name', 'billing_phone', 'billing_company', 'billing_street1', 'billing_street2', 'billing_city', 'billing_zone', 'billing_postal_code', 'payment_method', 'modified', 'created', ); foreach ($order_fields as $field) { $order->$field = (string)$order_data->$field; } $order->delivery_country = $id_map['countries'][(string)$order_data->delivery_country]; $order->billing_country = $id_map['countries'][(string)$order_data->billing_country]; db_query("UPDATE {uc_orders} SET uid = %d, order_status = '%s', order_total = %f, primary_email = '%s', " ."delivery_first_name = '%s', delivery_last_name = '%s', delivery_phone = '%s', " ."delivery_company = '%s', delivery_street1 = '%s', delivery_street2 = '%s', " ."delivery_city = '%s', delivery_zone = %d, delivery_postal_code = '%s', delivery_country = %d, " ."billing_first_name = '%s', billing_last_name = '%s', billing_phone = '%s', " ."billing_company = '%s', billing_street1 = '%s', billing_street2 = '%s', " ."billing_city = '%s', billing_zone = %d, billing_postal_code = '%s', billing_country = %d, " ."payment_method = '%s', modified = %d, created = %d WHERE order_id = %d", $order->uid, $order->order_status, $order->order_total, $order->primary_email, $order->delivery_first_name, $order->delivery_last_name, $order->delivery_phone, $order->delivery_company, $order->delivery_street1, $order->delivery_street2, $order->delivery_city, $order->delivery_zone, $order->delivery_postal_code, ((is_null($order->delivery_country) || $order->delivery_country == 0) ? variable_get('uc_store_country', 840) : $order->delivery_country), $order->billing_first_name, $order->billing_last_name, $order->billing_phone, $order->billing_company, $order->billing_street1, $order->billing_street2, $order->billing_city, $order->billing_zone, $order->billing_postal_code, ((is_null($order->billing_country) || $order->billing_country == 0) ? variable_get('uc_store_country', 840) : $order->billing_country), $order->payment_method, $order->modified, $order->created, $order->order_id); foreach ($order_data->products->product as $product_data) { $product = new stdClass(); $product->nid = 0; $product_fields = array( 'qty', 'name', 'manufacturer', 'model', 'cost', 'price', 'weight', ); foreach ($product_fields as $field) { $product->$field = (string)$product_data->$field; } $product->data = unserialize((string)$product_data->data); uc_order_product_save($order->order_id, $product); } $comments_types = array(); $comments_values = array(); foreach ($order->comments->comment as $comment) { $comments_types[] = "(%d,%d,'%s',%d,%d,%d)"; $comments_values[] = $order->order_id; $commenter = user_load(array('name' => (string)$comment->user)); if ($commenter) { $comments_values[] = $commenter->uid; } else { $comments_values[] = 0; } $comments_values[] = (string)$comment->message; $comments_values[] = (string)$comment->order_status; $comments_values[] = (int)$comment->notified; $comments_values[] = (int)$comment->created; } if (count($comments_values)) { db_query("INSERT INTO {uc_order_comments} (order_id, uid, message, order_status, notified, created) VALUES ". implode(',', $comments_types), $comments_values); } $comments_types = array(); $comments_values = array(); foreach ($order->admin_comments->comment as $comment) { $comments_types[] = "(%d,%d,'%s',%d)"; $comments_values[] = $order->order_id; $commenter = user_load(array('name' => (string)$comment->user)); if ($commenter) { $comments_values[] = $commenter->uid; } else { $comments_values[] = 0; } $comments_values[] = (string)$comment->message; $comments_values[] = (int)$comment->created; } if (count($comments_values)) { db_query("INSERT INTO {uc_order_admin_comments} (order_id, uid, message, created) VALUES ". implode(',', $comments_types), $comments_values); } } } /** * Invoke hook_xml_exporter(). * * @return * Concatenated XML data from each module's implementation. */ function uc_importer_invoke() { $args = func_get_args(); $direction = array_shift($args); if ($direction = 'export') { $output = ''; foreach (module_list() as $module) { if (module_hook($module, 'xml_exporter')) { // Can't use module_invoke because of the array of arguments $output .= call_user_func_array($module .'_xml_exporter', $args); } } return $output; } }