-
-
Save EHLOVader/8601735 to your computer and use it in GitHub Desktop.
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 | |
public function subscribeEvents() | |
{ | |
Backend::$events->addEvent('shop:onExtendCategoryModel', $this, 'extend_category_model'); | |
} | |
public function extend_category_model($category, $context) | |
{ | |
$total_sales = "SELECT count(totals_shop_order_items.id)*totals_shop_order_items.quantity | |
FROM shop_products_categories as totals_shop_products_categories | |
LEFT JOIN shop_categories totals_shop_categories | |
ON totals_shop_products_categories.shop_category_id = totals_shop_categories.id | |
LEFT JOIN shop_products totals_shop_products | |
ON totals_shop_products_categories.shop_product_id = totals_shop_products.id | |
LEFT JOIN totals_shop_order_items totals_shop_order_items | |
ON totals_shop_products.id = as totals_shop_order_items.shop_product_id | |
LEFT JOIN shop_orders totals_shop_orders | |
ON totals_shop_order_items.shop_order_id = totals_shop_orders.id | |
WHERE totals_shop_orders.payment_processed IS NOT NULL | |
AND totals_shop_categories.id = shop_categories.id | |
"; | |
$category->define_column('total_sales', 'Total sales'); | |
$category->calculated_columns['total_sales'] = array( | |
'sql' => $total_sales, | |
'type' => db_number | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment