Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | commerce_bpc-set-language-on-bulk-creation-issue-1623060.patch | 437 bytes | dawitti |
Bildschirmfoto.png | 116.35 KB | dawitti |
Comments
Comment #1
dawitti CreditAttribution: dawitti commentedHere'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)
Comment #2
dawitti CreditAttribution: dawitti commentedComment #3
dawitti CreditAttribution: dawitti commentedComment #4
sven.lauer CreditAttribution: sven.lauer commentedCommitted, thanks!
The 2.x branch also now has proper language selection & handling.