I would like to be able to add registrations to the commerce cart even if they are free.

I have some free registrations and some chargeable registrations, but I want them all to go through the commerce checkout workflow.

Thanks you for this module.

CommentFileSizeAuthor
#2 allow_0_value_payment.patch662 bytesgcb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lightsurge’s picture

There seemed to be a few architectural changes to the module that would be needed to get this working. Various places value was being checked.

So I just implemented a few hooks to adjust the price to '1', and then change it back to 0 in the cart (since none of my real items value will ever be 1, i.e 1 penny, I hope!).

Not a good solution, but in case it helps anybody:

function MODULE_registration_commerce_calculate_price($data, $info) {
  $date = node_load($data->entity_id); 
  $course = node_load($date->field_course[LANGUAGE_NONE][0]['target_id']);
  $value = (int) $course->field_price[LANGUAGE_NONE][0]['amount'] ? (int) $course->field_price[LANGUAGE_NONE][0]['amount'] : 1;
  return array('amount'=>$value,'currency_code'=>'GBP');
}

function MODULE_commerce_product_calculate_sell_price_line_item_alter($line_item){
  if ((int) $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['amount'] == 1) {
    $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['amount'] = 0;
  }
}

function MODULE_commerce_cart_line_item_refresh($line_item, $order_wrapper){
  if ((int) $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['amount'] == 1) {
    $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['amount'] = 0;
    if (isset($line_item->commerce_unit_price[LANGUAGE_NONE]['0']['data']['components']['0']['price']['amount'])) {
      $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['data']['components']['0']['price']['amount']=0;
    }
    if (isset($line_item->commerce_unit_price[LANGUAGE_NONE]['0']['data']['components']['1']['price']['amount'])) {
      $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['data']['components']['1']['price']['amount']=0;
    }
  }
}
gcb’s picture

Status: Active » Closed (fixed)
FileSize
662 bytes

This is fixed in the latest commit. Here's a patch you can apply. Make sure your items have a "0" price at least, though. Null prices still won't work.