TopProducts ​
- Type
- Class
- Namespace
- craft\commerce\stats
- Inherits
- craft\commerce\stats\TopProducts » craft\commerce\base\Stat
- Implements
- craft\commerce\base\HasStoreInterface, craft\commerce\base\StatInterface
- Uses traits
- craft\commerce\base\StatTrait, craft\commerce\base\StoreTrait
- Since
- 3.0
Top Products Stat
Public Properties ​
| Property | Description |
|---|---|
| cache | boolean |
| cacheDuration | integer – How long to cache the data, in seconds. |
| dateRange | string, null |
| limit | integer – Number of products to show. |
| revenueOptions | string[] |
| storeId | integer, null – Store ID |
| type | string – Type either 'qty' or 'revenue'. |
| weekStartDay | integer |
limit ​
- Type
- integer
- Default value
5
Number of products to show.
revenueOptions ​
- Type
- string[]
- Default value
[]- Since
- 3.4
type ​
- Type
- string
- Default value
self::TYPE_QTY
Type either 'qty' or 'revenue'.
Protected Properties ​
| Property | Description |
|---|---|
| _handle | string |
_handle ​
- Type
- string
- Default value
'topProducts'
Public Methods ​
| Method | Description |
|---|---|
| __construct() | Stat constructor. |
| get() | |
| getChartQueryOptionsByInterval() | |
| getData() | |
| getDateRangeInterval() | |
| getDateRangeWording() | |
| getEndDate() | |
| getHandle() | |
| getOrderStatuses() | |
| getStartDate() | |
| getStore() | |
| prepareData() | |
| setEndDate() | |
| setOrderStatuses() | Set order statuses to limit stat query. Accepts array of OrderStatus models, handle strings or uid strings. |
| setStartDate() |
__construct() ​
Stat constructor.
Arguments ​
$dateRange(string, null)$type$startDate(DateTime, boolean, null)$endDate(DateTime, boolean, null)$revenueOptions$storeId
Throws ​
getData() ​
Returns ​
mixed
getHandle() ​
prepareData() ​
Arguments ​
$data(mixed)
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.
getAdjustmentsSelect() ​
- Since
- 3.4
Create select statement for a stat type custom based on the options chosen.
getGroupBy() ​
- Since
- 3.4
Return group by statement based on state type.
getOrderBy() ​
- Since
- 3.4
Return the order by clause for the data query.
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. |