0

In a custom module I am adding data to a line item added to the cart like this:

$user_to_add =_get_user_by_ain($ain);
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, 1, 0, array('apply_to_user' => $user_to_add));
commerce_cart_product_add($user->uid, $line_item);

This data is used in Rules after checkout is completed. What I'm struggling with now is being able to show that data in the cart view (default, Commerce provided, commerce_cart_form). For example, if the $user_to_add contains the users first name, I'd like to be able to show that in the cart view next to the product label.

I've been going through the views api, testing the hooks available, and I can't figure out where to do this. In the hooks that I've tried, the data is is available in $view->result[0]->_field_data['commerce_line_item_field_data_commerce_line_items_line_item_]['entity']->data['apply_to_user']

1 Answer 1

1

If you're wanting to display information from inside the $order->data array, then you'll need to create a Views handler for each value and write some code to load the object, access the data, and then display it. An example of how to do this can be found in the GetID3 views integration. It loads file metadata and exposes it to views, but the idea is the same.

1
  • Thanks @nvahalik. After digging around I think I'm nearing the conclusion: you do answer the question, but I was asking the wrong question. I should have been using a custom line item type for this scenario. Once I switched to that mindset, I was able to programmatically create the line item, add the fields to it, save the order and now everything is available in views. Will probably accept this answer and try to phrase a new question that might help someone else in a similar situation. Dec 3, 2015 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.