1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Odiseo\SyliusReportPlugin\DataFetcher; |
4
|
|
|
|
5
|
|
|
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\NumberOfOrdersType; |
6
|
|
|
use Sylius\Component\Core\OrderPaymentStates; |
7
|
|
|
use Sylius\Component\Order\Model\Order; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Łukasz Chruściel <[email protected]> |
11
|
|
|
* @author Diego D'amico <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class NumberOfOrdersDataFetcher extends TimePeriodDataFetcher |
14
|
|
|
{ |
15
|
|
|
protected function setupQueryFilter(array $configuration = []): void |
16
|
|
|
{ |
17
|
|
|
$qb = $this->queryFilter->getQueryBuilder(); |
18
|
|
|
|
19
|
|
|
$qb |
20
|
|
|
->select('DATE(payment.updatedAt) as date', 'COUNT(o.id) as NumberOfOrders') |
21
|
|
|
->from(Order::class, 'o') |
22
|
|
|
; |
23
|
|
|
$this->queryFilter->addLeftJoin('o.items', 'oi'); |
24
|
|
|
$this->queryFilter->addLeftJoin('oi.variant', 'v'); |
25
|
|
|
$this->queryFilter->addLeftJoin('v.product', 'p'); |
26
|
|
|
$this->queryFilter->addLeftJoin('p.productTaxons', 'pt'); |
27
|
|
|
$this->queryFilter->addLeftJoin('o.customer', 'c'); |
28
|
|
|
$this->queryFilter->addLeftJoin('c.user', 'user'); |
29
|
|
|
$this->queryFilter->addLeftJoin('o.payments', 'payment'); |
30
|
|
|
|
31
|
|
|
$qb |
32
|
|
|
->where($qb->expr()->eq('o.payment_state', OrderPaymentStates::STATE_PAID)) |
33
|
|
|
; |
34
|
|
|
|
35
|
|
|
$this->queryFilter->addTimePeriod($configuration); |
36
|
|
|
$this->queryFilter->addChannel($configuration, 'o.channel'); |
37
|
|
|
$this->queryFilter->addUserGender($configuration); |
38
|
|
|
$this->queryFilter->addUserCountry($configuration, 'shipping'); |
39
|
|
|
$this->queryFilter->addUserCity($configuration, 'shipping'); |
40
|
|
|
$this->queryFilter->addUserProvince($configuration, 'shipping'); |
41
|
|
|
$this->queryFilter->addUserPostcode($configuration, 'shipping'); |
42
|
|
|
$this->queryFilter->addUserCountry($configuration, 'billing'); |
43
|
|
|
$this->queryFilter->addUserCity($configuration, 'billing'); |
44
|
|
|
$this->queryFilter->addUserProvince($configuration, 'billing'); |
45
|
|
|
$this->queryFilter->addUserPostcode($configuration, 'billing'); |
46
|
|
|
$this->queryFilter->addProduct($configuration); |
47
|
|
|
$this->queryFilter->addProductBrand($configuration); |
48
|
|
|
$this->queryFilter->addProductCategory($configuration); |
49
|
|
|
$this->queryFilter->addOrderNumbers($configuration); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getType(): string |
56
|
|
|
{ |
57
|
|
|
return NumberOfOrdersType::class; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|