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
|
|
|
namespace Sylius\Bundle\OrderBundle\Doctrine\ORM; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
15
|
|
|
use Sylius\Component\Core\OrderCheckoutStates; |
16
|
|
|
use Sylius\Component\Core\OrderPaymentStates; |
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 count() |
29
|
|
|
{ |
30
|
|
|
$count = $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
|
|
|
return (int) $count; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function findLatest($count) |
45
|
|
|
{ |
46
|
|
|
return $this->createQueryBuilder('o') |
47
|
|
|
->andWhere('o.state != :state') |
48
|
|
|
->setMaxResults($count) |
49
|
|
|
->orderBy('o.checkoutCompletedAt', 'desc') |
50
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
51
|
|
|
->getQuery() |
52
|
|
|
->getResult() |
53
|
|
|
; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function findOneByNumber($number) |
60
|
|
|
{ |
61
|
|
|
return $this->createQueryBuilder('o') |
62
|
|
|
->andWhere('o.state != :state') |
63
|
|
|
->andWhere('o.number = :number') |
64
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
65
|
|
|
->setParameter('number', $number) |
66
|
|
|
->getQuery() |
67
|
|
|
->getOneOrNullResult() |
68
|
|
|
; |
69
|
|
|
} |
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function findCartById($id) |
74
|
|
|
{ |
75
|
|
|
return $this->createQueryBuilder('o') |
76
|
|
|
->where('o.id = :id') |
77
|
|
|
->andWhere('o.state = :state') |
78
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
79
|
|
|
->setParameter('id', $id) |
80
|
|
|
->getQuery() |
81
|
|
|
->getOneOrNullResult() |
82
|
|
|
; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function findCartsNotModifiedSince(\DateTime $terminalDate) |
89
|
|
|
{ |
90
|
|
|
return $this->createQueryBuilder('o') |
91
|
|
|
->where('o.state = :state') |
92
|
|
|
->andWhere('o.updatedAt < :terminalDate') |
93
|
|
|
->setParameter('state', OrderInterface::STATE_CART) |
94
|
|
|
->setParameter('terminalDate', $terminalDate) |
95
|
|
|
->getQuery() |
96
|
|
|
->getResult() |
97
|
|
|
; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function findOrdersUnpaidSince(\DateTime $terminalDate) |
104
|
|
|
{ |
105
|
|
|
return $this->createQueryBuilder('o') |
106
|
|
|
->where('o.checkoutState = :checkoutState') |
107
|
|
|
->andWhere('o.paymentState != :paymentState') |
108
|
|
|
->andWhere('o.state = :orderState') |
109
|
|
|
->andWhere('o.checkoutCompletedAt < :terminalDate') |
110
|
|
|
->setParameter('checkoutState', OrderCheckoutStates::STATE_COMPLETED) |
111
|
|
|
->setParameter('paymentState', OrderPaymentStates::STATE_PAID) |
112
|
|
|
->setParameter('orderState', OrderInterface::STATE_NEW) |
113
|
|
|
->setParameter('terminalDate', $terminalDate) |
114
|
|
|
->getQuery() |
115
|
|
|
->getResult() |
116
|
|
|
; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|