When I bulk create products they don't get a language (not even LANGUAGE_NONE) set (see screenshot. the last 2 products were bulk created the others manually).

The code actually calling commerce_product_new() and commerce_product_save() does not set the language attribute. I had a look into the code of those functions and the language is not set in there as well.

Is there a reason why the new product's status and uid are set, but not language?

Thanks, Martin

The concerned code is the following (commerce_bpc.module, line 331):

function commerce_bpc_create_product($product_type, $combination, $static_values, $extras) {
  $form_state = array();
  $form_state['values'] = $static_values;
  $form = array();
  $form['#parents'] = array();

  // Generate a new product object.
  $new_product = commerce_product_new($product_type);

  $new_product->status = $extras['status'];
  $new_product->uid = $extras['uid'];

  // Replace the tokens for the SKU and Title.
  $data = array();
  $data['bulk_data'] = array(
    'combination' => $combination,
    'static_values' => $static_values,
    'product_type' => $product_type,
  );
  $new_product->sku = token_replace($extras['sku_pattern'], $data, array('sanitize' => FALSE));
  $new_product->title = token_replace($extras['title_pattern'], $data, array('sanitize' => FALSE));

  // Set the proper values in the form_state for this product's combination of
  // fields.
  foreach ($combination as $field => $value) {
    $form_state['values'][$field] = $value;
  }
  // Notify field widgets to save their field data.
  field_attach_submit('commerce_product', $new_product, $form, $form_state);

  commerce_product_save($new_product);
  return $new_product->product_id;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawitti’s picture

Here's the patch to set the language in commerce_bpc_create_product(). It works for me.
(It's my first patch to drupal, so tell me if something is amiss)

dawitti’s picture

Status: Active » Needs review
dawitti’s picture

Title: Bulk created products » Bulk created product entities don't have a language set
sven.lauer’s picture

Status: Needs review » Fixed

Committed, thanks!

The 2.x branch also now has proper language selection & handling.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.