uawdijnntqw1x1x1
IP : 216.73.216.127
Hostname : toronto-dev2
Kernel : Linux toronto-dev2 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
srv
/
users
/
craft4
/
apps
/
craft4-newsite-space
/
vendor
/
craftcms
/
commerce
/
src
/
stats
/
TopProductTypes.php
/
/
<?php /** * @link https://craftcms.com/ * @copyright Copyright (c) Pixel & Tonic, Inc. * @license https://craftcms.github.io/license/ */ namespace craft\commerce\stats; use Craft; use craft\commerce\base\Stat; use craft\commerce\db\Table; use craft\commerce\Plugin; use craft\db\Table as CraftTable; use yii\db\Expression; /** * Top Product Types Stat * * @author Pixel & Tonic, Inc. <support@pixelandtonic.com> * @since 3.0 */ class TopProductTypes extends Stat { /** * @inheritdoc */ protected string $_handle = 'topProductTypes'; /** * @var string Type either 'qty' or 'revenue'. */ public string $type = 'qty'; /** * @var int Number of customers to show. */ public int $limit = 5; /** * @inheritDoc */ public function __construct(string $dateRange = null, string $type = null, $startDate = null, $endDate = null) { $this->type = $type ?? $this->type; parent::__construct($dateRange, $startDate, $endDate); } /** * @inheritDoc */ public function getData(): array { $primarySite = Craft::$app->getSites()->getPrimarySite(); $selectTotalQty = new Expression('SUM([[li.qty]]) as qty'); $orderByQty = new Expression('SUM([[li.qty]]) DESC'); $selectTotalRevenue = new Expression('SUM([[li.total]]) as revenue'); $orderByRevenue = new Expression('SUM([[li.total]]) DESC'); $editableProductTypeIds = Plugin::getInstance()->getProductTypes()->getEditableProductTypeIds(); $results = $this->_createStatQuery() ->select([ '[[pt.id]] as id', '[[pt.name]]', $selectTotalQty, $selectTotalRevenue, ]) ->leftJoin(Table::LINEITEMS . ' li', '[[li.orderId]] = [[orders.id]]') ->leftJoin(Table::PURCHASABLES . ' p', '[[p.id]] = [[li.purchasableId]]') ->leftJoin(Table::VARIANTS . ' v', '[[v.id]] = [[p.id]]') ->leftJoin(Table::PRODUCTS . ' pr', '[[pr.id]] = [[v.productId]]') ->leftJoin(Table::PRODUCTTYPES . ' pt', '[[pt.id]] = [[pr.typeId]]') ->leftJoin(CraftTable::CONTENT . ' content', [ 'and', '[[content.elementId]] = [[v.productId]]', ['content.siteId' => $primarySite->id], ]) ->andWhere(['not', ['pt.name' => null]]) ->andWhere(['pt.id' => $editableProductTypeIds]) ->groupBy('[[pt.id]]') ->orderBy($this->type == 'revenue' ? $orderByRevenue : $orderByQty) ->limit($this->limit); return $results->all(); } /** * @inheritDoc */ public function getHandle(): string { return $this->_handle . $this->type; } /** * @inheritDoc */ public function prepareData($data): mixed { if (!empty($data)) { foreach ($data as &$row) { $row['productType'] = ($row['id']) ? Plugin::getInstance()->getProductTypes()->getProductTypeById((int)$row['id']) : null; } } return $data; } }
/srv/users/craft4/apps/craft4-newsite-space/vendor/craftcms/commerce/src/stats/TopProductTypes.php