Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EditController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EditController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 37 | class EditController extends AbstractController |
||
|
|
|||
| 38 | { |
||
| 39 | 16 | public function index(Application $app, Request $request, $id = null) |
|
| 40 | { |
||
| 41 | /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
||
| 42 | 16 | $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
| 43 | 16 | $softDeleteFilter->setExcludes(array( |
|
| 44 | 16 | 'Eccube\Entity\ProductClass', |
|
| 45 | 16 | 'Eccube\Entity\Product', |
|
| 46 | 16 | )); |
|
| 47 | |||
| 48 | 16 | $TargetOrder = null; |
|
| 49 | 16 | $OriginOrder = null; |
|
| 50 | |||
| 51 | 16 | if (is_null($id)) { |
|
| 52 | // 空のエンティティを作成. |
||
| 53 | 6 | $TargetOrder = $this->newOrder(); |
|
| 54 | 6 | } else { |
|
| 55 | 10 | $TargetOrder = $app['eccube.repository.order']->find($id); |
|
| 56 | 10 | if (is_null($TargetOrder)) { |
|
| 57 | throw new NotFoundHttpException(); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | // 編集前の受注情報を保持 |
||
| 62 | 16 | $OriginOrder = clone $TargetOrder; |
|
| 63 | 16 | $OriginalOrderDetails = new ArrayCollection(); |
|
| 64 | |||
| 65 | 16 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
| 66 | 10 | $OriginalOrderDetails->add($OrderDetail); |
|
| 67 | 16 | } |
|
| 68 | |||
| 69 | 16 | $builder = $app['form.factory'] |
|
| 70 | 16 | ->createBuilder('order', $TargetOrder); |
|
| 71 | |||
| 72 | 16 | $event = new EventArgs( |
|
| 73 | array( |
||
| 74 | 16 | 'builder' => $builder, |
|
| 75 | 16 | 'OriginOrder' => $OriginOrder, |
|
| 76 | 16 | 'TargetOrder' => $TargetOrder, |
|
| 77 | 16 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
| 78 | 16 | ), |
|
| 79 | 6 | $request |
|
| 80 | 16 | ); |
|
| 81 | 16 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event); |
|
| 82 | |||
| 83 | 16 | $form = $builder->getForm(); |
|
| 84 | |||
| 85 | 16 | if ('POST' === $request->getMethod()) { |
|
| 86 | 10 | $form->handleRequest($request); |
|
| 87 | |||
| 88 | 10 | $event = new EventArgs( |
|
| 89 | array( |
||
| 90 | 10 | 'builder' => $builder, |
|
| 91 | 10 | 'OriginOrder' => $OriginOrder, |
|
| 92 | 10 | 'TargetOrder' => $TargetOrder, |
|
| 93 | 10 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
| 94 | 10 | ), |
|
| 95 | $request |
||
| 96 | 10 | ); |
|
| 97 | 10 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); |
|
| 98 | |||
| 99 | // 入力情報にもとづいて再計算. |
||
| 100 | 10 | $this->calculate($app, $TargetOrder); |
|
| 101 | |||
| 102 | // 登録ボタン押下 |
||
| 103 | 10 | switch ($request->get('mode')) { |
|
| 104 | 10 | case 'register': |
|
| 105 | 10 | if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) { |
|
| 106 | $form['charge']->addError(new FormError('合計金額の上限を超えております。')); |
||
| 107 | 10 | } elseif ($form->isValid()) { |
|
| 108 | |||
| 109 | 10 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
|
| 110 | |||
| 111 | // お支払い方法の更新 |
||
| 112 | 10 | $TargetOrder->setPaymentMethod($TargetOrder->getPayment()->getMethod()); |
|
| 113 | |||
| 114 | // 配送業者・お届け時間の更新 |
||
| 115 | 10 | $Shippings = $TargetOrder->getShippings(); |
|
| 116 | 10 | foreach ($Shippings as $Shipping) { |
|
| 117 | 10 | $Shipping->setShippingDeliveryName($Shipping->getDelivery()->getName()); |
|
| 118 | 10 | if (!is_null($Shipping->getDeliveryTime())) { |
|
| 119 | 10 | $Shipping->setShippingDeliveryTime($Shipping->getDeliveryTime()->getDeliveryTime()); |
|
| 120 | 10 | } else { |
|
| 121 | $Shipping->setShippingDeliveryTime(null); |
||
| 122 | } |
||
| 123 | 10 | } |
|
| 124 | |||
| 125 | |||
| 126 | // 受注日/発送日/入金日の更新. |
||
| 127 | 10 | $this->updateDate($app, $TargetOrder, $OriginOrder); |
|
| 128 | |||
| 129 | // 受注明細で削除されているものをremove |
||
| 130 | 10 | foreach ($OriginalOrderDetails as $OrderDetail) { |
|
| 131 | 7 | if (false === $TargetOrder->getOrderDetails()->contains($OrderDetail)) { |
|
| 132 | $app['orm.em']->remove($OrderDetail); |
||
| 133 | } |
||
| 134 | 10 | } |
|
| 135 | |||
| 136 | |||
| 137 | 10 | if ($BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { |
|
| 138 | 4 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
| 139 | /** @var $OrderDetail \Eccube\Entity\OrderDetail */ |
||
| 140 | 4 | $OrderDetail->setOrder($TargetOrder); |
|
| 141 | 4 | } |
|
| 142 | |||
| 143 | /** @var \Eccube\Entity\Shipping $Shipping */ |
||
| 144 | 4 | View Code Duplication | foreach ($Shippings as $Shipping) { |
| 145 | 4 | $shipmentItems = $Shipping->getShipmentItems(); |
|
| 146 | /** @var \Eccube\Entity\ShipmentItem $ShipmentItem */ |
||
| 147 | 4 | foreach ($shipmentItems as $ShipmentItem) { |
|
| 148 | 4 | $ShipmentItem->setOrder($TargetOrder); |
|
| 149 | 4 | $ShipmentItem->setShipping($Shipping); |
|
| 150 | 4 | $app['orm.em']->persist($ShipmentItem); |
|
| 151 | 4 | } |
|
| 152 | 4 | $Shipping->setOrder($TargetOrder); |
|
| 153 | 4 | $app['orm.em']->persist($Shipping); |
|
| 154 | 4 | } |
|
| 155 | 4 | } else { |
|
| 156 | |||
| 157 | 6 | $NewShipmentItems = new ArrayCollection(); |
|
| 158 | |||
| 159 | 6 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
| 160 | /** @var $OrderDetail \Eccube\Entity\OrderDetail */ |
||
| 161 | 6 | $OrderDetail->setOrder($TargetOrder); |
|
| 162 | |||
| 163 | 6 | $NewShipmentItem = new ShipmentItem(); |
|
| 164 | $NewShipmentItem |
||
| 165 | 6 | ->setProduct($OrderDetail->getProduct()) |
|
| 166 | 6 | ->setProductClass($OrderDetail->getProductClass()) |
|
| 167 | 6 | ->setProductName($OrderDetail->getProduct()->getName()) |
|
| 168 | 6 | ->setProductCode($OrderDetail->getProductClass()->getCode()) |
|
| 169 | 6 | ->setClassCategoryName1($OrderDetail->getClassCategoryName1()) |
|
| 170 | 6 | ->setClassCategoryName2($OrderDetail->getClassCategoryName2()) |
|
| 171 | 6 | ->setClassName1($OrderDetail->getClassName1()) |
|
| 172 | 6 | ->setClassName2($OrderDetail->getClassName2()) |
|
| 173 | 6 | ->setPrice($OrderDetail->getPrice()) |
|
| 174 | 6 | ->setQuantity($OrderDetail->getQuantity()) |
|
| 175 | 6 | ->setOrder($TargetOrder); |
|
| 176 | 6 | $NewShipmentItems[] = $NewShipmentItem; |
|
| 177 | |||
| 178 | 6 | } |
|
| 179 | // 配送商品の更新. delete/insert. |
||
| 180 | 6 | $Shippings = $TargetOrder->getShippings(); |
|
| 181 | 6 | View Code Duplication | foreach ($Shippings as $Shipping) { |
| 182 | 6 | $ShipmentItems = $Shipping->getShipmentItems(); |
|
| 183 | 6 | foreach ($ShipmentItems as $ShipmentItem) { |
|
| 184 | 4 | $app['orm.em']->remove($ShipmentItem); |
|
| 185 | 6 | } |
|
| 186 | 6 | $ShipmentItems->clear(); |
|
| 187 | 6 | foreach ($NewShipmentItems as $NewShipmentItem) { |
|
| 188 | 6 | $NewShipmentItem->setShipping($Shipping); |
|
| 189 | 6 | $ShipmentItems->add($NewShipmentItem); |
|
| 190 | 6 | } |
|
| 191 | 6 | } |
|
| 192 | } |
||
| 193 | |||
| 194 | 10 | $app['orm.em']->persist($TargetOrder); |
|
| 195 | 10 | $app['orm.em']->flush(); |
|
| 196 | |||
| 197 | 10 | $Customer = $TargetOrder->getCustomer(); |
|
| 198 | 10 | if ($Customer) { |
|
| 199 | // 会員の場合、購入回数、購入金額などを更新 |
||
| 200 | 10 | $app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId()); |
|
| 201 | 10 | } |
|
| 202 | |||
| 203 | |||
| 204 | 10 | $event = new EventArgs( |
|
| 205 | array( |
||
| 206 | 10 | 'form' => $form, |
|
| 207 | 10 | 'OriginOrder' => $OriginOrder, |
|
| 208 | 10 | 'TargetOrder' => $TargetOrder, |
|
| 209 | 10 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
| 210 | 10 | 'Customer' => $Customer, |
|
| 211 | 10 | ), |
|
| 212 | $request |
||
| 213 | 10 | ); |
|
| 214 | 10 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event); |
|
| 215 | |||
| 216 | 10 | $app->addSuccess('admin.order.save.complete', 'admin'); |
|
| 217 | |||
| 218 | 10 | return $app->redirect($app->url('admin_order_edit', array('id' => $TargetOrder->getId()))); |
|
| 219 | } |
||
| 220 | |||
| 221 | 2 | break; |
|
| 222 | |||
| 223 | case 'add_delivery': |
||
| 224 | // お届け先情報の新規追加 |
||
| 225 | |||
| 226 | $form = $builder->getForm(); |
||
| 227 | |||
| 228 | $Shipping = new \Eccube\Entity\Shipping(); |
||
| 229 | $Shipping->setDelFlg(Constant::DISABLED); |
||
| 230 | |||
| 231 | $TargetOrder->addShipping($Shipping); |
||
| 232 | |||
| 233 | $Shipping->setOrder($TargetOrder); |
||
| 234 | |||
| 235 | $form->setData($TargetOrder); |
||
| 236 | |||
| 237 | break; |
||
| 238 | |||
| 239 | 11 | default: |
|
| 240 | break; |
||
| 241 | 11 | } |
|
| 242 | 2 | } |
|
| 243 | |||
| 244 | // 会員検索フォーム |
||
| 245 | 8 | $builder = $app['form.factory'] |
|
| 246 | 8 | ->createBuilder('admin_search_customer'); |
|
| 247 | |||
| 248 | 8 | $event = new EventArgs( |
|
| 249 | array( |
||
| 250 | 8 | 'builder' => $builder, |
|
| 251 | 8 | 'OriginOrder' => $OriginOrder, |
|
| 252 | 8 | 'TargetOrder' => $TargetOrder, |
|
| 253 | 8 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
| 254 | 8 | ), |
|
| 255 | $request |
||
| 256 | 8 | ); |
|
| 257 | 8 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event); |
|
| 258 | |||
| 259 | 8 | $searchCustomerModalForm = $builder->getForm(); |
|
| 260 | |||
| 261 | // 商品検索フォーム |
||
| 262 | 8 | $builder = $app['form.factory'] |
|
| 263 | 8 | ->createBuilder('admin_search_product'); |
|
| 264 | |||
| 265 | 8 | $event = new EventArgs( |
|
| 266 | array( |
||
| 267 | 8 | 'builder' => $builder, |
|
| 268 | 8 | 'OriginOrder' => $OriginOrder, |
|
| 269 | 8 | 'TargetOrder' => $TargetOrder, |
|
| 270 | 8 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
| 271 | 8 | ), |
|
| 272 | $request |
||
| 273 | 8 | ); |
|
| 274 | 8 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event); |
|
| 275 | |||
| 276 | 8 | $searchProductModalForm = $builder->getForm(); |
|
| 277 | |||
| 278 | // 配送業者のお届け時間 |
||
| 279 | 8 | $times = array(); |
|
| 280 | 8 | $deliveries = $app['eccube.repository.delivery']->findAll(); |
|
| 281 | 8 | foreach ($deliveries as $Delivery) { |
|
| 282 | 8 | $deliveryTiems = $Delivery->getDeliveryTimes(); |
|
| 283 | 8 | foreach ($deliveryTiems as $DeliveryTime) { |
|
| 284 | 8 | $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime(); |
|
| 285 | 8 | } |
|
| 286 | 8 | } |
|
| 287 | |||
| 288 | 8 | return $app->render('Order/edit.twig', array( |
|
| 289 | 8 | 'form' => $form->createView(), |
|
| 290 | 8 | 'searchCustomerModalForm' => $searchCustomerModalForm->createView(), |
|
| 291 | 8 | 'searchProductModalForm' => $searchProductModalForm->createView(), |
|
| 292 | 8 | 'Order' => $TargetOrder, |
|
| 293 | 8 | 'id' => $id, |
|
| 294 | 8 | 'shippingDeliveryTimes' => $app['serializer']->serialize($times, 'json'), |
|
| 295 | 8 | )); |
|
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * 顧客情報を検索する. |
||
| 300 | * |
||
| 301 | * @param Application $app |
||
| 302 | * @param Request $request |
||
| 303 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
| 304 | */ |
||
| 305 | 3 | public function searchCustomer(Application $app, Request $request) |
|
| 306 | { |
||
| 307 | 3 | if ($request->isXmlHttpRequest()) { |
|
| 308 | 3 | $app['monolog']->addDebug('search customer start.'); |
|
| 309 | |||
| 310 | $searchData = array( |
||
| 311 | 3 | 'multi' => $request->get('search_word'), |
|
| 312 | 3 | ); |
|
| 313 | |||
| 314 | 3 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
|
| 315 | |||
| 316 | 3 | $event = new EventArgs( |
|
| 317 | array( |
||
| 318 | 3 | 'qb' => $qb, |
|
| 319 | 3 | 'data' => $searchData, |
|
| 320 | 3 | ), |
|
| 321 | $request |
||
| 322 | 3 | ); |
|
| 323 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
|
| 324 | |||
| 325 | 3 | $Customers = $qb->getQuery()->getResult(); |
|
| 326 | |||
| 327 | |||
| 328 | 3 | if (empty($Customers)) { |
|
| 329 | $app['monolog']->addDebug('search customer not found.'); |
||
| 330 | } |
||
| 331 | |||
| 332 | 3 | $data = array(); |
|
| 333 | |||
| 334 | 3 | $formatTel = '%s-%s-%s'; |
|
| 335 | 3 | $formatName = '%s%s(%s%s)'; |
|
| 336 | 3 | foreach ($Customers as $Customer) { |
|
| 337 | 3 | $data[] = array( |
|
| 338 | 3 | 'id' => $Customer->getId(), |
|
| 339 | 3 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(), |
|
| 340 | 3 | $Customer->getKana02()), |
|
| 341 | 3 | 'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()), |
|
| 342 | ); |
||
| 343 | 3 | } |
|
| 344 | |||
| 345 | 3 | $event = new EventArgs( |
|
| 346 | array( |
||
| 347 | 3 | 'data' => $data, |
|
| 348 | 3 | 'Customers' => $Customers, |
|
| 349 | 3 | ), |
|
| 350 | $request |
||
| 351 | 3 | ); |
|
| 352 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
|
| 353 | 3 | $data = $event->getArgument('data'); |
|
| 354 | |||
| 355 | 3 | return $app->json($data); |
|
| 356 | } |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * 顧客情報を検索する. |
||
| 361 | * |
||
| 362 | * @param Application $app |
||
| 363 | * @param Request $request |
||
| 364 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
| 365 | */ |
||
| 366 | 3 | public function searchCustomerById(Application $app, Request $request) |
|
| 367 | { |
||
| 368 | 3 | if ($request->isXmlHttpRequest()) { |
|
| 369 | 3 | $app['monolog']->addDebug('search customer by id start.'); |
|
| 370 | |||
| 371 | /** @var $Customer \Eccube\Entity\Customer */ |
||
| 372 | 3 | $Customer = $app['eccube.repository.customer'] |
|
| 373 | 3 | ->find($request->get('id')); |
|
| 374 | |||
| 375 | 3 | $event = new EventArgs( |
|
| 376 | array( |
||
| 377 | 3 | 'Customer' => $Customer, |
|
| 378 | 3 | ), |
|
| 379 | $request |
||
| 380 | 3 | ); |
|
| 381 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event); |
|
| 382 | |||
| 383 | 3 | if (is_null($Customer)) { |
|
| 384 | $app['monolog']->addDebug('search customer by id not found.'); |
||
| 385 | |||
| 386 | return $app->json(array(), 404); |
||
| 387 | } |
||
| 388 | |||
| 389 | 3 | $app['monolog']->addDebug('search customer by id found.'); |
|
| 390 | |||
| 391 | $data = array( |
||
| 392 | 3 | 'id' => $Customer->getId(), |
|
| 393 | 3 | 'name01' => $Customer->getName01(), |
|
| 394 | 3 | 'name02' => $Customer->getName02(), |
|
| 395 | 3 | 'kana01' => $Customer->getKana01(), |
|
| 396 | 3 | 'kana02' => $Customer->getKana02(), |
|
| 397 | 3 | 'zip01' => $Customer->getZip01(), |
|
| 398 | 3 | 'zip02' => $Customer->getZip02(), |
|
| 399 | 3 | 'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(), |
|
| 400 | 3 | 'addr01' => $Customer->getAddr01(), |
|
| 401 | 3 | 'addr02' => $Customer->getAddr02(), |
|
| 402 | 3 | 'email' => $Customer->getEmail(), |
|
| 403 | 3 | 'tel01' => $Customer->getTel01(), |
|
| 404 | 3 | 'tel02' => $Customer->getTel02(), |
|
| 405 | 3 | 'tel03' => $Customer->getTel03(), |
|
| 406 | 3 | 'fax01' => $Customer->getFax01(), |
|
| 407 | 3 | 'fax02' => $Customer->getFax02(), |
|
| 408 | 3 | 'fax03' => $Customer->getFax03(), |
|
| 409 | 3 | 'company_name' => $Customer->getCompanyName(), |
|
| 410 | 3 | ); |
|
| 411 | |||
| 412 | 3 | $event = new EventArgs( |
|
| 413 | array( |
||
| 414 | 3 | 'data' => $data, |
|
| 415 | 3 | 'Customer' => $Customer, |
|
| 416 | 3 | ), |
|
| 417 | $request |
||
| 418 | 3 | ); |
|
| 419 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event); |
|
| 420 | 3 | $data = $event->getArgument('data'); |
|
| 421 | |||
| 422 | 3 | return $app->json($data); |
|
| 423 | } |
||
| 424 | } |
||
| 425 | |||
| 426 | 13 | public function searchProduct(Application $app, Request $request) |
|
| 427 | { |
||
| 428 | 3 | if ($request->isXmlHttpRequest()) { |
|
| 429 | 3 | $app['monolog']->addDebug('search product start.'); |
|
| 430 | |||
| 431 | $searchData = array( |
||
| 432 | 3 | 'name' => $request->get('id'), |
|
| 433 | 3 | ); |
|
| 434 | |||
| 435 | 3 | if ($categoryId = $request->get('category_id')) { |
|
| 436 | $Category = $app['eccube.repository.category']->find($categoryId); |
||
| 437 | 10 | $searchData['category_id'] = $Category; |
|
| 438 | 10 | } |
|
| 439 | |||
| 440 | /** @var $Products \Eccube\Entity\Product[] */ |
||
| 441 | 13 | $qb = $app['eccube.repository.product'] |
|
| 442 | 3 | ->getQueryBuilderBySearchData($searchData); |
|
| 443 | |||
| 444 | 13 | $event = new EventArgs( |
|
| 445 | array( |
||
| 446 | 3 | 'qb' => $qb, |
|
| 447 | 3 | 'searchData' => $searchData, |
|
| 448 | 3 | ), |
|
| 449 | $request |
||
| 450 | 3 | ); |
|
| 451 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event); |
|
| 452 | |||
| 453 | /** @var $Products \Eccube\Entity\Product[] */ |
||
| 454 | 3 | $Products = $qb->getQuery()->getResult(); |
|
| 455 | |||
| 456 | 11 | if (empty($Products)) { |
|
| 457 | 11 | $app['monolog']->addDebug('search product not found.'); |
|
| 458 | 11 | } |
|
| 459 | |||
| 460 | 3 | $forms = array(); |
|
| 461 | 3 | foreach ($Products as $Product) { |
|
| 462 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
| 463 | $builder = $app['form.factory']->createNamedBuilder('', 'add_cart', null, array( |
||
| 464 | 'product' => $Product, |
||
| 465 | )); |
||
| 466 | $addCartForm = $builder->getForm(); |
||
| 467 | $forms[$Product->getId()] = $addCartForm->createView(); |
||
| 468 | 3 | } |
|
| 469 | |||
| 470 | 3 | $event = new EventArgs( |
|
| 471 | array( |
||
| 472 | 3 | 'forms' => $forms, |
|
| 473 | 3 | 'Products' => $Products, |
|
| 474 | 3 | ), |
|
| 475 | 10 | $request |
|
| 476 | 13 | ); |
|
| 477 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event); |
|
| 478 | |||
| 479 | 3 | return $app->render('Order/search_product.twig', array( |
|
| 480 | 3 | 'forms' => $forms, |
|
| 481 | 3 | 'Products' => $Products, |
|
| 482 | 3 | )); |
|
| 483 | } |
||
| 484 | } |
||
| 485 | |||
| 486 | 6 | protected function newOrder() |
|
| 496 | |||
| 497 | /** |
||
| 498 | * フォームからの入直内容に基づいて、受注情報の再計算を行う |
||
| 499 | * |
||
| 500 | * @param $app |
||
| 501 | * @param $Order |
||
| 502 | */ |
||
| 503 | 11 | protected function calculate($app, \Eccube\Entity\Order $Order) |
|
| 575 | |||
| 576 | /** |
||
| 577 | * 受注ステータスに応じて, 受注日/入金日/発送日を更新する, |
||
| 578 | * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う. |
||
| 579 | * |
||
| 580 | * 編集の場合 |
||
| 581 | * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新 |
||
| 582 | * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新 |
||
| 583 | * |
||
| 584 | * 新規登録の場合 |
||
| 585 | * - 受注日を更新 |
||
| 586 | * - 受注ステータスが発送済に設定された場合に発送日を更新 |
||
| 587 | * - 受注ステータスが入金済に設定された場合に入金日を更新 |
||
| 588 | * |
||
| 589 | * |
||
| 590 | * @param $app |
||
| 591 | * @param $TargetOrder |
||
| 592 | * @param $OriginOrder |
||
| 593 | */ |
||
| 594 | 10 | protected function updateDate($app, $TargetOrder, $OriginOrder) |
|
| 636 | } |
||
| 637 |