How to use hook_entity_presave? I have a product type called package. It is a package of another product type which is called applications; when a user wants to create or update a package , I want to calculate the price of the package by adding the price of all applications in that package . I want to use hook_entity_presave(). but it doesn't work. I have put my function here. 

My question: what should I check exactly against the $entity-&gt;type? My node type? Or my product type? It doesn't work either way.

function itunesdev_entity_presave(&amp;$entity, $type) {
  if($entity-&gt;type == 'package') {
    $product_ids = array();   
    foreach($entity-&gt;field_products[LANGUAGE_NONE] as $key =&gt; $pid)
      $product_ids[] = $pid['target_id'];   
    $products = entity_load('commerce_product', $product_ids);   
    // reset default price
    $entity-&gt;commerce_price[LANGUAGE_NONE][0]['amount'] = 0;
    foreach($products as $pid =&gt; $product) {
      $entity-&gt;commerce_price[LANGUAGE_NONE][0]['amount'] += $product-&gt;commerce_price[LANGUAGE_NONE][0]['amount'];
    }
  }
}
Function hook_entity_presave acts on an entity before it is about to be created or updated


Code:

  function hook_entity_presave($entity, $type) {
    $entity-&gt;changed = REQUEST_TIME;
  }


source :  Drupal API