You are here

function uuid_commerce_product_features_export_render in UUID Features Integration 7

Implements hook_features_export_render().

File

includes/uuid_commerce_product.features.inc, line 77
Features hooks for the uuid_commerce_product features component.

Code

function uuid_commerce_product_features_export_render($module, $data) {
  $translatables = $code = array();
  $code[] = '  $products = array();';
  $code[] = '';
  $product_ids = entity_get_id_by_uuid('commerce_product', $data);

  // Always sort by the uuid to ensure the order is maintained.
  ksort($product_ids);
  foreach ($product_ids as $uuid => $product_id) {

    // Only export the node if it exists.
    if ($product_id === FALSE) {
      continue;
    }

    // Attempt to load the product, using a fresh cache.
    $products = commerce_product_load_multiple(array(
      $product_id,
    ), NULL, TRUE);
    if (empty($products)) {
      continue;
    }
    $product = reset($products);
    if (!empty($product->path)) {
      $product->pathauto_perform_alias = FALSE;
    }

    // Clone entity to avoid changes by reference.
    $export = clone $product;

    // Don't cause conflicts with product_id/vid/revision_timestamp/changed
    // fields.
    uuid_features_file_field_export($export, 'commerce_product');
    $entity_type = 'commerce_product';
    drupal_alter('uuid_entity_features_export_render', $entity_type, $export, $product, $module);
    drupal_alter('uuid_commerce_product_features_export_render', $export, $product, $module);
    unset($export->changed);
    unset($export->revision_uid);
    unset($export->revision_timestamp);
    unset($export->product_id);
    unset($export->revision_id);
    unset($export->cid);
    $code[] = '  $products[] = ' . features_var_export($export) . ';';
  }
  if (!empty($translatables)) {
    $code[] = features_translatables_export($translatables, '  ');
  }
  $code[] = '  return $products;';
  $code = implode("\n", $code);
  return array(
    'uuid_features_default_commerce_product' => $code,
  );
}