function bpc_taxonomy_commerce_bpc_get_combinations in Commerce Bulk Product Creation 7
Same name and namespace in other branches
- 7.2 modules/bpc_taxonomy/bpc_taxonomy.module \bpc_taxonomy_commerce_bpc_get_combinations()
Implements hook_commmerce_bpc_get_combinations().
@todo: This is EXACTLY the same as the list implementation, except for three places where 'list' needs to be replaced by 'bpc_taxonomy'. Refactoring.
File
- modules/
bpc_taxonomy/ bpc_taxonomy.module, line 68 - The Commerce BPC Taxonomy integration module enables the use of taxonomy term references in bulk creation.
Code
function bpc_taxonomy_commerce_bpc_get_combinations($form, &$form_state, &$combinations) {
if (isset($form_state['commerce_bpc']['bpc_taxonomy'])) {
$new_combinations = array();
$fields = $form_state['commerce_bpc']['bpc_taxonomy']['combination_fields'];
foreach ($fields as $field_name) {
$new_combinations = array();
// Todo: Treat languages properly.
$langs = array_keys($form_state['values']['combinations'][$field_name]);
$lang = reset($langs);
$values =& $form_state['values']['combinations'][$field_name][$lang];
if (empty($values)) {
// If no value is present, we skip processing this field.
continue;
}
foreach ($combinations as $combination) {
foreach ($values as &$columns) {
if ($columns['tid'] == 'autocreate') {
// We save new values entered into the autocomplete here---for there
// there is no sensible way to create combinations if the term does
// not exist.
$term = (object) $columns;
unset($term->tid);
taxonomy_term_save($term);
$columns['tid'] = $term->tid;
}
if (!taxonomy_field_is_empty($columns, $field_name)) {
$new_combinations[] = $combination + array(
$field_name => array(
$lang => array(
$columns,
),
),
);
}
else {
$new_combinations[] = $combination;
// If the values for a field are empty, we make sure that
// we (re)-add the original combination only once.
break;
}
}
}
$combinations = $new_combinations;
}
}
}