0

I have two content types. Let's call them "A" and "B".

A has nodes with field_cost

B has nodes with field_total_cost

Content type A has a field_costumer which is referenced to the entity of Content B.

Which means, the title of Content B node = value of field_costumer of Node A.

They have Many-to-one relationship. In the picture below, Node x has two nodes attached to it and so does Node y.

enter image description here

I wanted to calculate the total number of nodes of content type A that are attached to a particular node of content type B (say node X).

I was able to accomplish:

$type = 'A';
$nid = $entity->nid;
$query = new EntityFieldQuery;
$result = $query
->entityCondition('entity_type', 'node')
->propertyCondition('status', 1)
->propertyCondition('type', $type)
->fieldCondition('field_customer', 'target_id', $nid ,'=')
->execute();

$cant = count($result['node']);
$entity_field[0]['value'] = $cant;

I got the desired result which was:

2

Now here is the problem: I want to sum a particular column(field) of content type A nodes which are connected to Node X.

I am using computed field drupal 7 module.

I tried different ways, for example, using field_cost_value and passed it as the column name instead of usual entity reference's target_id. I created a variable and tried to load the node of the content type A and passing it to result as $result['node']['field_cost'] but failed.

I am out of my stretch here. Help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.