function _uc_importer_export_products in Ubercart 5
Export products as XML.
1 call to _uc_importer_export_products()
- uc_importer_export in uc_importer/
uc_importer.module - Constructs the XML representation of the store from the ids given.
File
- uc_importer/
uc_importer.module, line 559 - XML product importer and exporter.
Code
function _uc_importer_export_products($products) {
$xml = '<products>';
foreach ($products as $nid) {
$xml .= '<product>';
$product = node_load($nid);
$xml .= '<unique_hash>' . $product->unique_hash . '</unique_hash>';
$xml .= '<id>' . $product->nid . '</id>';
$xml .= '<type>' . $product->type . '</type>';
$xml .= '<name>' . htmlspecialchars($product->title, ENT_QUOTES, "UTF-8") . '</name>';
$xml .= '<description>' . htmlspecialchars($product->body, ENT_QUOTES, "UTF-8") . '</description>';
$xml .= '<model>' . htmlspecialchars($product->model, ENT_QUOTES, "UTF-8") . '</model>';
if (module_exists('uc_manufacturer')) {
$manufacturer = uc_product_get_manufacturer($product->nid);
$xml .= isset($manufacturer->tid) ? '<manufacturer>' . htmlspecialchars($manufacturer->name, ENT_QUOTES, "UTF-8") . '</manufacturer>' : '';
}
$xml .= isset($product->list_price) ? '<list_price>' . $product->list_price . '</list_price>' : '';
$xml .= isset($product->cost) ? '<cost>' . $product->cost . '</cost>' : '';
$xml .= '<sell_price>' . $product->sell_price . '</sell_price>';
$xml .= '<weight>' . $product->weight . '</weight>';
$xml .= '<weight_units>' . $product->weight_units . '</weight_units>';
$xml .= '<length>' . $product->length . '</length>';
$xml .= '<width>' . $product->width . '</width>';
$xml .= '<height>' . $product->height . '</height>';
$xml .= '<length_units>' . $product->length_units . '</length_units>';
$xml .= '<pkg_qty>' . $product->pkg_qty . '</pkg_qty>';
$xml .= '<default_qty>' . $product->default_qty . '</default_qty>';
$xml .= '<shippable>' . $product->shippable . '</shippable>';
if (isset($product->field_image_cache) && file_exists($product->field_image_cache[0]['filepath'])) {
foreach ($product->field_image_cache as $image) {
$xml .= '<image>';
$xml .= '<path>' . $GLOBALS['base_url'] . '/' . dirname($image['filepath']) . '/' . rawurlencode(basename($image['filepath'])) . '</path>';
if (!empty($image['alt'])) {
$xml .= '<alt>' . $image['alt'] . '</alt>';
}
if (!empty($image['title'])) {
$xml .= '<title>' . $image['title'] . '</title>';
}
$xml .= '</image>';
}
}
if (module_exists('content')) {
$type = content_types($product->type);
if (count($type['fields'])) {
$field_xml = '';
foreach ($type['fields'] as $field) {
if ($field['field_name'] != 'field_image_cache') {
$node_field = isset($product->{$field}['field_name']) ? $product->{$field}['field_name'] : array();
if (count($node_field)) {
$field_xml .= '<field>';
$field_xml .= '<name>' . $field['field_name'] . '</name>';
foreach ($node_field as $columns) {
$field_xml .= '<delta>';
foreach ($columns as $name => $value) {
$field_xml .= '<' . $name . '>' . $value . '</' . $name . '>';
}
$field_xml .= '</delta>';
}
$field_xml .= '</field>';
}
}
}
if ($field_xml) {
$xml .= "<fields>{$field_xml}</fields>";
}
}
}
if (module_exists('taxonomy')) {
$terms = taxonomy_node_get_terms($product->nid);
$xml .= '<categories>';
foreach ($terms as $term) {
$xml .= '<category>';
$xml .= '<id>' . $term->tid . '</id>';
$xml .= '</category>';
}
$xml .= '</categories>';
}
if (module_exists('uc_attribute')) {
$attributes = uc_product_get_attributes($product->nid);
if (!empty($attributes)) {
$xml .= '<attributes>';
foreach ($attributes as $attribute) {
$xml .= '<attribute>';
$xml .= '<id>' . $attribute->aid . '</id>';
$xml .= '<name>' . htmlspecialchars($attribute->name, ENT_QUOTES, "UTF-8") . '</name>';
$xml .= '<ordering>' . $attribute->ordering . '</ordering>';
$xml .= '<default_option>' . $attribute->default_option . '</default_option>';
if (!empty($attribute->options)) {
$xml .= '<options>';
foreach ($attribute->options as $option) {
$xml .= '<option>';
$xml .= '<id>' . $option->oid . '</id>';
$xml .= '<name>' . htmlspecialchars($option->name, ENT_QUOTES, "UTF-8") . '</name>';
$xml .= '<price>' . $option->price . '</price>';
$xml .= '<weight>' . $option->weight . '</weight>';
$xml .= '<ordering>' . $option->ordering . '</ordering>';
$xml .= uc_importer_invoke('export', 'product-option', $product->nid, $option->oid);
$xml .= '</option>';
}
$xml .= '</options>';
}
$xml .= uc_importer_invoke('export', 'product-attribute', $product->nid, $attribute->aid);
$xml .= '</attribute>';
}
$xml .= '</attributes>';
}
$result = db_query("SELECT combination, model FROM {uc_product_adjustments} WHERE nid = %d", $product->nid);
if (db_num_rows($result)) {
$xml .= '<adjustments>';
while ($adjustment = db_fetch_object($result)) {
$xml .= '<adjustment>';
$xml .= '<combination>' . htmlspecialchars($adjustment->combination, ENT_QUOTES, "UTF-8") . '</combination>';
$xml .= '<model>' . htmlspecialchars($adjustment->model, ENT_QUOTES, "UTF-8") . '</model>';
$xml .= uc_importer_invoke('export', 'adjustment', $adjustment, $product->nid);
$xml .= '</adjustment>';
}
$xml .= '</adjustments>';
}
}
$xml .= uc_importer_invoke('export', 'product', $product->nid);
$xml .= '</product>';
}
$xml .= '</products>';
return $xml;
}