Skip to content

Instantly share code, notes, and snippets.

@EHLOVader
Forked from GreatPotato/gist:8600713
Last active January 4, 2016 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EHLOVader/8601735 to your computer and use it in GitHub Desktop.
Save EHLOVader/8601735 to your computer and use it in GitHub Desktop.
<?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