Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
Created October 9, 2013 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GreatPotato/6902395 to your computer and use it in GitHub Desktop.
Save GreatPotato/6902395 to your computer and use it in GitHub Desktop.
Gets best selling products in the current category - LemonStand
<?php
$obj = new Shop_Product();
$obj->select('count(shop_order_items.id) AS "sold"');
$obj->join('shop_products_categories', 'shop_products.id = shop_products_categories.shop_product_id');
$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_products_categories.shop_category_id=? AND shop_orders.payment_processed IS NOT NULL', $category->id)->group('shop_products.id')->order('count(shop_order_items.id) DESC')->limit(3)->find_all();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment