Skip to content

Instantly share code, notes, and snippets.

@EHLOVader
Forked from GreatPotato/gist:6902395
Last active December 25, 2015 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EHLOVader/6902579 to your computer and use it in GitHub Desktop.
Save EHLOVader/6902579 to your computer and use it in GitHub Desktop.
Total number of items sold
<?php
$obj = new Shop_Product();
$obj->select('shop_products.id, sum(shop_order_items.quantity) AS "sold"');
$obj->join('shop_order_items', 'shop_products.id = shop_order_items.shop_product_id');
$obj->join('shop_orders', 'shop_order_items.shop_order_id = shop_orders.id');
$best_selling = $obj->where('shop_orders.payment_processed IS NOT NULL')->group('shop_products.id')->find_all();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment