Guest User

shopPieWidgetSalesbycat.class.php

a guest
Oct 9th, 2015
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Created by PhpStorm.
  5.  * User: snark | itfrogs.ru
  6.  * Date: 9/24/15
  7.  * Time: 5:17 PM
  8.  */
  9. class shopPieWidgetSalesbycat
  10. {
  11.     private $settings;
  12.  
  13.     function __construct($settings)
  14.     {
  15.         $this->settings = $settings;
  16.     }
  17.  
  18.     public function getData() {
  19.         $olm = new shopOrderLogModel();
  20.         $oim = new shopOrderItemsModel();
  21.         $cam = new shopCategoryModel();
  22.  
  23.         $categories = $cam->getByField('parent_id', 0, true);
  24.         $cats = array();
  25.         foreach ($categories as $key => $category) {
  26.             $cats[$category['id']] = $category;
  27.             $subs = $cam->getTree($category['id']);
  28.             $cats[$category['id']]['subcategories'] = array_keys($subs);
  29.             $cats[$category['id']]['count'] = 0;
  30.         }
  31.  
  32.         $title = _wp('Sales by Category');
  33.         if (!$this->settings['period']) {
  34.             $this->settings['period'] = 86400;
  35.         }
  36.         if (!$this->settings['action']) {
  37.             $this->settings['action'] = 'create';
  38.         }
  39.  
  40.         $smps = array($title);
  41.         $vars = array();
  42.         $data = array();
  43.  
  44.         $model = new waModel();
  45.         foreach ($cats as $key => $cat) {
  46.             $cat['count'] = $model->query(
  47.                 'SELECT COUNT(i.id) FROM shop_order_items i '
  48.                 .'JOIN shop_order_log o ON o.order_id = i.order_id '
  49.                 .'WHERE (o.action_id = s:action AND UNIX_TIMESTAMP(o.datetime) > (UNIX_TIMESTAMP(NOW()) - i:period) '
  50.                 .'AND (SELECT p.id FROM shop_product p  WHERE p.id = i.product_id AND p.category_id IN ('.implode(",", $cat['subcategories']).')))',
  51.                         array(
  52.                             'action' => $this->settings['action'],
  53.                             'period' => $this->settings['period'],
  54.                         )
  55.             )->fetchField();
  56.             if ($cat['count'] > 0) {
  57.                 $vars = array_merge($vars, array($cat['name']));
  58.                 $data = array_merge($data, array(array(
  59.                     $cat['count'])
  60.                 ));
  61.             }
  62.         }
  63.  
  64.         return (object) array(
  65.             'vars' => $vars,
  66.             'smps' => $smps,
  67.             'data' => $data,
  68.         );
  69.     }
  70. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×