1 | <?php |
||
39 | class CartService |
||
40 | { |
||
41 | /** |
||
42 | * @var Session |
||
43 | * @Inject("session") |
||
44 | */ |
||
45 | protected $session; |
||
46 | |||
47 | /** |
||
48 | * @var EntityManager |
||
49 | * @Inject("orm.em") |
||
50 | */ |
||
51 | protected $em; |
||
52 | |||
53 | /** |
||
54 | * @var ItemHolderInterface |
||
55 | */ |
||
56 | protected $cart; |
||
57 | |||
58 | /** |
||
59 | * @return ItemHolderInterface|Cart |
||
60 | */ |
||
61 | 91 | public function getCart() |
|
62 | { |
||
63 | 91 | if (is_null($this->cart)) { |
|
64 | 91 | $this->cart = $this->session->get('cart', new Cart()); |
|
65 | 91 | $this->loadItems(); |
|
66 | } |
||
67 | |||
68 | 91 | return $this->cart; |
|
69 | } |
||
70 | |||
71 | 91 | protected function loadItems() |
|
81 | |||
82 | 24 | public function addProduct($ProductClass, $quantity = 1) |
|
112 | |||
113 | /** |
||
114 | * @param int $cart_no |
||
115 | * @param int $quantity |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function addQuantity($cart_no, $quantity = 1) |
||
129 | |||
130 | /** |
||
131 | * @param integer $cart_no |
||
132 | * @return bool |
||
133 | */ |
||
134 | 1 | public function removeProduct($cart_no) |
|
139 | |||
140 | /** |
||
141 | * @param $cart_no |
||
142 | * @return CartItem|null |
||
143 | */ |
||
144 | 3 | public function getCartItem($cart_no) |
|
148 | |||
149 | 33 | public function save() |
|
153 | |||
154 | 3 | public function unlock() |
|
160 | |||
161 | 15 | public function lock() |
|
167 | |||
168 | /** |
||
169 | * @return bool |
||
170 | */ |
||
171 | 22 | public function isLocked() |
|
175 | |||
176 | /** |
||
177 | * @param string $pre_order_id |
||
178 | * @return \Eccube\Service\CartService |
||
179 | */ |
||
180 | 12 | public function setPreOrderId($pre_order_id) |
|
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | 12 | public function getPreOrderId() |
|
194 | |||
195 | /** |
||
196 | * @return \Eccube\Service\CartService |
||
197 | */ |
||
198 | 24 | public function clear() |
|
207 | } |
||
208 |