I am trying to create a rule so that when a node containing a commerce product is update will notify all customers that have made a order containing this product.

I act on event "After updating existing content" and get to the commerce product using entity has field (field_product). How can I get from the product to all the orders containing it so I can loop through them?

1 Answer 1


I ended up creating a module for it as it didn't seem possible to implement using rules.

here is the function that is called on hook_node_update

//load all pending orders
$orders = commerce_order_load_multiple(array(), array('status'=>'pending'), TRUE);
//go through the loaded orders
foreach($orders as $order){
    //load each order as an entity
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach($order_wrapper->commerce_line_items as $line_item_wrapper){
        //check if the order contains this node's product
        $product = $line_item_wrapper->commerce_product;
        $node_product = $node_wrapper->field_product;
        if($product->sku->value() === $node_product->sku->value()){
            //change the status of the order to processing  
            $order_wrapper->status = 'processing';

return TRUE;

Now since I got the respective orders to processing status, I can go on using rules for the rest of the implementation.

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.