12 use Psr\Log\LoggerInterface as Logger;
24 protected $_totals = [
'lifetime' => 0,
'base_lifetime' => 0,
'base_avgsale' => 0,
'num_orders' => 0];
73 $this->_storeCollectionFactory = $storeCollectionFactory;
124 $this->_orderStateCondition = $exclude ?
'NOT IN' :
'IN';
125 $this->_state = !is_array($state) ? [$state] : $state;
140 'lifetime' =>
new \
Zend_Db_Expr(
'SUM(base_grand_total)'),
141 'base_lifetime' =>
new \
Zend_Db_Expr(
'SUM(base_grand_total * base_to_global_rate)'),
142 'avgsale' =>
new \
Zend_Db_Expr(
'AVG(base_grand_total)'),
143 'base_avgsale' =>
new \
Zend_Db_Expr(
'AVG(base_grand_total * base_to_global_rate)'),
144 'num_orders' =>
new \
Zend_Db_Expr(
'COUNT(base_grand_total)')
149 if ($this->_customerId) {
153 if ($this->_state !==
null) {
155 switch ($this->_orderStateCondition) {
166 $this->_eventManager->dispatch(
'sales_sale_collection_query_before', [
'collection' => $this]);
177 public function load($printQuery =
false, $logQuery =
false)
192 $stores = $this->_storeCollectionFactory->create()->setWithoutDefaultFilter()->load()->toOptionHash();
194 foreach (
$data as $v) {
195 $storeObject = new \Magento\Framework\DataObject($v);
198 $storeObject->setStoreName(
201 $this->_storeManager->getStore(
$storeId)->getWebsiteId()
203 $v[
'avgsale'] * $v[
'num_orders']
205 $this->_items[
$storeId] = $storeObject;
206 foreach (array_keys($this->_totals) as $key) {
207 $this->_totals[$key] += $storeObject->getData($key);
211 if ($this->_totals[
'num_orders']) {
212 $this->_totals[
'avgsale'] = $this->_totals[
'base_lifetime'] / $this->_totals[
'num_orders'];
227 return new \Magento\Framework\DataObject($this->_totals);
load($printQuery=false, $logQuery=false)
addStoreFilter($storeIds)
printLogQuery($printQuery=false, $logQuery=false, $sql=null)
setCustomerIdFilter($customerId)
addFieldToFilter($attribute, $condition=null)
_init($model, $resourceModel)
__construct(EntityFactory $entityFactory, Logger $logger, FetchStrategyInterface $fetchStrategy, ManagerInterface $eventManager, \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeCollectionFactory, StoreManagerInterface $storeManager)
setOrderStateFilter($state, $exclude=false)