Typo on line 21. The price array should have 'currency_code' instead of 'currency'. This slowed me down a bit until I realized why.

CommentFileSizeAuthor
#3 issue-2861384.patch376 bytessonoutlaw
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sonoutlaw created an issue. See original summary.

sonoutlaw’s picture

Issue summary: View changes
sonoutlaw’s picture

FileSize
376 bytes
gcb’s picture

Status: Active » Reviewed & tested by the community
fonant’s picture

I discovered this too :)

As well as building an array, you can return the value of a Price field.

For example I configured the Event node to have two Price fields for members and non-members, and configured the Registration to have a "member/non-member" radiobutton. This code uses the radiobutton value to apply the correct price to the line item:

function MYMODULE_registration_commerce_calculate_price($registration, $info) {
  if ($registration->type == 'event_registration') {
    $registration_wrapper = entity_metadata_wrapper('registration', $registration);
    $entity = entity_load_single($registration->entity_type, $registration->entity_id);
    $entity_wrapper = entity_metadata_wrapper($registration->entity_type, $entity);
    switch ($registration_wrapper->field_rate->value()) {
      case 'member':
        return $entity_wrapper->field_price_member->value();
        break;
      case 'non-member':
        return $entity_wrapper->field_price_non_member->value();
        break;
    }
  }
}

  • gcb committed e994e42 on 7.x-1.x authored by sonoutlaw
    Issue #2861384 by sonoutlaw: Typo in registration_commerce.api.php
    
gcb’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Committed.

Status: Fixed » Closed (fixed)

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