Test Failed
Push — master ( 48ddb2...dea459 )
by David
11:07
created

OrderManager::setCartOrdered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GGGGino\SkuskuCartBundle\Service;
4
5
use Doctrine\ORM\EntityManager;
6
use GGGGino\SkuskuCartBundle\Model\SkuskuCart;
7
use GGGGino\SkuskuCartBundle\Model\SkuskuCartProduct;
8
use GGGGino\SkuskuCartBundle\Model\SkuskuCustomerInterface;
9
use GGGGino\SkuskuCartBundle\Model\SkuskuLangInterface;
10
use GGGGino\SkuskuCartBundle\Model\SkuskuOrder;
11
use GGGGino\SkuskuCartBundle\Model\SkuskuProductInterface;
12
use Symfony\Component\Form\Form;
13
use Symfony\Component\Form\FormInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\RequestStack;
16
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
17
18
class OrderManager
19
{
20
    /**
21
     * @var EntityManager
22
     */
23
    private $em;
24
25
    /**
26
     * @var TokenStorage
27
     */
28
    private $tokenStorage;
29
30
    /**
31
     * @var bool
32
     */
33
    private $allowAnonymous;
34
35
    /**
36
     * CartExtension constructor.
37
     * @param EntityManager $em
38
     * @param TokenStorage $tokenStorage
39
     * @param bool $allowAnonymous
40
     */
41
    public function __construct(EntityManager $em, TokenStorage $tokenStorage, $allowAnonymous = true)
42
    {
43
        $this->em = $em;
44
        $this->tokenStorage = $tokenStorage;
45
        $this->allowAnonymous = $allowAnonymous;
46
    }
47
48
    /**
49
     * Create a temp Entity with some field initialized
50
     *
51
     * @return SkuskuOrder
52
     */
53
    private function createTempOrder()
54
    {
55
        $order = new SkuskuOrder();
56
        $order->setDateAdd(new \DateTime());
57
        $order->setDateUpd(new \DateTime());
58
59
        return $order;
60
    }
61
62
    /**
63
     * Build the order from a cart
64
     *
65
     * @param SkuskuCart $cart
66
     * @return SkuskuOrder
67
     */
68
    public function buildOrderFromCart(SkuskuCart $cart)
69
    {
70
        /** @var SkuskuOrder $order */
71
        $order = $this->createTempOrder();
72
73
        $order->setCart($cart);
74
        $order->setTotalPaid($cart->getTotalPrice());
75
        $order->setTotalPaidReal($cart->getTotalPrice());
76
        $order->setTotalProducts($cart->getTotalQuantity());
77
        $order->setCustomer($cart->getCustomer());
78
        $order->setCurrency($cart->getCurrency());
79
        $order->setLang($cart->getLang());
80
81
        $this->setCartOrdered($cart);
82
83
        return $order;
84
    }
85
86
    /**
87
     * @param SkuskuOrder $order
88
     */
89
    public function saveOrder(SkuskuOrder $order)
90
    {
91
        $this->em->persist($order);
92
        $this->em->flush();
93
    }
94
95
    public function setCartOrdered(SkuskuCart $cart)
96
    {
97
        $cart->setStatus(SkuskuCart::STATUS_ORDERED);
98
    }
99
}