Discussions

Display User's Total in Block View

Hi again,

I'm using Commerce to process donations for a "virtual walk" promotion where our members earn 1 mile for ever $1 they donate.

So what I want to do is display in a Views block how many total miles they've walked. I'm using the Aggregation to calculate the some of the user's order total.

I have a Relationship setup to "Relate this order to is owner's user account" using the "Order owner" identifier.

It seems to calculate everything OK except it shows the same total for every user, rather than just that user's total. Rather than showing 20000+ total "miles" walked for the entire site, I want it to just show the miles walked of that authenticated user.

Should I be using a Contextual Filter instead of a Relationship? I'm not really sure I understand the difference very well yet.

Below is the query I'm currently using:

SELECT MIN(commerce_order.order_id) AS order_id, 'commerce_order' AS field_data_commerce_order_total_commerce_order_entity_type, SUM(field_data_commerce_order_total.commerce_order_total_amount) AS field_data_commerce_order_total_commerce_order_total_amount, SUM(field_data_commerce_order_total.commerce_order_total_currency_code) AS field_data_commerce_order_total_commerce_order_total_currenc
FROM
{commerce_order} commerce_order
INNER JOIN {users} users_commerce_order ON commerce_order.uid = users_commerce_order.uid
LEFT JOIN {field_data_commerce_order_total} field_data_commerce_order_total ON commerce_order.order_id = field_data_commerce_order_total.entity_id AND (field_data_commerce_order_total.entity_type = 'commerce_order' AND field_data_commerce_order_total.deleted = '0')
GROUP BY field_data_commerce_order_total_commerce_order_entity_type

Any help would be much appreciated.

Thank you

Posted: Mar 14, 2013

Comments