Discussions

Check products values on order completion

Please could someone point me in the right direction to do the following?

I want after an order has been marked as completed, to run a function that will add all values of products in the order. Each product has numeric custom field. I want to add all the values of the products in the completed order.

Which hook should I use? In which way?

Posted: Jun 5, 2011

Comments

yannisc on June 5, 2011

Digging, I found out how to do it. Maybe that helps someone else:

function hook_commerce_checkout_router($order, $checkout_page) {
if ($checkout_page['page_id'] == 'complete') {
if(!($order instanceof EntityMetadataWrapper)) {
$order = entity_metadata_wrapper('commerce_order', $order);
}
foreach ($order->commerce_line_items as $line_item) {
$qty = $line_item->quantity->value();
$prod_credits = $line_item->commerce_product->field_product_credits->value();

}
}
}