1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\OrderBundle\Doctrine\ORM; |
15
|
|
|
|
16
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
17
|
|
|
use Sylius\Component\Order\Model\OrderInterface; |
18
|
|
|
use Sylius\Component\Order\Repository\OrderRepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class OrderRepository extends EntityRepository implements OrderRepositoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function countPlacedOrders() |
29
|
|
|
{ |
30
|
|
|
return (int) $this->createQueryBuilder('o') |
31
|
|
|
->select('COUNT(o.id)') |
32
|
|
|
->andWhere('o.state != :state') |
33
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
34
|
|
|
->getQuery() |
35
|
|
|
->getSingleScalarResult() |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function createCartQueryBuilder() |
43
|
|
|
{ |
44
|
|
|
return $this->createQueryBuilder('o') |
45
|
|
|
->addSelect('channel') |
46
|
|
|
->addSelect('customer') |
47
|
|
|
->innerJoin('o.channel', 'channel') |
48
|
|
|
->leftJoin('o.customer', 'customer') |
49
|
|
|
->andWhere('o.state = :state') |
50
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function findLatest($count) |
58
|
|
|
{ |
59
|
|
|
return $this->createQueryBuilder('o') |
60
|
|
|
->andWhere('o.state != :state') |
61
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
62
|
|
|
->addOrderBy('o.checkoutCompletedAt', 'DESC') |
63
|
|
|
->setMaxResults($count) |
64
|
|
|
->getQuery() |
65
|
|
|
->getResult() |
66
|
|
|
; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function findOneByNumber($number) |
73
|
|
|
{ |
74
|
|
|
return $this->createQueryBuilder('o') |
75
|
|
|
->andWhere('o.state != :state') |
76
|
|
|
->andWhere('o.number = :number') |
77
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
78
|
|
|
->setParameter('number', $number) |
79
|
|
|
->getQuery() |
80
|
|
|
->getOneOrNullResult() |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function findOneByTokenValue($tokenValue) |
88
|
|
|
{ |
89
|
|
|
return $this->createQueryBuilder('o') |
90
|
|
|
->andWhere('o.state != :state') |
91
|
|
|
->andWhere('o.tokenValue = :tokenValue') |
92
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
93
|
|
|
->setParameter('tokenValue', $tokenValue) |
94
|
|
|
->getQuery() |
95
|
|
|
->getOneOrNullResult() |
96
|
|
|
; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function findCartById($id) |
103
|
|
|
{ |
104
|
|
|
return $this->createQueryBuilder('o') |
105
|
|
|
->andWhere('o.id = :id') |
106
|
|
|
->andWhere('o.state = :state') |
107
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
108
|
|
|
->setParameter('id', $id) |
109
|
|
|
->getQuery() |
110
|
|
|
->getOneOrNullResult() |
111
|
|
|
; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function findCartsNotModifiedSince(\DateTime $terminalDate) |
118
|
|
|
{ |
119
|
|
|
return $this->createQueryBuilder('o') |
120
|
|
|
->andWhere('o.state = :state') |
121
|
|
|
->andWhere('o.updatedAt < :terminalDate') |
122
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
123
|
|
|
->setParameter('terminalDate', $terminalDate) |
124
|
|
|
->getQuery() |
125
|
|
|
->getResult() |
126
|
|
|
; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|