function globallink_commerce_get_xml in GlobalLink Connect for Drupal 7.7
Gets XML data from specific commerce product.
Parameters
string $pid: The commerce product ID.
Return value
array Associative array of commerce product XML data.
2 calls to globallink_commerce_get_xml()
- globallink_commerce_preview_content in globallink_commerce/
globallink_commerce_send.inc - Helper function
- globallink_commerce_send_for_translations in globallink_commerce/
globallink_commerce.inc - Sends commerce for translation.
File
- globallink_commerce/
globallink_commerce.inc, line 81
Code
function globallink_commerce_get_xml($pid, $target_arr) {
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = TRUE;
$root = $dom
->createElement('content');
$dom
->appendChild($root);
$id = $dom
->createAttribute('pid');
$id->value = $pid;
$root
->appendChild($id);
$commerce_product = commerce_product_load($pid);
$language = $commerce_product->language;
if (module_exists('metatag')) {
$lang = entity_language('commerce_product', $commerce_product);
if (isset($commerce_product->metatags)) {
if (globallink_is_field_configured_for_translation('commerce_product', 'cp:' . $commerce_product->type, 'metatags', 'cp:' . $commerce_product->type)) {
if (!empty($commerce_product->metatags[$lang])) {
$metatags = $commerce_product->metatags[$lang];
foreach ($metatags as $name => $value) {
if (isset($value['value'])) {
globallink_insert_child_element($dom, $root, 'metatag', $value['value'], array(
'entity_type' => 'commerce_product',
'name' => $name,
'label' => 'Metatag - ' . ucwords($name),
));
}
}
}
}
}
}
$fields = globallink_commerce_get_fields($commerce_product->type);
$configured_fields = globallink_get_configured_fields_for_cp($commerce_product->type);
foreach ($fields as $field) {
if (empty($commerce_product->{$field})) {
continue;
}
$language = field_language('commerce_product', $commerce_product, $field, NULL);
$field_values = field_get_items('commerce_product', $commerce_product, $field, $language);
$field_info = field_info_field($field);
if ($field_values) {
$parent_fc = '';
if ($field_info['type'] == 'field_collection') {
$parent_fc = $field;
if (isset($field_values[0]['revision_id'])) {
$field_collection_item_entity = entity_load('field_collection_item', array(
$field_values[0]['value'],
), array(
'revision_id' => $field_values[0]['revision_id'],
));
}
globallink_commerce_traverse_fields_and_field_collections('commerce_product', $commerce_product->type, $parent_fc, $commerce_product->type, $commerce_product->pid, $field_values, $field, $dom, $root, $commerce_product, $target_arr, $language);
}
}
if (array_key_exists($field, $configured_fields) && $configured_fields[$field]->translatable == 1) {
$field_values = field_get_items('commerce_product', $commerce_product, $field, $language);
$field_info = field_info_field($field);
if (is_array($field_values) && !empty($field_values)) {
foreach ($field_values as $delta => $values) {
if ($field_info['type'] == 'link_field') {
globallink_insert_child_element($dom, $root, 'field', $values['title'], array(
'field_name' => $field,
'delta' => $delta,
'langcode' => $language,
));
}
elseif ($field_info['type'] == 'image') {
if (isset($values['alt'])) {
globallink_insert_child_element($dom, $root, 'field_image', $values['alt'], array(
'field_name' => $field,
'type' => 'alt',
'delta' => $delta,
'langcode' => $language,
));
}
if (isset($values['title'])) {
globallink_insert_child_element($dom, $root, 'field_image', $values['title'], array(
'field_name' => $field,
'type' => 'title',
'delta' => $delta,
'langcode' => $language,
));
}
}
elseif (!empty($values['value'])) {
globallink_insert_child_element($dom, $root, 'field', $values['value'], array(
'field_name' => $field,
'delta' => $delta,
'langcode' => $language,
));
}
}
}
elseif (!empty($field_values) && is_string($field_values)) {
// Test this without field translation
globallink_insert_child_element($dom, $root, 'field', $field_values, array(
'field_name' => $field,
));
}
}
}
$xml = $dom
->saveXML();
return $xml;
}