1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Twig\Extension; |
15
|
|
|
|
16
|
|
|
use Eccube\Entity\Cart; |
17
|
|
|
use Eccube\Service\CartService; |
18
|
|
|
use Twig\Extension\AbstractExtension; |
19
|
|
|
|
20
|
|
|
class CartServiceExtension extends AbstractExtension |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var CartService |
24
|
|
|
*/ |
25
|
|
|
protected $cartService; |
26
|
|
|
|
27
|
|
|
public function __construct(CartService $cartService) |
28
|
|
|
{ |
29
|
|
|
$this->cartService = $cartService; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getFunctions() |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
new \Twig_Function('get_cart', [$this, 'get_cart'], ['is_safe' => ['all']]), |
|
|
|
|
36
|
|
|
new \Twig_Function('get_all_carts', [$this, 'get_all_carts'], ['is_safe' => ['all']]), |
|
|
|
|
37
|
|
|
new \Twig_Function('get_carts_total_price', [$this, 'get_carts_total_price'], ['is_safe' => ['all']]), |
|
|
|
|
38
|
|
|
new \Twig_Function('get_carts_total_quantity', [$this, 'get_carts_total_quantity'], ['is_safe' => ['all']]), |
|
|
|
|
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function get_cart() |
43
|
|
|
{ |
44
|
|
|
return $this->cartService->getCart(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function get_all_carts() |
48
|
|
|
{ |
49
|
|
|
return $this->cartService->getCarts(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function get_carts_total_price() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$Carts = $this->cartService->getCarts(); |
55
|
|
|
$totalPrice = array_reduce($Carts, function ($total, Cart $Cart) { |
56
|
|
|
$total += $Cart->getTotalPrice(); |
57
|
|
|
|
58
|
|
|
return $total; |
59
|
|
|
}, 0); |
60
|
|
|
|
61
|
|
|
return $totalPrice; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function get_carts_total_quantity() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$Carts = $this->cartService->getCarts(); |
67
|
|
|
$totalQuantity = array_reduce($Carts, function ($total, Cart $Cart) { |
68
|
|
|
$total += $Cart->getTotalQuantity(); |
69
|
|
|
|
70
|
|
|
return $total; |
71
|
|
|
}, 0); |
72
|
|
|
|
73
|
|
|
return $totalQuantity; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.