function uc_importer_export in Ubercart 5
Constructs the XML representation of the store from the ids given.
Parameters
$nids: An array of product ids.
Return value
XML data to be sent.
3 calls to uc_importer_export()
- uc_importer_export_buffer_form_submit in uc_importer/
uc_importer.module - Submit handler for uc_importer_export_buffer_form().
- uc_importer_export_form_submit in uc_importer/
uc_importer.module - Submit handler for uc_importer_form().
- uc_repeater_export in uc_repeater/
uc_repeater.module - Pushes new products to other sites.
File
- uc_importer/
uc_importer.module, line 371 - XML product importer and exporter.
Code
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('<pre>' . print_r($data, true) . '</pre>');
$xml = '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
$xml .= '<store xmlns="http://www.ubercart.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ubercart.org http://www.ubercart.org/files/store.xsd">';
if (is_array($data['vocabularies']) && !empty($data['categories'])) {
$xml .= _uc_importer_export_vocabularies($data['vocabularies']);
}
if (is_array($data['categories']) && !empty($data['categories'])) {
$xml .= _uc_importer_export_categories($data['categories']);
}
if (is_array($data['manufacturers']) && !empty($data['manufacturers'])) {
$xml .= _uc_importer_export_manufacturers($data['manufacturers']);
}
if (is_array($data['attributes']) && !empty($data['attributes'])) {
$xml .= _uc_importer_export_attributes($data['attributes']);
}
if (is_array($data['classes']) && !empty($data['classes'])) {
$xml .= _uc_importer_export_classes($data['classes']);
}
if (is_array($data['products']) && !empty($data['products'])) {
$xml .= _uc_importer_export_products($data['products']);
}
if (is_array($data['orders']) && !empty($data['orders'])) {
$xml .= _uc_importer_export_orders($data['orders']);
}
$xml .= uc_importer_invoke('export', 'store', $nids);
$xml .= '</store>';
//drupal_set_message(htmlspecialchars($xml));
return $xml;
}