Created
October 9, 2013 14:41
-
-
Save GreatPotato/6902395 to your computer and use it in GitHub Desktop.
Gets best selling products in the current category - LemonStand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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