You are here

function commerce_pricing_attributes_entity_load in Commerce Pricing Attributes 7

Implements hook_entity_load().

Create an alias od commerce_pricing_attributes property in line item on load. We need it to use it at card combines.

File

./commerce_pricing_attributes.module, line 1270

Code

function commerce_pricing_attributes_entity_load(&$entities, $type) {
  if ($type == 'commerce_line_item') {
    foreach ($entities as &$entity) {
      $entity->commerce_pricing_attributes = array();
      $commerce_options = commerce_option_load_by_line_item($entity->line_item_id);
      foreach ($commerce_options as $commerce_option) {
        $commerce_option_wrapper = entity_metadata_wrapper('commerce_option', $commerce_option);
        $fields = field_info_instances('commerce_option', $commerce_option->set_id);
        foreach ($fields as $field_name => $field) {
          $entity->commerce_pricing_attributes[$commerce_option->set_id][$field_name] = $commerce_option_wrapper->{$field_name}
            ->value();
          asort($entity->commerce_pricing_attributes[$commerce_option->set_id]);
        }
      }
      asort($entity->commerce_pricing_attributes);
      $entity->commerce_pricing_attributes = serialize($entity->commerce_pricing_attributes);
    }
  }
}