Drupal commerce get quantity per sku in hook_commerce_checkout_complete Inside this hook I need the total products per sku. For example, user #1 buy 2 products with the sku #7, user #2 buy 5 products with the sku #10. I need to know how to get:


sku #7 -> 2
sku #10 -> 5


I was trying something like:

foreach ( $order-&gt;commerce_line_items as $line_item ) {
   $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
   $line_item_wrapper-&gt;commerce_product-&gt;sku-&gt;value();
}   


But it gives me just sku #7 and sku #10. Also, this function commerce_line_items_quantity($line_items) didn't help so much because it gave me just the total of all sku's, not individually.

This way I can award the user with some "user points" (I think is easier this way than using rules).
You need to wrap the $order object before looping over the line items. It also removes the need to wrap the line items explicitly.

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
foreach ( $order_wrapper-&gt;commerce_line_items as $line_item_wrapper ) {
  if ($line_item_wrapper-&gt;commerce_product-&gt;sku-&gt;value() == 'some-SKU') {
    // increment quantity counter, award points etc.
  }
}