TopProducts
- Type
- Class
- Namespace
- craft\commerce\stats
- Inherits
- craft\commerce\stats\TopProducts » craft\commerce\base\Stat
- Implements
- craft\commerce\base\StatInterface
- Uses traits
- craft\commerce\base\StatTrait
- Since
- 3.0
Top Products Stat
View source (opens new window)
# Public Properties
| Property | Description |
|---|---|
| cache | boolean (opens new window) |
| cacheDuration | integer (opens new window) – How long to cache the data, in seconds. |
| dateRange | string (opens new window) |
| limit | integer (opens new window) – Number of products to show. |
| revenueOptions | string (opens new window)[] |
| type | string (opens new window) – Type either 'qty' or 'revenue'. |
| weekStartDay | integer (opens new window) |
# limit
- Type
- integer (opens new window)
- Default value
5
Number of products to show.
View source (opens new window)
# revenueOptions
- Type
- string (opens new window)[]
- Default value
[]- Since
- 3.4
View source (opens new window)
# type
- Type
- string (opens new window)
- Default value
self::TYPE_QTY
Type either 'qty' or 'revenue'.
View source (opens new window)
# Protected Properties
| Property | Description |
|---|---|
| _handle | string (opens new window) |
# _handle
- Type
- string (opens new window)
- Default value
'topProducts'
View source (opens new window)
# Public Methods
| Method | Description |
|---|---|
| __construct() | Stat constructor. |
| get() | |
| getChartQueryOptionsByInterval() | |
| getData() | |
| getDateRangeInterval() | |
| getDateRangeWording() | |
| getEndDate() | |
| getHandle() | |
| getStartDate() | |
| prepareData() | |
| setEndDate() | |
| setStartDate() |
# __construct()
Stat constructor.
View source (opens new window)
Arguments
$dateRange(string (opens new window), null (opens new window))$type$startDate(DateTime (opens new window), null (opens new window))$endDate(DateTime (opens new window), null (opens new window))$revenueOptions
Throws
# getData()
View source (opens new window)
Returns
array (opens new window), null (opens new window), false (opens new window)
# getHandle()
View source (opens new window)
Returns
# prepareData()
View source (opens new window)
Arguments
$data
Returns
mixed
# Protected Methods
| Method | Description |
|---|---|
| _createChartQuery() | |
| _createStatQuery() | Generate base stat query |
| createAdjustmentsSubQuery() | Create the adjustments sub query for use with revenue calculation. |
| getAdjustmentsSelect() | Create select statement for a stat type custom based on the options chosen. |
| getGroupBy() | Return group by statement based on state type. |
| getOrderBy() | Return the order by clause for the data query. |
# createAdjustmentsSubQuery()
- Since
- 3.4
Create the adjustments sub query for use with revenue calculation.
View source (opens new window)
Returns
craft\db\Query (opens new window)
# getAdjustmentsSelect()
- Since
- 3.4
Create select statement for a stat type custom based on the options chosen.
View source (opens new window)
Returns
yii\db\Expression (opens new window)
# getGroupBy()
- Since
- 3.4
Return group by statement based on state type.
View source (opens new window)
Returns
# getOrderBy()
- Since
- 3.4
Return the order by clause for the data query.
View source (opens new window)
Returns
yii\db\Expression (opens new window)
# Constants
| Constant | Description |
|---|---|
REVENUE_OPTION_DISCOUNT | |
REVENUE_OPTION_SHIPPING | |
REVENUE_OPTION_TAX | |
REVENUE_OPTION_TAX_INCLUDED | |
TYPE_QTY | Stat returned based on quantity. |
TYPE_REVENUE | Stat returned based on revenue. |