Completed
Push — master ( f563c7...7369e3 )
by Kamil
20:40
created

OrderRepository::findOrdersUnpaidSince()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 1
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\Order\Model\OrderInterface;
16
use Sylius\Component\Order\Repository\OrderRepositoryInterface;
17
18
/**
19
 * @author Paweł Jędrzejewski <[email protected]>
20
 */
21
class OrderRepository extends EntityRepository implements OrderRepositoryInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function count()
27
    {
28
        return (int) $this->createQueryBuilder('o')
29
            ->select('COUNT(o.id)')
30
            ->andWhere('o.state != :state')
31
            ->setParameter('state', OrderInterface::STATE_CART)
32
            ->getQuery()
33
            ->getSingleScalarResult()
34
        ;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function findLatest($count)
41
    {
42
        return $this->createQueryBuilder('o')
43
            ->andWhere('o.state != :state')
44
            ->setParameter('state', OrderInterface::STATE_CART)
45
            ->addOrderBy('o.checkoutCompletedAt', 'DESC')
46
            ->setMaxResults($count)
47
            ->getQuery()
48
            ->getResult()
49
        ;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function findOneByNumber($number)
56
    {
57
        return $this->createQueryBuilder('o')
58
            ->andWhere('o.state != :state')
59
            ->andWhere('o.number = :number')
60
            ->setParameter('state', OrderInterface::STATE_CART)
61
            ->setParameter('number', $number)
62
            ->getQuery()
63
            ->getOneOrNullResult()
64
        ;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function findOneByTokenValue($tokenValue)
71
    {
72
        return $this->createQueryBuilder('o')
73
            ->andWhere('o.state != :state')
74
            ->andWhere('o.tokenValue = :tokenValue')
75
            ->setParameter('state', OrderInterface::STATE_CART)
76
            ->setParameter('tokenValue', $tokenValue)
77
            ->getQuery()
78
            ->getOneOrNullResult()
79
        ;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function findCartById($id)
86
    {
87
        return $this->createQueryBuilder('o')
88
            ->andWhere('o.id = :id')
89
            ->andWhere('o.state = :state')
90
            ->setParameter('state', OrderInterface::STATE_CART)
91
            ->setParameter('id', $id)
92
            ->getQuery()
93
            ->getOneOrNullResult()
94
        ;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function findCartsNotModifiedSince(\DateTime $terminalDate)
101
    {
102
        return $this->createQueryBuilder('o')
103
            ->andWhere('o.state = :state')
104
            ->andWhere('o.updatedAt < :terminalDate')
105
            ->setParameter('state', OrderInterface::STATE_CART)
106
            ->setParameter('terminalDate', $terminalDate)
107
            ->getQuery()
108
            ->getResult()
109
        ;
110
    }
111
}
112