created a product with an option set (e.x. pizza toppings) , have set prices for each option.
when the allowed value is 1 everything works great either with select list or radio button.
when allowed value is set to unlimited ( checkboxes) the price of the product is not affected in any way.
I can see the ajax firing but price is not updated

Comments

wqmeng’s picture

Hello VKazakid

Should we also check the module Multiple Selects and get commerce_pricing_attributes work with it?

http://drupal.org/project/multiple_selects

I also created another issue ticket to support Multiple Selects, Which maybe make sense.

#1906122: Support various widgets for list field type

Thanks

VKazakid’s picture

Hi,
I did the following that resolved my issue,(now unlimited option values work with check boxes fine):
function commerce_pricing_attributes_calculate_adjusment($line_item_wrapper){
$commerce_attribute_adjustment = 0;

$attributes = array();
$commerce_product_fields = field_info_instances('commerce_product', $line_item_wrapper->commerce_product->type->value());
foreach ($commerce_product_fields as $field_name => $field_instance) {
$field = field_info_field($field_name);
if($field['type'] == 'commerce_pricing_attributes'){
$attributes[$field_name] = $line_item_wrapper->commerce_product->{$field_name}->value();
}
}

if(!empty($attributes)){
$commerce_option_list = commerce_option_load_by_line_item($line_item_wrapper->line_item_id->value());
if(isset($line_item_wrapper->value()->data['commerce_option_list'])){
$commerce_option_list = $line_item_wrapper->value()->data['commerce_option_list'];
}

if(!empty($commerce_option_list)){
foreach($commerce_option_list as $commerce_option){
if(!array_key_exists($commerce_option->field_name, $attributes)){
continue;
}
$commerce_option_wrapper = entity_metadata_wrapper('commerce_option', $commerce_option);
$attribute = $attributes[$commerce_option->field_name];
$option_fields = field_info_instances('commerce_option', $commerce_option->set_id);
foreach ($option_fields as $field_name => $field) {
$selected_options = $commerce_option_wrapper->{$field_name}->value();
if(!empty($selected_options) and isset($attribute['set_details'][$field_name]['options'])){
if(is_array($selected_options)){
foreach($selected_options as $selected_option){
$price = $attribute['set_details'][$field_name]['options'][$selected_option]['price'];
if($price > 0){
switch ($attribute['set_details'][$field_name]['options'][$selected_option]['price_op']) {
case 'minus':
$commerce_attribute_adjustment -= $price;
break;
case 'plus':
default:
$commerce_attribute_adjustment += $price;
break;
}

}
}
}
else
{
$price = $attribute['set_details'][$field_name]['options'][$selected_options]['price'];
if($price > 0){
switch ($attribute['set_details'][$field_name]['options'][$selected_options]['price_op']) {
case 'minus':
$commerce_attribute_adjustment -= $price;
break;
case 'plus':
default:
$commerce_attribute_adjustment += $price;
break;
}

}

}
}
}
}
}
}
but because this is the first time i wrote any php code i am not sure if it is written as it should.
please review and comment
thanks,
vkazakid

nchar’s picture

Status: Active » Fixed

Hi VKazakid!

The issue is now fixed and committed to the latest dev version. You have done good work with your first code, keep on contributing! Please the next time use a patch instead of raw code in the issue queue.. Thanks anyway.

Status: Fixed » Closed (fixed)

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