1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Doctrine\EventSubscriber; |
26
|
|
|
|
27
|
|
|
use Doctrine\Common\EventSubscriber; |
28
|
|
|
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; |
29
|
|
|
use Doctrine\ORM\Events; |
30
|
|
|
use Eccube\Entity\ProductClass; |
31
|
|
|
use Eccube\Entity\OrderItem; |
32
|
|
|
|
33
|
|
|
class TaxRuleEventSubscriber implements EventSubscriber |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var \Eccube\Service\TaxRuleService |
37
|
|
|
*/ |
38
|
|
|
private $taxRateService; |
39
|
|
|
|
40
|
1067 |
|
public function __construct(\Eccube\Service\TaxRuleService $taxRateService) |
|
|
|
|
41
|
|
|
{ |
42
|
1067 |
|
$this->taxRateService = $taxRateService; |
43
|
|
|
} |
44
|
|
|
|
45
|
1067 |
|
public function getSubscribedEvents() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
return array( |
48
|
1067 |
|
Events::prePersist, |
49
|
1067 |
|
Events::postLoad, |
50
|
1067 |
|
Events::postPersist, |
51
|
1067 |
|
Events::postUpdate, |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
541 |
View Code Duplication |
public function prePersist(LifecycleEventArgs $args) |
|
|
|
|
56
|
|
|
{ |
57
|
541 |
|
$entity = $args->getObject(); |
58
|
|
|
|
59
|
541 |
|
if ($entity instanceof ProductClass) { |
60
|
216 |
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
61
|
216 |
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
62
|
|
|
} |
63
|
541 |
|
if ($entity instanceof OrderItem) { |
64
|
116 |
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
771 |
View Code Duplication |
public function postLoad(LifecycleEventArgs $args) |
|
|
|
|
69
|
|
|
{ |
70
|
771 |
|
$entity = $args->getObject(); |
71
|
|
|
|
72
|
771 |
|
if ($entity instanceof ProductClass) { |
73
|
66 |
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
74
|
66 |
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
75
|
|
|
} |
76
|
771 |
|
if ($entity instanceof OrderItem) { |
77
|
|
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
541 |
View Code Duplication |
public function postPersist(LifecycleEventArgs $args) |
|
|
|
|
82
|
|
|
{ |
83
|
541 |
|
$entity = $args->getObject(); |
84
|
|
|
|
85
|
541 |
|
if ($entity instanceof ProductClass) { |
86
|
216 |
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
87
|
216 |
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
88
|
|
|
} |
89
|
541 |
|
if ($entity instanceof OrderItem) { |
90
|
116 |
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
318 |
View Code Duplication |
public function postUpdate(LifecycleEventArgs $args) |
|
|
|
|
95
|
|
|
{ |
96
|
318 |
|
$entity = $args->getObject(); |
97
|
|
|
|
98
|
318 |
|
if ($entity instanceof ProductClass) { |
99
|
42 |
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
100
|
42 |
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
101
|
|
|
} |
102
|
318 |
|
if ($entity instanceof OrderItem) { |
103
|
3 |
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|