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\ServiceProvider; |
26
|
|
|
|
27
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
28
|
|
|
use Eccube\Entity\ItemHolderInterface; |
29
|
|
|
use Eccube\Entity\BaseInfo; |
30
|
|
|
use Eccube\EventListener\ForwardOnlyListener; |
31
|
|
|
use Eccube\EventListener\TransactionListener; |
32
|
|
|
use Eccube\Repository\BaseInfoRepository; |
33
|
|
|
use Eccube\Repository\DeliveryRepository; |
34
|
|
|
use Eccube\Service\PurchaseFlow\Processor\AdminOrderRegisterPurchaseProcessor; |
35
|
|
|
use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator; |
36
|
|
|
use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; |
37
|
|
|
use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; |
38
|
|
|
use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; |
39
|
|
|
use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; |
40
|
|
|
use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor; |
41
|
|
|
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; |
42
|
|
|
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator; |
43
|
|
|
use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; |
44
|
|
|
use Eccube\Service\PurchaseFlow\Processor\StockValidator; |
45
|
|
|
use Eccube\Service\PurchaseFlow\Processor\UpdateDatePurchaseProcessor; |
46
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
47
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlow; |
48
|
|
|
use Eccube\Service\TaxRuleService; |
49
|
|
|
use Pimple\Container; |
50
|
|
|
use Pimple\ServiceProviderInterface; |
51
|
|
|
use Silex\Api\EventListenerProviderInterface; |
52
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
53
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
54
|
|
|
|
55
|
|
|
class EccubeServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* Registers services on the given app. |
59
|
|
|
* |
60
|
|
|
* This method should only be used to configure services and parameters. |
61
|
|
|
* It should not get services. |
62
|
|
|
* |
63
|
|
|
* @param BaseApplication $app An Application instance |
64
|
|
|
*/ |
65
|
1092 |
|
public function register(Container $app) |
66
|
|
|
{ |
67
|
|
|
$app[BaseInfo::class] = function () use ($app) { |
68
|
1092 |
|
return $app[BaseInfoRepository::class]->get(); |
69
|
|
|
}; |
70
|
|
|
|
71
|
|
|
$app['eccube.calculate.context'] = function () use ($app) { |
72
|
|
|
return new \Eccube\Service\Calculator\CalculateContext(); |
73
|
|
|
}; |
74
|
|
|
|
75
|
|
|
$app['eccube.calculate.strategies'] = function () use ($app) { |
76
|
|
|
$Collection = new \Eccube\Service\Calculator\CalculateStrategyCollection(); |
77
|
|
|
$Collection->setApplication($app); |
|
|
|
|
78
|
|
|
//$Collection->setOrder($Order); |
79
|
|
|
// デフォルトのストラテジーをセットしておく |
80
|
|
|
$Collection->add($app['eccube.calculate.strategy.shipping']); |
81
|
|
|
$Collection->add($app['eccube.calculate.strategy.charge']); |
82
|
|
|
$Collection->add($app['eccube.calculate.strategy.tax']); |
83
|
|
|
$Collection->add($app['eccube.calculate.strategy.calculate_delivery_fee']); |
84
|
|
|
$Collection->add($app['eccube.calculate.strategy.calculate_charge']); |
85
|
|
|
$Collection->add($app['eccube.calculate.strategy.calculate_total']); |
86
|
|
|
return $Collection; |
|
|
|
|
87
|
|
|
}; |
88
|
|
|
$app['eccube.calculate.strategy.shipping'] = function () use ($app) { |
89
|
|
|
$Strategy = new \Eccube\Service\Calculator\Strategy\ShippingStrategy(); |
90
|
|
|
$Strategy->setApplication($app); |
|
|
|
|
91
|
|
|
return $Strategy; |
|
|
|
|
92
|
|
|
}; |
93
|
|
|
$app['eccube.calculate.strategy.charge'] = function () use ($app) { |
94
|
|
|
$Strategy = new \Eccube\Service\Calculator\Strategy\ChargeStrategy(); |
95
|
|
|
$Strategy->setApplication($app); |
|
|
|
|
96
|
|
|
return $Strategy; |
|
|
|
|
97
|
|
|
}; |
98
|
|
|
|
99
|
|
|
$app['eccube.calculate.strategy.tax'] = function () use ($app) { |
100
|
|
|
$Strategy = new \Eccube\Service\Calculator\Strategy\TaxStrategy(); |
101
|
|
|
$Strategy->setApplication($app); |
|
|
|
|
102
|
|
|
return $Strategy; |
|
|
|
|
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
$app['eccube.calculate.strategy.calculate_delivery_fee'] = function () use ($app) { |
106
|
|
|
$Strategy = new \Eccube\Service\Calculator\Strategy\CalculateDeliveryFeeStrategy(); |
107
|
|
|
$Strategy->setApplication($app); |
|
|
|
|
108
|
|
|
return $Strategy; |
|
|
|
|
109
|
|
|
}; |
110
|
|
|
$app['eccube.calculate.strategy.calculate_charge'] = function () use ($app) { |
111
|
|
|
$Strategy = new \Eccube\Service\Calculator\Strategy\CalculateChargeStrategy(); |
112
|
|
|
$Strategy->setApplication($app); |
|
|
|
|
113
|
|
|
return $Strategy; |
|
|
|
|
114
|
|
|
}; |
115
|
|
|
$app['eccube.calculate.strategy.calculate_total'] = function () use ($app) { |
116
|
|
|
$Strategy = new \Eccube\Service\Calculator\Strategy\CalculateTotalStrategy(); |
117
|
|
|
$Strategy->setApplication($app); |
|
|
|
|
118
|
|
|
return $Strategy; |
|
|
|
|
119
|
|
|
}; |
120
|
|
|
|
121
|
|
|
$app['payment.method'] = $app->protect(function ($clazz, $form) use ($app) { |
122
|
1 |
|
$PaymentMethod = new $clazz; |
|
|
|
|
123
|
1 |
|
$PaymentMethod->setApplication($app); |
124
|
1 |
|
$PaymentMethod->setFormType($form); |
125
|
1 |
|
return $PaymentMethod; |
|
|
|
|
126
|
1092 |
|
}); |
127
|
|
|
|
128
|
|
|
$app['payment.method.request'] = $app->protect(function ($clazz, $form, $request) use ($app) { |
129
|
2 |
|
$PaymentMethod = new $clazz; |
|
|
|
|
130
|
2 |
|
$PaymentMethod->setApplication($app); |
131
|
2 |
|
$PaymentMethod->setFormType($form); |
132
|
2 |
|
$PaymentMethod->setRequest($request); |
133
|
2 |
|
return $PaymentMethod; |
|
|
|
|
134
|
1092 |
|
}); |
135
|
|
|
|
136
|
|
|
$app['eccube.service.calculate'] = $app->protect(function ($Order, $Customer) use ($app) { |
137
|
|
|
$Service = new \Eccube\Service\CalculateService($Order, $Customer); |
138
|
|
|
$Context = $app['eccube.calculate.context']; |
139
|
|
|
$app['eccube.calculate.strategies']->setOrder($Order); |
140
|
|
|
$Context->setCalculateStrategies($app['eccube.calculate.strategies']); |
141
|
|
|
$Context->setOrder($Order); |
142
|
|
|
$Service->setContext($Context); |
143
|
|
|
|
144
|
|
|
return $Service; |
145
|
1092 |
|
}); |
146
|
|
|
|
147
|
|
|
$app['eccube.service.payment'] = $app->protect(function ($clazz) use ($app) { |
148
|
3 |
|
$Service = new $clazz($app['request_stack']); |
149
|
|
|
|
150
|
3 |
|
return $Service; |
151
|
1092 |
|
}); |
152
|
|
|
|
153
|
|
|
$app['paginator'] = $app->protect(function () { |
154
|
29 |
|
$paginator = new \Knp\Component\Pager\Paginator(); |
155
|
29 |
|
$paginator->subscribe(new \Eccube\EventListener\PaginatorListener()); |
156
|
|
|
|
157
|
29 |
|
return $paginator; |
158
|
1092 |
|
}); |
159
|
|
|
|
160
|
|
|
$app['request_scope'] = function () { |
161
|
22 |
|
return new ParameterBag(); |
162
|
|
|
}; |
163
|
|
|
// TODO 使用するか検討 |
164
|
|
|
$app['eccube.twig.node.hello'] = $app->protect(function ($node, $compiler) { |
165
|
|
|
$compiler |
166
|
|
|
->addDebugInfo($node) |
167
|
|
|
->write("echo 'Helloooooo ' . ") |
168
|
|
|
->subcompile($node->getNode('expr')) |
169
|
|
|
->raw(" . '!';\n") |
170
|
|
|
; |
171
|
|
|
|
172
|
1092 |
|
}); |
173
|
|
|
// TODO 使用するか検討 |
174
|
|
|
$app['eccube.twig.node.jiro'] = $app->protect(function ($node, $compiler) { |
175
|
|
|
$compiler |
176
|
|
|
->addDebugInfo($node) |
177
|
|
|
->write("echo 'jirooooooo ' . ") |
178
|
|
|
->subcompile($node->getNode('expr')) |
179
|
|
|
->raw(" . '!';\n") |
180
|
|
|
; |
181
|
|
|
|
182
|
1092 |
|
}); |
183
|
|
|
|
184
|
|
|
// TODO 使用するか検討 |
185
|
|
|
$app['eccube.twig.generic_node_names'] = function () use ($app) { |
186
|
|
|
return [ |
|
|
|
|
187
|
113 |
|
'hello', |
188
|
|
|
'jiro', |
189
|
|
|
'bbb' |
190
|
|
|
]; |
191
|
|
|
}; |
192
|
|
|
|
193
|
|
|
// TODO 使用するか検討 |
194
|
|
|
$app['twig_parsers'] = function () use ($app) { |
195
|
113 |
|
$GenericTokenParsers = []; |
196
|
113 |
|
foreach ($app['eccube.twig.generic_node_names'] as $tagName) { |
197
|
113 |
|
$GenericTokenParsers[] = new \Eccube\Twig\Extension\GenericTokenParser($app, $tagName); |
198
|
|
|
} |
199
|
113 |
|
return $GenericTokenParsers; |
|
|
|
|
200
|
|
|
}; |
201
|
|
|
|
202
|
|
|
$app['eccube.twig.block.templates'] = function () { |
203
|
|
|
$templates = new ArrayCollection(); |
204
|
|
|
$templates[] = 'render_block.twig'; |
205
|
|
|
|
206
|
|
|
return $templates; |
207
|
|
|
}; |
208
|
|
|
|
209
|
1092 |
|
$app['eccube.entity.event.dispatcher']->addEventListener(new \Acme\Entity\SoldOutEventListener()); |
210
|
|
|
$app['eccube.queries'] = function () { |
211
|
1092 |
|
return new \Eccube\Doctrine\Query\Queries(); |
212
|
|
|
}; |
213
|
|
|
// TODO QueryCustomizerの追加方法は要検討 |
214
|
1092 |
|
$app['eccube.queries']->addCustomizer(new \Acme\Entity\AdminProductListCustomizer()); |
215
|
|
|
|
216
|
|
|
$app['eccube.purchase.context'] = $app->protect(function (ItemHolderInterface $origin = null) { |
217
|
17 |
|
return new PurchaseContext($origin); |
218
|
1092 |
|
}); |
219
|
|
|
|
220
|
|
|
$app['eccube.purchase.flow.cart.item_processors'] = function ($app) { |
221
|
24 |
|
$processors = new ArrayCollection(); |
222
|
24 |
|
$processors->add(new DisplayStatusValidator()); |
223
|
24 |
|
$processors->add(new SaleLimitValidator()); |
224
|
24 |
|
$processors->add(new DeliverySettingValidator($app['eccube.repository.delivery'])); |
225
|
|
|
|
226
|
24 |
|
return $processors; |
227
|
|
|
}; |
228
|
|
|
|
229
|
|
|
$app['eccube.purchase.flow.cart.holder_processors'] = function ($app) { |
230
|
24 |
|
$processors = new ArrayCollection(); |
231
|
24 |
|
$processors->add(new PaymentProcessor($app[DeliveryRepository::class])); |
232
|
24 |
|
$processors->add(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); |
233
|
24 |
|
$processors->add(new DeliveryFeeFreeProcessor($app[BaseInfo::class])); |
234
|
24 |
|
$processors->add(new PaymentTotalNegativeValidator()); |
235
|
|
|
|
236
|
24 |
|
return $processors; |
237
|
|
|
}; |
238
|
|
|
|
239
|
|
|
// example |
240
|
|
|
$app->extend('eccube.purchase.flow.cart.item_processors', function ($processors, $app) { |
|
|
|
|
241
|
|
|
|
242
|
24 |
|
$processors->add(new StockValidator()); |
243
|
|
|
|
244
|
24 |
|
return $processors; |
245
|
1092 |
|
}); |
246
|
|
|
|
247
|
|
|
$app['eccube.purchase.flow.cart'] = function ($app) { |
248
|
24 |
|
$flow = new PurchaseFlow(); |
249
|
24 |
|
$flow->setItemProcessors($app['eccube.purchase.flow.cart.item_processors']); |
250
|
24 |
|
$flow->setItemHolderProcessors($app['eccube.purchase.flow.cart.holder_processors']); |
251
|
|
|
|
252
|
24 |
|
return $flow; |
253
|
|
|
}; |
254
|
|
|
|
255
|
|
View Code Duplication |
$app['eccube.purchase.flow.shopping'] = function () use ($app) { |
256
|
22 |
|
$flow = new PurchaseFlow(); |
257
|
22 |
|
$flow->addItemProcessor(new StockValidator()); |
258
|
22 |
|
$flow->addItemProcessor(new DisplayStatusValidator()); |
259
|
22 |
|
$flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); |
260
|
22 |
|
$flow->addItemHolderProcessor(new DeliveryFeeProcessor($app['orm.em'])); |
261
|
22 |
|
$flow->addItemHolderProcessor(new PaymentTotalNegativeValidator()); |
262
|
22 |
|
return $flow; |
|
|
|
|
263
|
|
|
}; |
264
|
|
|
|
265
|
8 |
View Code Duplication |
$app['eccube.purchase.flow.order'] = function () use ($app) { |
266
|
8 |
|
$flow = new PurchaseFlow(); |
267
|
8 |
|
$flow->addItemProcessor(new StockValidator()); |
268
|
8 |
|
$flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); |
269
|
8 |
|
$flow->addPurchaseProcessor(new UpdateDatePurchaseProcessor($app['config'])); |
270
|
8 |
|
$flow->addPurchaseProcessor(new AdminOrderRegisterPurchaseProcessor($app)); |
|
|
|
|
271
|
8 |
|
return $flow; |
|
|
|
|
272
|
|
|
}; |
273
|
|
|
} |
274
|
|
|
|
275
|
1092 |
|
public function subscribe(Container $app, EventDispatcherInterface $dispatcher) |
|
|
|
|
276
|
|
|
{ |
277
|
|
|
// Add event subscriber to TaxRuleEvent |
278
|
1092 |
|
$app['orm.em']->getEventManager()->addEventSubscriber(new \Eccube\Doctrine\EventSubscriber\TaxRuleEventSubscriber($app[TaxRuleService::class])); |
279
|
|
|
|
280
|
1092 |
|
$dispatcher->addSubscriber(new ForwardOnlyListener($app)); |
|
|
|
|
281
|
1092 |
|
$dispatcher->addSubscriber(new TransactionListener($app)); |
|
|
|
|
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|