0

I have 3 content types that I have created: order, product and salesperson.

The fields for each are as follows: Order: Purchaser Name, Product (entity reference to Product), Quantity Product: Product Name, Salesperson (entity reference to Salesperson) Salesperson: Name, Email

The way the system works is that a salesperson creates a product and then sells that product. Each product will be tied to a salesperson (no other salesperson can sell that product). Once they receive an order, they would create "content" containing the name of the person buying the product, what product it was, and the quantity they sold.

I'm trying to figure out how to create a view that would let me allow a user to choose a product and have the view show how many of that product were sold.

Did I set this up the right way using 3 different content types with entity references or is there a better option? If so, how can I show the sum of all the orders tied to a certain product?

1 Answer 1

1

What you are looking for is the equivalent of SQL aggregation. I have done this successfully in a Drupal 6 install using the Views Group By module. The process is pretty simple as long as you are reasonably familiar with views. Your setup sounds like exactly what you should have for this case.

In Drupal 7, the equivalent functionality is built into the default views module. You will need to open the "Advanced" section to see it.

An alternative approach would be to write a custom module that creates the SQL aggregation itself. But it sounds like you are already familiar with views and should stick with this approach.

2
  • Thanks for the response. So I should be looking into using aggregation in Views.
    – SQL Newbie
    Commented Oct 24, 2014 at 13:20
  • If you are using Drupal 7, yes. You could also hand-code it but I suspect it would be far more cumbersome. Commented Oct 24, 2014 at 13:22

Your Answer

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

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