This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | namespace Eccube\Controller\Admin\Order; |
||
25 | |||
26 | use Doctrine\Common\Collections\ArrayCollection; |
||
27 | use Eccube\Application; |
||
28 | use Eccube\Common\Constant; |
||
29 | use Eccube\Controller\AbstractController; |
||
30 | use Eccube\Entity\Master\DeviceType; |
||
31 | use Eccube\Entity\ShipmentItem; |
||
32 | use Eccube\Event\EccubeEvents; |
||
33 | use Eccube\Event\EventArgs; |
||
34 | use Symfony\Component\Form\FormError; |
||
35 | use Symfony\Component\HttpFoundation\Request; |
||
36 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
37 | |||
38 | class EditController extends AbstractController |
||
39 | { |
||
40 | 19 | public function index(Application $app, Request $request, $id = null) |
|
41 | { |
||
42 | /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
||
43 | 19 | $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
44 | 19 | $softDeleteFilter->setExcludes(array( |
|
45 | 19 | 'Eccube\Entity\ProductClass', |
|
46 | 'Eccube\Entity\Product', |
||
47 | )); |
||
48 | |||
49 | 19 | $TargetOrder = null; |
|
50 | 19 | $OriginOrder = null; |
|
51 | |||
52 | 19 | if (is_null($id)) { |
|
53 | // 空のエンティティを作成. |
||
54 | 7 | $TargetOrder = $this->newOrder($app); |
|
55 | } else { |
||
56 | 12 | $TargetOrder = $app['eccube.repository.order']->find($id); |
|
57 | 12 | if (is_null($TargetOrder)) { |
|
58 | throw new NotFoundHttpException(); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | // 編集前の受注情報を保持 |
||
63 | 19 | $OriginOrder = clone $TargetOrder; |
|
64 | 19 | $OriginalOrderDetails = new ArrayCollection(); |
|
65 | // 編集前のお届け先情報を保持 |
||
66 | 19 | $OriginalShippings = new ArrayCollection(); |
|
67 | // 編集前のお届け先のアイテム情報を保持 |
||
68 | 19 | $OriginalShipmentItems = new ArrayCollection(); |
|
69 | |||
70 | 19 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
71 | 19 | $OriginalOrderDetails->add($OrderDetail); |
|
72 | } |
||
73 | |||
74 | // 編集前の情報を保持 |
||
75 | 19 | foreach ($TargetOrder->getShippings() as $tmpOriginalShippings) { |
|
76 | 19 | foreach ($tmpOriginalShippings->getShipmentItems() as $tmpOriginalShipmentItem) { |
|
77 | // アイテム情報 |
||
78 | 19 | $OriginalShipmentItems->add($tmpOriginalShipmentItem); |
|
79 | } |
||
80 | // お届け先情報 |
||
81 | 19 | $OriginalShippings->add($tmpOriginalShippings); |
|
82 | } |
||
83 | |||
84 | 19 | $builder = $app['form.factory'] |
|
85 | 19 | ->createBuilder('order', $TargetOrder); |
|
86 | |||
87 | 19 | $event = new EventArgs( |
|
88 | array( |
||
89 | 19 | 'builder' => $builder, |
|
90 | 19 | 'OriginOrder' => $OriginOrder, |
|
91 | 19 | 'TargetOrder' => $TargetOrder, |
|
92 | 19 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
93 | ), |
||
94 | $request |
||
95 | ); |
||
96 | 19 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event); |
|
97 | |||
98 | 19 | $form = $builder->getForm(); |
|
99 | |||
100 | 19 | if ('POST' === $request->getMethod()) { |
|
101 | 13 | $form->handleRequest($request); |
|
102 | |||
103 | 13 | $event = new EventArgs( |
|
104 | array( |
||
105 | 13 | 'builder' => $builder, |
|
106 | 13 | 'OriginOrder' => $OriginOrder, |
|
107 | 13 | 'TargetOrder' => $TargetOrder, |
|
108 | 13 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
109 | ), |
||
110 | $request |
||
111 | ); |
||
112 | 13 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); |
|
113 | |||
114 | // 入力情報にもとづいて再計算. |
||
115 | 13 | $this->calculate($app, $TargetOrder); |
|
116 | |||
117 | // 登録ボタン押下 |
||
118 | 13 | switch ($request->get('mode')) { |
|
119 | 13 | case 'register': |
|
120 | |||
121 | 13 | log_info('受注登録開始', array($TargetOrder->getId())); |
|
122 | |||
123 | 13 | if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) { |
|
124 | log_info('受注登録入力チェックエラー', array($TargetOrder->getId())); |
||
125 | $form['charge']->addError(new FormError('合計金額の上限を超えております。')); |
||
126 | 13 | } elseif ($form->isValid()) { |
|
127 | |||
128 | 13 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
|
129 | |||
130 | // お支払い方法の更新 |
||
131 | 13 | $TargetOrder->setPaymentMethod($TargetOrder->getPayment()->getMethod()); |
|
132 | |||
133 | // 配送業者・お届け時間の更新 |
||
134 | 13 | $Shippings = $TargetOrder->getShippings(); |
|
135 | 13 | foreach ($Shippings as $Shipping) { |
|
136 | 13 | $Shipping->setShippingDeliveryName($Shipping->getDelivery()->getName()); |
|
137 | 13 | if (!is_null($Shipping->getDeliveryTime())) { |
|
138 | 13 | $Shipping->setShippingDeliveryTime($Shipping->getDeliveryTime()->getDeliveryTime()); |
|
139 | } else { |
||
140 | 13 | $Shipping->setShippingDeliveryTime(null); |
|
141 | } |
||
142 | } |
||
143 | |||
144 | |||
145 | // 受注日/発送日/入金日の更新. |
||
146 | 13 | $this->updateDate($app, $TargetOrder, $OriginOrder); |
|
147 | |||
148 | // 受注明細で削除されているものをremove |
||
149 | 13 | foreach ($OriginalOrderDetails as $OrderDetail) { |
|
150 | 9 | if (false === $TargetOrder->getOrderDetails()->contains($OrderDetail)) { |
|
151 | 13 | $app['orm.em']->remove($OrderDetail); |
|
152 | } |
||
153 | } |
||
154 | |||
155 | |||
156 | 13 | if ($BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { |
|
157 | 6 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
158 | /** @var $OrderDetail \Eccube\Entity\OrderDetail */ |
||
159 | 6 | $OrderDetail->setOrder($TargetOrder); |
|
160 | } |
||
161 | |||
162 | /** @var \Eccube\Entity\Shipping $Shipping */ |
||
163 | 6 | foreach ($Shippings as $Shipping) { |
|
164 | 6 | $shipmentItems = $Shipping->getShipmentItems(); |
|
165 | /** @var \Eccube\Entity\ShipmentItem $ShipmentItem */ |
||
166 | 6 | foreach ($shipmentItems as $ShipmentItem) { |
|
167 | // 削除予定から商品アイテムを外す |
||
168 | 6 | $OriginalShipmentItems->removeElement($ShipmentItem); |
|
169 | 6 | $ShipmentItem->setOrder($TargetOrder); |
|
170 | 6 | $ShipmentItem->setShipping($Shipping); |
|
171 | 6 | $app['orm.em']->persist($ShipmentItem); |
|
172 | } |
||
173 | // 削除予定からお届け先情報を外す |
||
174 | 6 | $OriginalShippings->removeElement($Shipping); |
|
175 | 6 | $Shipping->setOrder($TargetOrder); |
|
176 | 6 | $app['orm.em']->persist($Shipping); |
|
177 | } |
||
178 | // 商品アイテムを削除する |
||
179 | 6 | foreach ($OriginalShipmentItems as $OriginalShipmentItem) { |
|
180 | 6 | $app['orm.em']->remove($OriginalShipmentItem); |
|
181 | } |
||
182 | // お届け先情報削除する |
||
183 | 6 | foreach ($OriginalShippings as $OriginalShipping) { |
|
184 | 6 | $app['orm.em']->remove($OriginalShipping); |
|
185 | } |
||
186 | } else { |
||
187 | |||
188 | 7 | $NewShipmentItems = new ArrayCollection(); |
|
189 | |||
190 | 7 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
191 | /** @var $OrderDetail \Eccube\Entity\OrderDetail */ |
||
192 | 7 | $OrderDetail->setOrder($TargetOrder); |
|
193 | |||
194 | 7 | $NewShipmentItem = new ShipmentItem(); |
|
195 | $NewShipmentItem |
||
196 | 7 | ->setProduct($OrderDetail->getProduct()) |
|
197 | 7 | ->setProductClass($OrderDetail->getProductClass()) |
|
198 | 7 | ->setProductName($OrderDetail->getProduct()->getName()) |
|
199 | 7 | ->setProductCode($OrderDetail->getProductClass()->getCode()) |
|
200 | 7 | ->setClassCategoryName1($OrderDetail->getClassCategoryName1()) |
|
201 | 7 | ->setClassCategoryName2($OrderDetail->getClassCategoryName2()) |
|
202 | 7 | ->setClassName1($OrderDetail->getClassName1()) |
|
203 | 7 | ->setClassName2($OrderDetail->getClassName2()) |
|
204 | 7 | ->setPrice($OrderDetail->getPrice()) |
|
205 | 7 | ->setQuantity($OrderDetail->getQuantity()) |
|
206 | 7 | ->setOrder($TargetOrder); |
|
207 | 7 | $NewShipmentItems[] = $NewShipmentItem; |
|
208 | |||
209 | } |
||
210 | // 配送商品の更新. delete/insert. |
||
211 | 7 | $Shippings = $TargetOrder->getShippings(); |
|
212 | 7 | foreach ($Shippings as $Shipping) { |
|
213 | 7 | $ShipmentItems = $Shipping->getShipmentItems(); |
|
214 | 7 | foreach ($ShipmentItems as $ShipmentItem) { |
|
215 | 7 | $app['orm.em']->remove($ShipmentItem); |
|
216 | } |
||
217 | 7 | $ShipmentItems->clear(); |
|
218 | 7 | foreach ($NewShipmentItems as $NewShipmentItem) { |
|
219 | 7 | $NewShipmentItem->setShipping($Shipping); |
|
220 | 7 | $ShipmentItems->add($NewShipmentItem); |
|
221 | } |
||
222 | } |
||
223 | } |
||
224 | |||
225 | 13 | $Customer = $TargetOrder->getCustomer(); |
|
226 | 13 | if ($Customer) { |
|
227 | // 受注情報の会員情報を更新 |
||
228 | 13 | $TargetOrder->setSex($Customer->getSex()); |
|
229 | 13 | $TargetOrder->setJob($Customer->getJob()); |
|
230 | 13 | $TargetOrder->setBirth($Customer->getBirth()); |
|
231 | } |
||
232 | |||
233 | 13 | $app['orm.em']->persist($TargetOrder); |
|
234 | 13 | $app['orm.em']->flush(); |
|
235 | |||
236 | 13 | if ($Customer) { |
|
237 | // 会員の場合、購入回数、購入金額などを更新 |
||
238 | 13 | $app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId()); |
|
239 | } |
||
240 | |||
241 | 13 | $event = new EventArgs( |
|
242 | array( |
||
243 | 13 | 'form' => $form, |
|
244 | 13 | 'OriginOrder' => $OriginOrder, |
|
245 | 13 | 'TargetOrder' => $TargetOrder, |
|
246 | 13 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
247 | 13 | 'Customer' => $Customer, |
|
248 | ), |
||
249 | $request |
||
250 | ); |
||
251 | 13 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event); |
|
252 | |||
253 | 13 | $app->addSuccess('admin.order.save.complete', 'admin'); |
|
254 | |||
255 | 13 | log_info('受注登録完了', array($TargetOrder->getId())); |
|
256 | |||
257 | 13 | return $app->redirect($app->url('admin_order_edit', array('id' => $TargetOrder->getId()))); |
|
258 | } |
||
259 | |||
260 | 1 | break; |
|
261 | |||
262 | case 'add_delivery': |
||
263 | // お届け先情報の新規追加 |
||
264 | |||
265 | $form = $builder->getForm(); |
||
266 | |||
267 | $Shipping = new \Eccube\Entity\Shipping(); |
||
268 | $Shipping->setDelFlg(Constant::DISABLED); |
||
269 | |||
270 | $TargetOrder->addShipping($Shipping); |
||
271 | |||
272 | $Shipping->setOrder($TargetOrder); |
||
273 | |||
274 | $form->setData($TargetOrder); |
||
275 | |||
276 | break; |
||
277 | |||
278 | default: |
||
279 | 1 | break; |
|
280 | } |
||
281 | } |
||
282 | |||
283 | // 会員検索フォーム |
||
284 | 7 | $builder = $app['form.factory'] |
|
285 | 7 | ->createBuilder('admin_search_customer'); |
|
286 | |||
287 | 7 | $event = new EventArgs( |
|
288 | array( |
||
289 | 7 | 'builder' => $builder, |
|
290 | 7 | 'OriginOrder' => $OriginOrder, |
|
291 | 7 | 'TargetOrder' => $TargetOrder, |
|
292 | 7 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
293 | ), |
||
294 | $request |
||
295 | ); |
||
296 | 7 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event); |
|
297 | |||
298 | 7 | $searchCustomerModalForm = $builder->getForm(); |
|
299 | |||
300 | // 商品検索フォーム |
||
301 | 7 | $builder = $app['form.factory'] |
|
302 | 7 | ->createBuilder('admin_search_product'); |
|
303 | |||
304 | 7 | $event = new EventArgs( |
|
305 | array( |
||
306 | 7 | 'builder' => $builder, |
|
307 | 7 | 'OriginOrder' => $OriginOrder, |
|
308 | 7 | 'TargetOrder' => $TargetOrder, |
|
309 | 7 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
310 | ), |
||
311 | $request |
||
312 | ); |
||
313 | 7 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event); |
|
314 | |||
315 | 7 | $searchProductModalForm = $builder->getForm(); |
|
316 | |||
317 | // 配送業者のお届け時間 |
||
318 | 7 | $times = array(); |
|
319 | 7 | $deliveries = $app['eccube.repository.delivery']->findAll(); |
|
320 | 7 | foreach ($deliveries as $Delivery) { |
|
321 | 7 | $deliveryTiems = $Delivery->getDeliveryTimes(); |
|
322 | 7 | foreach ($deliveryTiems as $DeliveryTime) { |
|
323 | 7 | $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime(); |
|
324 | } |
||
325 | } |
||
326 | |||
327 | 7 | return $app->render('Order/edit.twig', array( |
|
328 | 7 | 'form' => $form->createView(), |
|
329 | 7 | 'searchCustomerModalForm' => $searchCustomerModalForm->createView(), |
|
330 | 7 | 'searchProductModalForm' => $searchProductModalForm->createView(), |
|
331 | 7 | 'Order' => $TargetOrder, |
|
332 | 7 | 'id' => $id, |
|
333 | 7 | 'shippingDeliveryTimes' => $app['serializer']->serialize($times, 'json'), |
|
334 | )); |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * 顧客情報を検索する. |
||
339 | * |
||
340 | * @param Application $app |
||
341 | * @param Request $request |
||
342 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
343 | */ |
||
344 | 5 | public function searchCustomer(Application $app, Request $request) |
|
345 | { |
||
346 | 5 | if ($request->isXmlHttpRequest()) { |
|
347 | 5 | $app['monolog']->addDebug('search customer start.'); |
|
348 | |||
349 | $searchData = array( |
||
350 | 5 | 'multi' => $request->get('search_word'), |
|
351 | ); |
||
352 | |||
353 | 5 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
|
354 | |||
355 | 5 | $event = new EventArgs( |
|
356 | array( |
||
357 | 5 | 'qb' => $qb, |
|
358 | 5 | 'data' => $searchData, |
|
359 | ), |
||
360 | $request |
||
361 | ); |
||
362 | 5 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
|
363 | |||
364 | 5 | $Customers = $qb->getQuery()->getResult(); |
|
365 | |||
366 | |||
367 | 5 | if (empty($Customers)) { |
|
368 | $app['monolog']->addDebug('search customer not found.'); |
||
369 | } |
||
370 | |||
371 | 5 | $data = array(); |
|
372 | |||
373 | 5 | $formatTel = '%s-%s-%s'; |
|
374 | 5 | $formatName = '%s%s(%s%s)'; |
|
375 | 5 | View Code Duplication | foreach ($Customers as $Customer) { |
0 ignored issues
–
show
|
|||
376 | 5 | $data[] = array( |
|
377 | 5 | 'id' => $Customer->getId(), |
|
378 | 5 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(), |
|
379 | 5 | $Customer->getKana02()), |
|
380 | 5 | 'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()), |
|
381 | 5 | 'email' => $Customer->getEmail(), |
|
382 | ); |
||
383 | } |
||
384 | |||
385 | 5 | $event = new EventArgs( |
|
386 | array( |
||
387 | 5 | 'data' => $data, |
|
388 | 5 | 'Customers' => $Customers, |
|
389 | ), |
||
390 | $request |
||
391 | ); |
||
392 | 5 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
|
393 | 5 | $data = $event->getArgument('data'); |
|
394 | |||
395 | 5 | return $app->json($data); |
|
396 | } |
||
397 | } |
||
398 | |||
399 | /** |
||
400 | * 顧客情報を検索する. |
||
401 | * |
||
402 | * @param Application $app |
||
403 | * @param Request $request |
||
0 ignored issues
–
show
|
|||
404 | * @param integer $page_no |
||
0 ignored issues
–
show
|
|||
405 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
406 | */ |
||
407 | 1 | public function searchCustomerHtml(Application $app, Request $request, $page_no = null) |
|
408 | { |
||
409 | 1 | if ($request->isXmlHttpRequest()) { |
|
410 | 1 | $app['monolog']->addDebug('search customer start.'); |
|
411 | 1 | $page_count = $app['config']['default_page_count']; |
|
412 | 1 | $session = $app['session']; |
|
413 | |||
414 | 1 | if ('POST' === $request->getMethod()) { |
|
0 ignored issues
–
show
|
|||
415 | |||
416 | 1 | $page_no = 1; |
|
417 | |||
418 | $searchData = array( |
||
419 | 1 | 'multi' => $request->get('search_word'), |
|
420 | ); |
||
421 | |||
422 | 1 | $session->set('eccube.admin.order.customer.search', $searchData); |
|
423 | 1 | $session->set('eccube.admin.order.customer.search.page_no', $page_no); |
|
424 | } else { |
||
425 | $searchData = (array)$session->get('eccube.admin.order.customer.search'); |
||
0 ignored issues
–
show
|
|||
426 | if (is_null($page_no)) { |
||
427 | $page_no = intval($session->get('eccube.admin.order.customer.search.page_no')); |
||
428 | } else { |
||
429 | $session->set('eccube.admin.order.customer.search.page_no', $page_no); |
||
430 | } |
||
431 | } |
||
432 | |||
433 | 1 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
|
434 | |||
435 | 1 | $event = new EventArgs( |
|
436 | array( |
||
437 | 1 | 'qb' => $qb, |
|
438 | 1 | 'data' => $searchData, |
|
439 | ), |
||
440 | $request |
||
441 | ); |
||
442 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
|
443 | |||
444 | /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
||
445 | 1 | $pagination = $app['paginator']()->paginate( |
|
446 | $qb, |
||
447 | $page_no, |
||
448 | $page_count, |
||
449 | 1 | array('wrap-queries' => true) |
|
450 | ); |
||
451 | |||
452 | /** @var $Customers \Eccube\Entity\Customer[] */ |
||
453 | 1 | $Customers = $pagination->getItems(); |
|
454 | |||
455 | 1 | if (empty($Customers)) { |
|
456 | $app['monolog']->addDebug('search customer not found.'); |
||
457 | } |
||
458 | |||
459 | 1 | $data = array(); |
|
460 | |||
461 | 1 | $formatTel = '%s-%s-%s'; |
|
462 | 1 | $formatName = '%s%s(%s%s)'; |
|
463 | 1 | View Code Duplication | foreach ($Customers as $Customer) { |
464 | 1 | $data[] = array( |
|
465 | 1 | 'id' => $Customer->getId(), |
|
466 | 1 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(), |
|
467 | 1 | $Customer->getKana02()), |
|
468 | 1 | 'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()), |
|
469 | 1 | 'email' => $Customer->getEmail(), |
|
470 | ); |
||
471 | } |
||
472 | |||
473 | 1 | $event = new EventArgs( |
|
474 | array( |
||
475 | 1 | 'data' => $data, |
|
476 | 1 | 'Customers' => $pagination, |
|
477 | ), |
||
478 | $request |
||
479 | ); |
||
480 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
|
481 | 1 | $data = $event->getArgument('data'); |
|
482 | |||
483 | 1 | return $app->render('Order/search_customer.twig', array( |
|
484 | 1 | 'data' => $data, |
|
485 | 1 | 'pagination' => $pagination, |
|
486 | )); |
||
487 | } |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * 顧客情報を検索する. |
||
492 | * |
||
493 | * @param Application $app |
||
494 | * @param Request $request |
||
495 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
496 | */ |
||
497 | 3 | public function searchCustomerById(Application $app, Request $request) |
|
498 | { |
||
499 | 3 | if ($request->isXmlHttpRequest()) { |
|
500 | 3 | $app['monolog']->addDebug('search customer by id start.'); |
|
501 | |||
502 | /** @var $Customer \Eccube\Entity\Customer */ |
||
503 | 3 | $Customer = $app['eccube.repository.customer'] |
|
504 | 3 | ->find($request->get('id')); |
|
505 | |||
506 | 3 | $event = new EventArgs( |
|
507 | array( |
||
508 | 3 | 'Customer' => $Customer, |
|
509 | ), |
||
510 | $request |
||
511 | ); |
||
512 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event); |
|
513 | |||
514 | 3 | if (is_null($Customer)) { |
|
515 | $app['monolog']->addDebug('search customer by id not found.'); |
||
516 | |||
517 | return $app->json(array(), 404); |
||
518 | } |
||
519 | |||
520 | 3 | $app['monolog']->addDebug('search customer by id found.'); |
|
521 | |||
522 | $data = array( |
||
523 | 3 | 'id' => $Customer->getId(), |
|
524 | 3 | 'name01' => $Customer->getName01(), |
|
525 | 3 | 'name02' => $Customer->getName02(), |
|
526 | 3 | 'kana01' => $Customer->getKana01(), |
|
527 | 3 | 'kana02' => $Customer->getKana02(), |
|
528 | 3 | 'zip01' => $Customer->getZip01(), |
|
529 | 3 | 'zip02' => $Customer->getZip02(), |
|
530 | 3 | 'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(), |
|
531 | 3 | 'addr01' => $Customer->getAddr01(), |
|
532 | 3 | 'addr02' => $Customer->getAddr02(), |
|
533 | 3 | 'email' => $Customer->getEmail(), |
|
534 | 3 | 'tel01' => $Customer->getTel01(), |
|
535 | 3 | 'tel02' => $Customer->getTel02(), |
|
536 | 3 | 'tel03' => $Customer->getTel03(), |
|
537 | 3 | 'fax01' => $Customer->getFax01(), |
|
538 | 3 | 'fax02' => $Customer->getFax02(), |
|
539 | 3 | 'fax03' => $Customer->getFax03(), |
|
540 | 3 | 'company_name' => $Customer->getCompanyName(), |
|
541 | ); |
||
542 | |||
543 | 3 | $event = new EventArgs( |
|
544 | array( |
||
545 | 3 | 'data' => $data, |
|
546 | 3 | 'Customer' => $Customer, |
|
547 | ), |
||
548 | $request |
||
549 | ); |
||
550 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event); |
|
551 | 3 | $data = $event->getArgument('data'); |
|
552 | |||
553 | 3 | return $app->json($data); |
|
554 | } |
||
555 | } |
||
556 | |||
557 | 3 | public function searchProduct(Application $app, Request $request, $page_no = null) |
|
558 | { |
||
559 | 3 | if ($request->isXmlHttpRequest()) { |
|
560 | 3 | $app['monolog']->addDebug('search product start.'); |
|
561 | 3 | $page_count = $app['config']['default_page_count']; |
|
562 | 3 | $session = $app['session']; |
|
563 | |||
564 | 3 | if ('POST' === $request->getMethod()) { |
|
0 ignored issues
–
show
|
|||
565 | |||
566 | 3 | $page_no = 1; |
|
567 | |||
568 | $searchData = array( |
||
569 | 3 | 'id' => $request->get('id'), |
|
570 | ); |
||
571 | |||
572 | 3 | if ($categoryId = $request->get('category_id')) { |
|
573 | $Category = $app['eccube.repository.category']->find($categoryId); |
||
574 | $searchData['category_id'] = $Category; |
||
575 | } |
||
576 | |||
577 | 3 | $session->set('eccube.admin.order.product.search', $searchData); |
|
578 | 3 | $session->set('eccube.admin.order.product.search.page_no', $page_no); |
|
579 | } else { |
||
580 | $searchData = (array)$session->get('eccube.admin.order.product.search'); |
||
0 ignored issues
–
show
|
|||
581 | if (is_null($page_no)) { |
||
582 | $page_no = intval($session->get('eccube.admin.order.product.search.page_no')); |
||
583 | } else { |
||
584 | $session->set('eccube.admin.order.product.search.page_no', $page_no); |
||
585 | } |
||
586 | } |
||
587 | |||
588 | 3 | $qb = $app['eccube.repository.product'] |
|
589 | 3 | ->getQueryBuilderBySearchDataForAdmin($searchData); |
|
590 | |||
591 | 3 | $event = new EventArgs( |
|
592 | array( |
||
593 | 3 | 'qb' => $qb, |
|
594 | 3 | 'searchData' => $searchData, |
|
595 | ), |
||
596 | $request |
||
597 | ); |
||
598 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event); |
|
599 | |||
600 | /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
||
601 | 3 | $pagination = $app['paginator']()->paginate( |
|
602 | $qb, |
||
603 | $page_no, |
||
604 | $page_count, |
||
605 | 3 | array('wrap-queries' => true) |
|
606 | ); |
||
607 | |||
608 | /** @var $Products \Eccube\Entity\Product[] */ |
||
609 | 3 | $Products = $pagination->getItems(); |
|
610 | |||
611 | 3 | if (empty($Products)) { |
|
612 | $app['monolog']->addDebug('search product not found.'); |
||
613 | } |
||
614 | |||
615 | 3 | $forms = array(); |
|
616 | 3 | foreach ($Products as $Product) { |
|
617 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
618 | 3 | $builder = $app['form.factory']->createNamedBuilder('', 'add_cart', null, array( |
|
619 | 3 | 'product' => $Product, |
|
620 | )); |
||
621 | 3 | $addCartForm = $builder->getForm(); |
|
622 | 3 | $forms[$Product->getId()] = $addCartForm->createView(); |
|
623 | } |
||
624 | |||
625 | 3 | $event = new EventArgs( |
|
626 | array( |
||
627 | 3 | 'forms' => $forms, |
|
628 | 3 | 'Products' => $Products, |
|
629 | 3 | 'pagination' => $pagination, |
|
630 | ), |
||
631 | $request |
||
632 | ); |
||
633 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event); |
|
634 | |||
635 | 3 | return $app->render('Order/search_product.twig', array( |
|
636 | 3 | 'forms' => $forms, |
|
637 | 3 | 'Products' => $Products, |
|
638 | 3 | 'pagination' => $pagination, |
|
639 | )); |
||
640 | } |
||
641 | } |
||
642 | |||
643 | 7 | protected function newOrder(Application $app) |
|
644 | { |
||
645 | 7 | $Order = new \Eccube\Entity\Order(); |
|
646 | 7 | $Shipping = new \Eccube\Entity\Shipping(); |
|
647 | 7 | $Shipping->setDelFlg(0); |
|
648 | 7 | $Order->addShipping($Shipping); |
|
649 | 7 | $Shipping->setOrder($Order); |
|
650 | |||
651 | // device type |
||
652 | 7 | $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_ADMIN); |
|
653 | 7 | $Order->setDeviceType($DeviceType); |
|
654 | |||
655 | 7 | return $Order; |
|
656 | } |
||
657 | |||
658 | /** |
||
659 | * フォームからの入直内容に基づいて、受注情報の再計算を行う |
||
660 | * |
||
661 | * @param $app |
||
662 | * @param $Order |
||
663 | */ |
||
664 | 13 | protected function calculate($app, \Eccube\Entity\Order $Order) |
|
665 | { |
||
666 | 13 | $taxtotal = 0; |
|
667 | 13 | $subtotal = 0; |
|
668 | |||
669 | // 受注明細データの税・小計を再計算 |
||
670 | /** @var $OrderDetails \Eccube\Entity\OrderDetail[] */ |
||
671 | 13 | $OrderDetails = $Order->getOrderDetails(); |
|
672 | 13 | foreach ($OrderDetails as $OrderDetail) { |
|
673 | // 税 |
||
674 | 13 | $tax = $app['eccube.service.tax_rule'] |
|
675 | 13 | ->calcTax($OrderDetail->getPrice(), $OrderDetail->getTaxRate(), $OrderDetail->getTaxRule()); |
|
676 | 13 | $OrderDetail->setPriceIncTax($OrderDetail->getPrice() + $tax); |
|
677 | |||
678 | 13 | $taxtotal += $tax * $OrderDetail->getQuantity(); |
|
679 | |||
680 | // 小計 |
||
681 | 13 | $subtotal += $OrderDetail->getTotalPrice(); |
|
682 | } |
||
683 | |||
684 | 13 | $shippings = $Order->getShippings(); |
|
685 | /** @var \Eccube\Entity\Shipping $Shipping */ |
||
686 | 13 | foreach ($shippings as $Shipping) { |
|
687 | 13 | $Shipping->setDelFlg(Constant::DISABLED); |
|
688 | } |
||
689 | |||
690 | // 受注データの税・小計・合計を再計算 |
||
691 | 13 | $Order->setTax($taxtotal); |
|
692 | 13 | $Order->setSubtotal($subtotal); |
|
693 | 13 | $Order->setTotal($subtotal + $Order->getCharge() + $Order->getDeliveryFeeTotal() - $Order->getDiscount()); |
|
694 | // お支払い合計は、totalと同一金額(2系ではtotal - point) |
||
695 | 13 | $Order->setPaymentTotal($Order->getTotal()); |
|
696 | } |
||
697 | |||
698 | /** |
||
699 | * 受注ステータスに応じて, 受注日/入金日/発送日を更新する, |
||
700 | * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う. |
||
701 | * |
||
702 | * 編集の場合 |
||
703 | * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新 |
||
704 | * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新 |
||
705 | * |
||
706 | * 新規登録の場合 |
||
707 | * - 受注日を更新 |
||
708 | * - 受注ステータスが発送済に設定された場合に発送日を更新 |
||
709 | * - 受注ステータスが入金済に設定された場合に入金日を更新 |
||
710 | * |
||
711 | * |
||
712 | * @param $app |
||
713 | * @param $TargetOrder |
||
714 | * @param $OriginOrder |
||
715 | */ |
||
716 | 13 | protected function updateDate($app, $TargetOrder, $OriginOrder) |
|
717 | { |
||
718 | 13 | $dateTime = new \DateTime(); |
|
719 | |||
720 | // 編集 |
||
721 | 13 | if ($TargetOrder->getId()) { |
|
722 | // 発送済 |
||
723 | 9 | if ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_deliv']) { |
|
724 | // 編集前と異なる場合のみ更新 |
||
725 | if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { |
||
726 | $TargetOrder->setCommitDate($dateTime); |
||
727 | // お届け先情報の発送日も更新する. |
||
728 | $Shippings = $TargetOrder->getShippings(); |
||
729 | foreach ($Shippings as $Shipping) { |
||
730 | $Shipping->setShippingCommitDate($dateTime); |
||
731 | } |
||
732 | } |
||
733 | // 入金済 |
||
734 | 9 | } elseif ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_pre_end']) { |
|
735 | // 編集前と異なる場合のみ更新 |
||
736 | if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { |
||
737 | 9 | $TargetOrder->setPaymentDate($dateTime); |
|
738 | } |
||
739 | } |
||
740 | // 新規 |
||
741 | } else { |
||
742 | // 発送済 |
||
743 | 4 | if ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_deliv']) { |
|
744 | $TargetOrder->setCommitDate($dateTime); |
||
745 | // お届け先情報の発送日も更新する. |
||
746 | $Shippings = $TargetOrder->getShippings(); |
||
747 | foreach ($Shippings as $Shipping) { |
||
748 | $Shipping->setShippingCommitDate($dateTime); |
||
749 | } |
||
750 | // 入金済 |
||
751 | 4 | } elseif ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_pre_end']) { |
|
752 | $TargetOrder->setPaymentDate($dateTime); |
||
753 | } |
||
754 | // 受注日時 |
||
755 | 4 | $TargetOrder->setOrderDate($dateTime); |
|
756 | } |
||
757 | } |
||
758 | } |
||
759 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.