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 ShoppingService 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 ShoppingService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 65 | class ShoppingService |
||
| 66 | { |
||
| 67 | /** |
||
| 68 | * @Inject(MailTemplateRepository::class) |
||
| 69 | * @var MailTemplateRepository |
||
| 70 | */ |
||
| 71 | protected $mailTemplateRepository; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @Inject(MailService::class) |
||
| 75 | * @var MailService |
||
| 76 | */ |
||
| 77 | protected $mailService; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @Inject("eccube.event.dispatcher") |
||
| 81 | * @var EventDispatcher |
||
| 82 | */ |
||
| 83 | protected $eventDispatcher; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @Inject("form.factory") |
||
| 87 | * @var FormFactory |
||
| 88 | */ |
||
| 89 | protected $formFactory; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @Inject(DeliveryFeeRepository::class) |
||
| 93 | * @var DeliveryFeeRepository |
||
| 94 | */ |
||
| 95 | protected $deliveryFeeRepository; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @Inject(TaxRuleRepository::class) |
||
| 99 | * @var TaxRuleRepository |
||
| 100 | */ |
||
| 101 | protected $taxRuleRepository; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @Inject(CustomerAddressRepository::class) |
||
| 105 | * @var CustomerAddressRepository |
||
| 106 | */ |
||
| 107 | protected $customerAddressRepository; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @Inject(DeliveryRepository::class) |
||
| 111 | * @var DeliveryRepository |
||
| 112 | */ |
||
| 113 | protected $deliveryRepository; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @Inject(OrderStatusRepository::class) |
||
| 117 | * @var OrderStatusRepository |
||
| 118 | */ |
||
| 119 | protected $orderStatusRepository; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @Inject(PaymentRepository::class) |
||
| 123 | * @var PaymentRepository |
||
| 124 | */ |
||
| 125 | protected $paymentRepository; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @Inject(DeviceTypeRepository::class) |
||
| 129 | * @var DeviceTypeRepository |
||
| 130 | */ |
||
| 131 | protected $deviceTypeRepository; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @Inject("orm.em") |
||
| 135 | * @var EntityManager |
||
| 136 | */ |
||
| 137 | protected $entityManager; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @Inject("config") |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | protected $appConfig; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @Inject(PrefRepository::class) |
||
| 147 | * @var PrefRepository |
||
| 148 | */ |
||
| 149 | protected $prefRepository; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @Inject("session") |
||
| 153 | * @var Session |
||
| 154 | */ |
||
| 155 | protected $session; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @Inject(OrderRepository::class) |
||
| 159 | * @var OrderRepository |
||
| 160 | */ |
||
| 161 | protected $orderRepository; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @Inject(BaseInfo::class) |
||
| 165 | * @var BaseInfo |
||
| 166 | */ |
||
| 167 | protected $BaseInfo; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @Inject(Application::class) |
||
| 171 | * @var \Eccube\Application |
||
| 172 | */ |
||
| 173 | public $app; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @Inject(CartService::class) |
||
| 177 | * @var \Eccube\Service\CartService |
||
| 178 | */ |
||
| 179 | protected $cartService; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @var \Eccube\Service\OrderService |
||
| 183 | * |
||
| 184 | * @deprecated |
||
| 185 | */ |
||
| 186 | protected $orderService; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * セッションにセットされた受注情報を取得 |
||
| 190 | * |
||
| 191 | * @param null $status |
||
| 192 | * @return null|object |
||
| 193 | */ |
||
| 194 | 11 | public function getOrder($status = null) |
|
| 195 | { |
||
| 196 | |||
| 197 | // 受注データを取得 |
||
| 198 | 11 | $preOrderId = $this->cartService->getPreOrderId(); |
|
| 199 | 11 | if (!$preOrderId) { |
|
| 200 | 11 | return null; |
|
| 201 | } |
||
| 202 | |||
| 203 | $condition = array( |
||
| 204 | 7 | 'pre_order_id' => $preOrderId, |
|
| 205 | ); |
||
| 206 | |||
| 207 | 7 | if (!is_null($status)) { |
|
| 208 | $condition += array( |
||
| 209 | 7 | 'OrderStatus' => $status, |
|
| 210 | ); |
||
| 211 | } |
||
| 212 | |||
| 213 | 7 | $Order = $this->orderRepository->findOneBy($condition); |
|
| 214 | |||
| 215 | 7 | return $Order; |
|
| 216 | |||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
|
|
|||
| 220 | * 非会員情報を取得 |
||
| 221 | * |
||
| 222 | * @param $sesisonKey |
||
| 223 | * @return $Customer|null |
||
| 224 | */ |
||
| 225 | 4 | public function getNonMember($sesisonKey) |
|
| 226 | { |
||
| 227 | |||
| 228 | // 非会員でも一度会員登録されていればショッピング画面へ遷移 |
||
| 229 | 4 | $nonMember = $this->session->get($sesisonKey); |
|
| 230 | 4 | if (is_null($nonMember)) { |
|
| 231 | 1 | return null; |
|
| 232 | } |
||
| 233 | 3 | if (!array_key_exists('customer', $nonMember) || !array_key_exists('pref', $nonMember)) { |
|
| 234 | return null; |
||
| 235 | } |
||
| 236 | |||
| 237 | 3 | $Customer = $nonMember['customer']; |
|
| 238 | 3 | $Customer->setPref($this->prefRepository->find($nonMember['pref'])); |
|
| 239 | |||
| 240 | 3 | foreach ($Customer->getCustomerAddresses() as $CustomerAddress) { |
|
| 241 | 3 | $Pref = $CustomerAddress->getPref(); |
|
| 242 | 3 | if ($Pref) { |
|
| 243 | 3 | $CustomerAddress->setPref($this->prefRepository->find($Pref->getId())); |
|
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | 3 | return $Customer; |
|
| 248 | |||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * 受注情報を作成 |
||
| 253 | * |
||
| 254 | * @param $Customer |
||
| 255 | * @return \Eccube\Entity\Order |
||
| 256 | */ |
||
| 257 | public function createOrder($Customer) |
||
| 258 | { |
||
| 259 | // ランダムなpre_order_idを作成 |
||
| 260 | View Code Duplication | do { |
|
| 261 | $preOrderId = sha1(Str::random(32)); |
||
| 262 | $Order = $this->orderRepository->findOneBy(array( |
||
| 263 | 'pre_order_id' => $preOrderId, |
||
| 264 | 'OrderStatus' => $this->appConfig['order_processing'], |
||
| 265 | )); |
||
| 266 | } while ($Order); |
||
| 267 | |||
| 268 | // 受注情報、受注明細情報、お届け先情報、配送商品情報を作成 |
||
| 269 | $Order = $this->registerPreOrder( |
||
| 270 | $Customer, |
||
| 271 | $preOrderId); |
||
| 272 | |||
| 273 | $this->cartService->setPreOrderId($preOrderId); |
||
| 274 | $this->cartService->save(); |
||
| 275 | |||
| 276 | return $Order; |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * 仮受注情報作成 |
||
| 281 | * |
||
| 282 | * @param $Customer |
||
| 283 | * @param $preOrderId |
||
| 284 | * @return mixed |
||
| 285 | * @throws \Doctrine\ORM\NoResultException |
||
| 286 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 287 | */ |
||
| 288 | public function registerPreOrder(Customer $Customer, $preOrderId) |
||
| 289 | { |
||
| 290 | |||
| 291 | $this->em = $this->entityManager; |
||
| 292 | |||
| 293 | // 受注情報を作成 |
||
| 294 | $Order = $this->getNewOrder($Customer); |
||
| 295 | $Order->setPreOrderId($preOrderId); |
||
| 296 | |||
| 297 | $DeviceType = $this->deviceTypeRepository->find($this->app['mobile_detect.device_type']); |
||
| 298 | $Order->setDeviceType($DeviceType); |
||
| 299 | |||
| 300 | $this->entityManager->persist($Order); |
||
| 301 | |||
| 302 | // 配送業者情報を取得 |
||
| 303 | $deliveries = $this->getDeliveriesCart(); |
||
| 304 | |||
| 305 | // お届け先情報を作成 |
||
| 306 | $Order = $this->getNewShipping($Order, $Customer, $deliveries); |
||
| 307 | |||
| 308 | // 受注明細情報、配送商品情報を作成 |
||
| 309 | $Order = $this->getNewDetails($Order); |
||
| 310 | |||
| 311 | // 小計 |
||
| 312 | $subTotal = $this->orderService->getSubTotal($Order); |
||
| 313 | |||
| 314 | // 消費税のみの小計 |
||
| 315 | $tax = $this->orderService->getTotalTax($Order); |
||
| 316 | |||
| 317 | // 配送料合計金額 |
||
| 318 | // TODO CalculateDeliveryFeeStrategy でセットする |
||
| 319 | // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($Order->getShippings())); |
||
| 320 | |||
| 321 | // 小計 |
||
| 322 | $Order->setSubTotal($subTotal); |
||
| 323 | |||
| 324 | // 配送料無料条件(合計金額) |
||
| 325 | $this->setDeliveryFreeAmount($Order); |
||
| 326 | |||
| 327 | // 配送料無料条件(合計数量) |
||
| 328 | $this->setDeliveryFreeQuantity($Order); |
||
| 329 | |||
| 330 | // 初期選択の支払い方法をセット |
||
| 331 | $payments = $this->paymentRepository->findAllowedPayments($deliveries); |
||
| 332 | $payments = $this->getPayments($payments, $subTotal); |
||
| 333 | |||
| 334 | if (count($payments) > 0) { |
||
| 335 | $payment = $payments[0]; |
||
| 336 | $Order->setPayment($payment); |
||
| 337 | $Order->setPaymentMethod($payment->getMethod()); |
||
| 338 | $Order->setCharge($payment->getCharge()); |
||
| 339 | } else { |
||
| 340 | $Order->setCharge(0); |
||
| 341 | } |
||
| 342 | |||
| 343 | $Order->setTax($tax); |
||
| 344 | |||
| 345 | // 合計金額の計算 |
||
| 346 | $this->calculatePrice($Order); |
||
| 347 | |||
| 348 | $this->entityManager->flush(); |
||
| 349 | |||
| 350 | return $Order; |
||
| 351 | |||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * 受注情報を作成 |
||
| 356 | * |
||
| 357 | * @param $Customer |
||
| 358 | * @return \Eccube\Entity\Order |
||
| 359 | */ |
||
| 360 | public function getNewOrder(Customer $Customer) |
||
| 361 | { |
||
| 362 | $Order = $this->newOrder(); |
||
| 363 | $this->copyToOrderFromCustomer($Order, $Customer); |
||
| 364 | |||
| 365 | return $Order; |
||
| 366 | } |
||
| 367 | |||
| 368 | |||
| 369 | /** |
||
| 370 | * 受注情報を作成 |
||
| 371 | * |
||
| 372 | * @return \Eccube\Entity\Order |
||
| 373 | */ |
||
| 374 | public function newOrder() |
||
| 375 | { |
||
| 376 | $OrderStatus = $this->orderStatusRepository->find($this->appConfig['order_processing']); |
||
| 377 | $Order = new \Eccube\Entity\Order($OrderStatus); |
||
| 378 | |||
| 379 | return $Order; |
||
| 380 | } |
||
| 381 | |||
| 382 | /** |
||
| 383 | * 受注情報を作成 |
||
| 384 | * |
||
| 385 | * @param \Eccube\Entity\Order $Order |
||
| 386 | * @param \Eccube\Entity\Customer|null $Customer |
||
| 387 | * @return \Eccube\Entity\Order |
||
| 388 | */ |
||
| 389 | public function copyToOrderFromCustomer(Order $Order, Customer $Customer = null) |
||
| 390 | { |
||
| 391 | if (is_null($Customer)) { |
||
| 392 | return $Order; |
||
| 393 | } |
||
| 394 | |||
| 395 | if ($Customer->getId()) { |
||
| 396 | $Order->setCustomer($Customer); |
||
| 397 | } |
||
| 398 | $Order |
||
| 399 | ->setName01($Customer->getName01()) |
||
| 400 | ->setName02($Customer->getName02()) |
||
| 401 | ->setKana01($Customer->getKana01()) |
||
| 402 | ->setKana02($Customer->getKana02()) |
||
| 403 | ->setCompanyName($Customer->getCompanyName()) |
||
| 404 | ->setEmail($Customer->getEmail()) |
||
| 405 | ->setTel01($Customer->getTel01()) |
||
| 406 | ->setTel02($Customer->getTel02()) |
||
| 407 | ->setTel03($Customer->getTel03()) |
||
| 408 | ->setFax01($Customer->getFax01()) |
||
| 409 | ->setFax02($Customer->getFax02()) |
||
| 410 | ->setFax03($Customer->getFax03()) |
||
| 411 | ->setZip01($Customer->getZip01()) |
||
| 412 | ->setZip02($Customer->getZip02()) |
||
| 413 | ->setZipCode($Customer->getZip01().$Customer->getZip02()) |
||
| 414 | ->setPref($Customer->getPref()) |
||
| 415 | ->setAddr01($Customer->getAddr01()) |
||
| 416 | ->setAddr02($Customer->getAddr02()) |
||
| 417 | ->setSex($Customer->getSex()) |
||
| 418 | ->setBirth($Customer->getBirth()) |
||
| 419 | ->setJob($Customer->getJob()); |
||
| 420 | |||
| 421 | return $Order; |
||
| 422 | } |
||
| 423 | |||
| 424 | |||
| 425 | /** |
||
| 426 | * 配送業者情報を取得 |
||
| 427 | * |
||
| 428 | * @return array |
||
| 429 | */ |
||
| 430 | public function getDeliveriesCart() |
||
| 431 | { |
||
| 432 | |||
| 433 | // カートに保持されている商品種別を取得 |
||
| 434 | $productTypes = $this->cartService->getProductTypes(); |
||
| 435 | |||
| 436 | return $this->getDeliveries($productTypes); |
||
| 437 | |||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * 配送業者情報を取得 |
||
| 442 | * |
||
| 443 | * @param Order $Order |
||
| 444 | * @return array |
||
| 445 | */ |
||
| 446 | public function getDeliveriesOrder(Order $Order) |
||
| 447 | { |
||
| 448 | |||
| 449 | // 受注情報から商品種別を取得 |
||
| 450 | $productTypes = $this->orderService->getProductTypes($Order); |
||
| 451 | |||
| 452 | return $this->getDeliveries($productTypes); |
||
| 453 | |||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * 配送業者情報を取得 |
||
| 458 | * |
||
| 459 | * @param $productTypes |
||
| 460 | * @return array |
||
| 461 | */ |
||
| 462 | 3 | public function getDeliveries($productTypes) |
|
| 463 | { |
||
| 464 | |||
| 465 | // 商品種別に紐づく配送業者を取得 |
||
| 466 | 3 | $deliveries = $this->deliveryRepository->getDeliveries($productTypes); |
|
| 467 | |||
| 468 | 3 | if ($this->BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { |
|
| 469 | // 複数配送対応 |
||
| 470 | |||
| 471 | // 支払方法を取得 |
||
| 472 | 1 | $payments = $this->paymentRepository->findAllowedPayments($deliveries); |
|
| 473 | |||
| 474 | 1 | if (count($productTypes) > 1) { |
|
| 475 | // 商品種別が複数ある場合、配送対象となる配送業者を取得 |
||
| 476 | 1 | $deliveries = $this->deliveryRepository->findAllowedDeliveries($productTypes, $payments); |
|
| 477 | } |
||
| 478 | |||
| 479 | } |
||
| 480 | |||
| 481 | 3 | return $deliveries; |
|
| 482 | |||
| 483 | } |
||
| 484 | |||
| 485 | |||
| 486 | /** |
||
| 487 | * お届け先情報を作成 |
||
| 488 | * |
||
| 489 | * @param Order $Order |
||
| 490 | * @param Customer $Customer |
||
| 491 | * @param $deliveries |
||
| 492 | * @return Order |
||
| 493 | */ |
||
| 494 | public function getNewShipping(Order $Order, Customer $Customer, $deliveries) |
||
| 495 | { |
||
| 496 | $productTypes = array(); |
||
| 497 | foreach ($deliveries as $Delivery) { |
||
| 498 | if (!in_array($Delivery->getProductType()->getId(), $productTypes)) { |
||
| 499 | $Shipping = new Shipping(); |
||
| 500 | |||
| 501 | $this->copyToShippingFromCustomer($Shipping, $Customer) |
||
| 502 | ->setOrder($Order) |
||
| 503 | ->setDelFlg(Constant::DISABLED); |
||
| 504 | |||
| 505 | // 配送料金の設定 |
||
| 506 | $this->setShippingDeliveryFee($Shipping, $Delivery); |
||
| 507 | |||
| 508 | $this->entityManager->persist($Shipping); |
||
| 509 | |||
| 510 | $Order->addShipping($Shipping); |
||
| 511 | |||
| 512 | $productTypes[] = $Delivery->getProductType()->getId(); |
||
| 513 | } |
||
| 514 | } |
||
| 515 | |||
| 516 | return $Order; |
||
| 517 | } |
||
| 518 | |||
| 519 | /** |
||
| 520 | * お届け先情報を作成 |
||
| 521 | * |
||
| 522 | * @param \Eccube\Entity\Shipping $Shipping |
||
| 523 | * @param \Eccube\Entity\Customer|null $Customer |
||
| 524 | * @return \Eccube\Entity\Shipping |
||
| 525 | */ |
||
| 526 | 1 | public function copyToShippingFromCustomer(Shipping $Shipping, Customer $Customer = null) |
|
| 527 | { |
||
| 528 | 1 | if (is_null($Customer)) { |
|
| 529 | 1 | return $Shipping; |
|
| 530 | } |
||
| 531 | |||
| 532 | $CustomerAddress = $this->customerAddressRepository->findOneBy( |
||
| 533 | array('Customer' => $Customer), |
||
| 534 | array('id' => 'ASC') |
||
| 535 | ); |
||
| 536 | |||
| 537 | if (!is_null($CustomerAddress)) { |
||
| 538 | $Shipping |
||
| 539 | ->setName01($CustomerAddress->getName01()) |
||
| 540 | ->setName02($CustomerAddress->getName02()) |
||
| 541 | ->setKana01($CustomerAddress->getKana01()) |
||
| 542 | ->setKana02($CustomerAddress->getKana02()) |
||
| 543 | ->setCompanyName($CustomerAddress->getCompanyName()) |
||
| 544 | ->setTel01($CustomerAddress->getTel01()) |
||
| 545 | ->setTel02($CustomerAddress->getTel02()) |
||
| 546 | ->setTel03($CustomerAddress->getTel03()) |
||
| 547 | ->setFax01($CustomerAddress->getFax01()) |
||
| 548 | ->setFax02($CustomerAddress->getFax02()) |
||
| 549 | ->setFax03($CustomerAddress->getFax03()) |
||
| 550 | ->setZip01($CustomerAddress->getZip01()) |
||
| 551 | ->setZip02($CustomerAddress->getZip02()) |
||
| 552 | ->setZipCode($CustomerAddress->getZip01().$CustomerAddress->getZip02()) |
||
| 553 | ->setPref($CustomerAddress->getPref()) |
||
| 554 | ->setAddr01($CustomerAddress->getAddr01()) |
||
| 555 | ->setAddr02($CustomerAddress->getAddr02()); |
||
| 556 | } else { |
||
| 557 | $Shipping |
||
| 558 | ->setName01($Customer->getName01()) |
||
| 559 | ->setName02($Customer->getName02()) |
||
| 560 | ->setKana01($Customer->getKana01()) |
||
| 561 | ->setKana02($Customer->getKana02()) |
||
| 562 | ->setCompanyName($Customer->getCompanyName()) |
||
| 563 | ->setTel01($Customer->getTel01()) |
||
| 564 | ->setTel02($Customer->getTel02()) |
||
| 565 | ->setTel03($Customer->getTel03()) |
||
| 566 | ->setFax01($Customer->getFax01()) |
||
| 567 | ->setFax02($Customer->getFax02()) |
||
| 568 | ->setFax03($Customer->getFax03()) |
||
| 569 | ->setZip01($Customer->getZip01()) |
||
| 570 | ->setZip02($Customer->getZip02()) |
||
| 571 | ->setZipCode($Customer->getZip01().$Customer->getZip02()) |
||
| 572 | ->setPref($Customer->getPref()) |
||
| 573 | ->setAddr01($Customer->getAddr01()) |
||
| 574 | ->setAddr02($Customer->getAddr02()); |
||
| 575 | } |
||
| 576 | |||
| 577 | return $Shipping; |
||
| 578 | } |
||
| 579 | |||
| 580 | |||
| 581 | /** |
||
| 582 | * 受注明細情報、配送商品情報を作成 |
||
| 583 | * |
||
| 584 | * @param Order $Order |
||
| 585 | * @return Order |
||
| 586 | */ |
||
| 587 | public function getNewDetails(Order $Order) |
||
| 588 | { |
||
| 589 | |||
| 590 | // 受注詳細, 配送商品 |
||
| 591 | foreach ($this->cartService->getCart()->getCartItems() as $item) { |
||
| 592 | /* @var $ProductClass \Eccube\Entity\ProductClass */ |
||
| 593 | $ProductClass = $item->getObject(); |
||
| 594 | /* @var $Product \Eccube\Entity\Product */ |
||
| 595 | $Product = $ProductClass->getProduct(); |
||
| 596 | |||
| 597 | $quantity = $item->getQuantity(); |
||
| 598 | |||
| 599 | // 配送商品情報を作成 |
||
| 600 | $this->getNewOrderItem($Order, $Product, $ProductClass, $quantity); |
||
| 601 | } |
||
| 602 | |||
| 603 | return $Order; |
||
| 604 | |||
| 605 | } |
||
| 606 | |||
| 607 | /** |
||
| 608 | * 配送商品情報を作成 |
||
| 609 | * |
||
| 610 | * @param Order $Order |
||
| 611 | * @param Product $Product |
||
| 612 | * @param ProductClass $ProductClass |
||
| 613 | * @param $quantity |
||
| 614 | * @return \Eccube\Entity\OrderItem |
||
| 615 | */ |
||
| 616 | public function getNewOrderItem(Order $Order, Product $Product, ProductClass $ProductClass, $quantity) |
||
| 617 | { |
||
| 618 | |||
| 619 | $OrderItem = new OrderItem(); |
||
| 620 | $shippings = $Order->getShippings(); |
||
| 621 | |||
| 622 | // 選択された商品がどのお届け先情報と関連するかチェック |
||
| 623 | $Shipping = null; |
||
| 624 | foreach ($shippings as $s) { |
||
| 625 | if ($s->getDelivery()->getProductType()->getId() == $ProductClass->getProductType()->getId()) { |
||
| 626 | // 商品種別が同一のお届け先情報と関連させる |
||
| 627 | $Shipping = $s; |
||
| 628 | break; |
||
| 629 | } |
||
| 630 | } |
||
| 631 | |||
| 632 | if (is_null($Shipping)) { |
||
| 633 | // お届け先情報と関連していない場合、エラー |
||
| 634 | throw new CartException('shopping.delivery.not.producttype'); |
||
| 635 | } |
||
| 636 | |||
| 637 | // 商品ごとの配送料合計 |
||
| 638 | $productDeliveryFeeTotal = 0; |
||
| 639 | if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) { |
||
| 640 | $productDeliveryFeeTotal = $ProductClass->getDeliveryFee() * $quantity; |
||
| 641 | } |
||
| 642 | |||
| 643 | $Shipping->setShippingDeliveryFee($Shipping->getShippingDeliveryFee() + $productDeliveryFeeTotal); |
||
| 644 | |||
| 645 | $OrderItem->setShipping($Shipping) |
||
| 646 | ->setOrder($Order) |
||
| 647 | ->setProductClass($ProductClass) |
||
| 648 | ->setProduct($Product) |
||
| 649 | ->setProductName($Product->getName()) |
||
| 650 | ->setProductCode($ProductClass->getCode()) |
||
| 651 | ->setPrice($ProductClass->getPrice02()) |
||
| 652 | ->setQuantity($quantity); |
||
| 653 | |||
| 654 | $ClassCategory1 = $ProductClass->getClassCategory1(); |
||
| 655 | if (!is_null($ClassCategory1)) { |
||
| 656 | $OrderItem->setClasscategoryName1($ClassCategory1->getName()); |
||
| 657 | $OrderItem->setClassName1($ClassCategory1->getClassName()->getName()); |
||
| 658 | } |
||
| 659 | $ClassCategory2 = $ProductClass->getClassCategory2(); |
||
| 660 | if (!is_null($ClassCategory2)) { |
||
| 661 | $OrderItem->setClasscategoryName2($ClassCategory2->getName()); |
||
| 662 | $OrderItem->setClassName2($ClassCategory2->getClassName()->getName()); |
||
| 663 | } |
||
| 664 | $Shipping->addOrderItem($OrderItem); |
||
| 665 | $this->entityManager->persist($OrderItem); |
||
| 666 | |||
| 667 | return $OrderItem; |
||
| 668 | |||
| 669 | } |
||
| 670 | |||
| 671 | /** |
||
| 672 | * お届け先ごとの送料合計を取得 |
||
| 673 | * |
||
| 674 | * @param $shippings |
||
| 675 | * @return int |
||
| 676 | */ |
||
| 677 | public function getShippingDeliveryFeeTotal($shippings) |
||
| 678 | { |
||
| 679 | $deliveryFeeTotal = 0; |
||
| 680 | foreach ($shippings as $Shipping) { |
||
| 681 | $deliveryFeeTotal += $Shipping->getShippingDeliveryFee(); |
||
| 682 | } |
||
| 683 | |||
| 684 | return $deliveryFeeTotal; |
||
| 685 | |||
| 686 | } |
||
| 687 | |||
| 688 | /** |
||
| 689 | * 商品ごとの配送料を取得 |
||
| 690 | * |
||
| 691 | * @param Shipping $Shipping |
||
| 692 | * @return int |
||
| 693 | */ |
||
| 694 | public function getProductDeliveryFee(Shipping $Shipping) |
||
| 695 | { |
||
| 696 | $productDeliveryFeeTotal = 0; |
||
| 697 | $OrderItems = $Shipping->getOrderItems(); |
||
| 698 | foreach ($OrderItems as $OrderItem) { |
||
| 699 | $productDeliveryFeeTotal += $OrderItem->getProductClass()->getDeliveryFee() * $OrderItem->getQuantity(); |
||
| 700 | } |
||
| 701 | |||
| 702 | return $productDeliveryFeeTotal; |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * 住所などの情報が変更された時に金額の再計算を行う |
||
| 707 | * @deprecated PurchaseFlowで行う |
||
| 708 | * @param Order $Order |
||
| 709 | * @return Order |
||
| 710 | */ |
||
| 711 | 1 | public function getAmount(Order $Order) |
|
| 712 | { |
||
| 713 | |||
| 714 | // 初期選択の配送業者をセット |
||
| 715 | 1 | $shippings = $Order->getShippings(); |
|
| 716 | |||
| 717 | // 配送料合計金額 |
||
| 718 | // TODO CalculateDeliveryFeeStrategy でセットする |
||
| 719 | // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings)); |
||
| 720 | |||
| 721 | // 配送料無料条件(合計金額) |
||
| 722 | 1 | $this->setDeliveryFreeAmount($Order); |
|
| 723 | |||
| 724 | // 配送料無料条件(合計数量) |
||
| 725 | 1 | $this->setDeliveryFreeQuantity($Order); |
|
| 726 | |||
| 727 | // 合計金額の計算 |
||
| 728 | 1 | $this->calculatePrice($Order); |
|
| 729 | |||
| 730 | 1 | return $Order; |
|
| 731 | |||
| 732 | } |
||
| 733 | |||
| 734 | /** |
||
| 735 | * 配送料金の設定 |
||
| 736 | * |
||
| 737 | * @param Shipping $Shipping |
||
| 738 | * @param Delivery|null $Delivery |
||
| 739 | */ |
||
| 740 | public function setShippingDeliveryFee(Shipping $Shipping, Delivery $Delivery = null) |
||
| 741 | { |
||
| 742 | // 配送料金の設定 |
||
| 743 | if (is_null($Delivery)) { |
||
| 744 | $Delivery = $Shipping->getDelivery(); |
||
| 745 | } |
||
| 746 | $deliveryFee = $this->deliveryFeeRepository->findOneBy(array('Delivery' => $Delivery, 'Pref' => $Shipping->getPref())); |
||
| 747 | if ($deliveryFee) { |
||
| 748 | $Shipping->setDeliveryFee($deliveryFee); |
||
| 749 | $Shipping->setFeeId($deliveryFee->getId()); |
||
| 750 | } |
||
| 751 | $Shipping->setDelivery($Delivery); |
||
| 752 | |||
| 753 | // 商品ごとの配送料合計 |
||
| 754 | $productDeliveryFeeTotal = 0; |
||
| 755 | if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) { |
||
| 756 | $productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping); |
||
| 757 | } |
||
| 758 | |||
| 759 | $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal); |
||
| 760 | $Shipping->setShippingDeliveryName($Delivery->getName()); |
||
| 761 | } |
||
| 762 | |||
| 763 | /** |
||
| 764 | * 配送料無料条件(合計金額)の条件を満たしていれば配送料金を0に設定 |
||
| 765 | * |
||
| 766 | * @param Order $Order |
||
| 767 | */ |
||
| 768 | 4 | View Code Duplication | public function setDeliveryFreeAmount(Order $Order) |
| 769 | { |
||
| 770 | // 配送料無料条件(合計金額) |
||
| 771 | 4 | $deliveryFreeAmount = $this->BaseInfo->getDeliveryFreeAmount(); |
|
| 772 | 4 | if (!is_null($deliveryFreeAmount)) { |
|
| 773 | // 合計金額が設定金額以上であれば送料無料 |
||
| 774 | 1 | if ($Order->getSubTotal() >= $deliveryFreeAmount) { |
|
| 775 | 1 | $Order->setDeliveryFeeTotal(0); |
|
| 776 | // お届け先情報の配送料も0にセット |
||
| 777 | 1 | $shippings = $Order->getShippings(); |
|
| 778 | 1 | foreach ($shippings as $Shipping) { |
|
| 779 | 1 | $Shipping->setShippingDeliveryFee(0); |
|
| 780 | } |
||
| 781 | } |
||
| 782 | } |
||
| 783 | } |
||
| 784 | |||
| 785 | /** |
||
| 786 | * 配送料無料条件(合計数量)の条件を満たしていれば配送料金を0に設定 |
||
| 787 | * |
||
| 788 | * @param Order $Order |
||
| 789 | */ |
||
| 790 | 3 | View Code Duplication | public function setDeliveryFreeQuantity(Order $Order) |
| 791 | { |
||
| 792 | // 配送料無料条件(合計数量) |
||
| 793 | 3 | $deliveryFreeQuantity = $this->BaseInfo->getDeliveryFreeQuantity(); |
|
| 794 | 3 | if (!is_null($deliveryFreeQuantity)) { |
|
| 795 | // 合計数量が設定数量以上であれば送料無料 |
||
| 796 | if ($this->orderService->getTotalQuantity($Order) >= $deliveryFreeQuantity) { |
||
| 797 | $Order->setDeliveryFeeTotal(0); |
||
| 798 | // お届け先情報の配送料も0にセット |
||
| 799 | $shippings = $Order->getShippings(); |
||
| 800 | foreach ($shippings as $Shipping) { |
||
| 801 | $Shipping->setShippingDeliveryFee(0); |
||
| 802 | } |
||
| 803 | } |
||
| 804 | } |
||
| 805 | } |
||
| 806 | |||
| 807 | /** |
||
| 808 | * 受注情報、お届け先情報の更新 |
||
| 809 | * |
||
| 810 | * @param Order $Order 受注情報 |
||
| 811 | * @param $data フォームデータ |
||
| 812 | * |
||
| 813 | * @deprecated since 3.0.5, to be removed in 3.1 |
||
| 814 | */ |
||
| 815 | public function setOrderUpdate(Order $Order, $data) |
||
| 816 | { |
||
| 817 | // 受注情報を更新 |
||
| 818 | $Order->setOrderDate(new \DateTime()); |
||
| 819 | $Order->setOrderStatus($this->orderStatusRepository->find($this->appConfig['order_new'])); |
||
| 820 | $Order->setMessage($data['message']); |
||
| 821 | // お届け先情報を更新 |
||
| 822 | $shippings = $data['shippings']; |
||
| 823 | foreach ($shippings as $Shipping) { |
||
| 824 | $Delivery = $Shipping->getDelivery(); |
||
| 825 | $deliveryFee = $this->deliveryFeeRepository->findOneBy(array( |
||
| 826 | 'Delivery' => $Delivery, |
||
| 827 | 'Pref' => $Shipping->getPref() |
||
| 828 | )); |
||
| 829 | $deliveryTime = $Shipping->getDeliveryTime(); |
||
| 830 | if (!empty($deliveryTime)) { |
||
| 831 | $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime()); |
||
| 832 | $Shipping->setTimeId($deliveryTime->getId()); |
||
| 833 | } |
||
| 834 | $Shipping->setDeliveryFee($deliveryFee); |
||
| 835 | // 商品ごとの配送料合計 |
||
| 836 | $productDeliveryFeeTotal = 0; |
||
| 837 | if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) { |
||
| 838 | $productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping); |
||
| 839 | } |
||
| 840 | $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal); |
||
| 841 | $Shipping->setShippingDeliveryName($Delivery->getName()); |
||
| 842 | } |
||
| 843 | // 配送料無料条件(合計金額) |
||
| 844 | $this->setDeliveryFreeAmount($Order); |
||
| 845 | // 配送料無料条件(合計数量) |
||
| 846 | $this->setDeliveryFreeQuantity($Order); |
||
| 847 | } |
||
| 848 | |||
| 849 | |||
| 850 | /** |
||
| 851 | * 受注情報の更新 |
||
| 852 | * |
||
| 853 | * @param Order $Order 受注情報 |
||
| 854 | */ |
||
| 855 | 3 | public function setOrderUpdateData(Order $Order) |
|
| 856 | { |
||
| 857 | // 受注情報を更新 |
||
| 858 | 3 | $Order->setOrderDate(new \DateTime()); // XXX 後続の setOrderStatus でも時刻を更新している |
|
| 859 | 3 | $OrderStatus = $this->orderStatusRepository->find($this->appConfig['order_new']); |
|
| 860 | 3 | $this->setOrderStatus($Order, $OrderStatus); |
|
| 861 | |||
| 862 | } |
||
| 863 | |||
| 864 | |||
| 865 | /** |
||
| 866 | * 会員情報の更新 |
||
| 867 | * |
||
| 868 | * @param Order $Order 受注情報 |
||
| 869 | * @param Customer $user ログインユーザ |
||
| 870 | */ |
||
| 871 | 2 | public function setCustomerUpdate(Order $Order, Customer $user) |
|
| 872 | { |
||
| 873 | // 顧客情報を更新 |
||
| 874 | 2 | $now = new \DateTime(); |
|
| 875 | 2 | $firstBuyDate = $user->getFirstBuyDate(); |
|
| 876 | 2 | if (empty($firstBuyDate)) { |
|
| 877 | 2 | $user->setFirstBuyDate($now); |
|
| 878 | } |
||
| 879 | 2 | $user->setLastBuyDate($now); |
|
| 880 | |||
| 881 | 2 | $user->setBuyTimes($user->getBuyTimes() + 1); |
|
| 882 | 2 | $user->setBuyTotal($user->getBuyTotal() + $Order->getTotal()); |
|
| 883 | } |
||
| 884 | |||
| 885 | |||
| 886 | /** |
||
| 887 | * 支払方法選択の表示設定 |
||
| 888 | * |
||
| 889 | * @param $payments 支払選択肢情報 |
||
| 890 | * @param $subTotal 小計 |
||
| 891 | * @return array |
||
| 892 | */ |
||
| 893 | 1 | public function getPayments($payments, $subTotal) |
|
| 894 | { |
||
| 895 | 1 | $pays = array(); |
|
| 896 | 1 | foreach ($payments as $payment) { |
|
| 897 | // 支払方法の制限値内であれば表示 |
||
| 898 | 1 | if (!is_null($payment)) { |
|
| 899 | 1 | $pay = $this->paymentRepository->find($payment['id']); |
|
| 900 | 1 | if (intval($pay->getRuleMin()) <= $subTotal) { |
|
| 901 | 1 | if (is_null($pay->getRuleMax()) || $pay->getRuleMax() >= $subTotal) { |
|
| 902 | 1 | $pays[] = $pay; |
|
| 903 | } |
||
| 904 | } |
||
| 905 | } |
||
| 906 | } |
||
| 907 | |||
| 908 | 1 | return $pays; |
|
| 909 | |||
| 910 | } |
||
| 911 | |||
| 912 | /** |
||
| 913 | * お届け日を取得 |
||
| 914 | * |
||
| 915 | * @param Order $Order |
||
| 916 | * @return array |
||
| 917 | */ |
||
| 918 | 2 | public function getFormDeliveryDates(Order $Order) |
|
| 919 | { |
||
| 920 | |||
| 921 | // お届け日の設定 |
||
| 922 | 2 | $minDate = 0; |
|
| 923 | 2 | $deliveryDateFlag = false; |
|
| 924 | |||
| 925 | // 配送時に最大となる商品日数を取得 |
||
| 926 | 2 | View Code Duplication | foreach ($Order->getOrderItems() as $item) { |
| 927 | 2 | if (!$item->isProduct()) { |
|
| 928 | 1 | continue; |
|
| 929 | } |
||
| 930 | 2 | $ProductClass = $item->getProductClass(); |
|
| 931 | 2 | $deliveryDate = $ProductClass->getDeliveryDate(); |
|
| 932 | 2 | if (!is_null($deliveryDate)) { |
|
| 933 | 2 | if ($deliveryDate->getValue() < 0) { |
|
| 934 | // 配送日数がマイナスの場合はお取り寄せなのでスキップする |
||
| 935 | 1 | $deliveryDateFlag = false; |
|
| 936 | 1 | break; |
|
| 937 | } |
||
| 938 | |||
| 939 | 1 | if ($minDate < $deliveryDate->getValue()) { |
|
| 940 | $minDate = $deliveryDate->getValue(); |
||
| 941 | } |
||
| 942 | // 配送日数が設定されている |
||
| 943 | 1 | $deliveryDateFlag = true; |
|
| 944 | } |
||
| 945 | } |
||
| 946 | |||
| 947 | // 配達最大日数期間を設定 |
||
| 948 | 2 | $deliveryDates = array(); |
|
| 949 | |||
| 950 | // 配送日数が設定されている |
||
| 951 | 2 | View Code Duplication | if ($deliveryDateFlag) { |
| 952 | 1 | $period = new \DatePeriod ( |
|
| 953 | 1 | new \DateTime($minDate.' day'), |
|
| 954 | 1 | new \DateInterval('P1D'), |
|
| 955 | 1 | new \DateTime($minDate + $this->appConfig['deliv_date_end_max'].' day') |
|
| 956 | ); |
||
| 957 | |||
| 958 | 1 | foreach ($period as $day) { |
|
| 959 | 1 | $deliveryDates[$day->format('Y/m/d')] = $day->format('Y/m/d'); |
|
| 960 | } |
||
| 961 | } |
||
| 962 | |||
| 963 | 2 | return $deliveryDates; |
|
| 964 | } |
||
| 965 | |||
| 966 | /** |
||
| 967 | * 支払方法を取得 |
||
| 968 | * |
||
| 969 | * @param $deliveries |
||
| 970 | * @param Order $Order |
||
| 971 | * @return array |
||
| 972 | */ |
||
| 973 | public function getFormPayments($deliveries, Order $Order) |
||
| 974 | { |
||
| 975 | |||
| 976 | $productTypes = $this->orderService->getProductTypes($Order); |
||
| 977 | if ($this->BaseInfo->getOptionMultipleShipping() == Constant::ENABLED && count($productTypes) > 1) { |
||
| 978 | // 複数配送時の支払方法 |
||
| 979 | |||
| 980 | $payments = $this->paymentRepository->findAllowedPayments($deliveries); |
||
| 981 | } else { |
||
| 982 | |||
| 983 | // 配送業者をセット |
||
| 984 | $shippings = $Order->getShippings(); |
||
| 985 | $Shipping = $shippings[0]; |
||
| 986 | $payments = $this->paymentRepository->findPayments($Shipping->getDelivery(), true); |
||
| 987 | |||
| 988 | } |
||
| 989 | $payments = $this->getPayments($payments, $Order->getSubTotal()); |
||
| 990 | |||
| 991 | return $payments; |
||
| 992 | |||
| 993 | } |
||
| 994 | |||
| 995 | /** |
||
| 996 | * お届け先ごとにFormを作成 |
||
| 997 | * |
||
| 998 | * @param Order $Order |
||
| 999 | * @return \Symfony\Component\Form\Form |
||
| 1000 | * @deprecated since 3.0, to be removed in 3.1 |
||
| 1001 | */ |
||
| 1002 | View Code Duplication | public function getShippingForm(Order $Order) |
|
| 1003 | { |
||
| 1004 | $message = $Order->getMessage(); |
||
| 1005 | |||
| 1006 | $deliveries = $this->getDeliveriesOrder($Order); |
||
| 1007 | |||
| 1008 | // 配送業者の支払方法を取得 |
||
| 1009 | $payments = $this->getFormPayments($deliveries, $Order); |
||
| 1010 | |||
| 1011 | $builder = $this->formFactory->createBuilder('shopping', null, array( |
||
| 1012 | 'payments' => $payments, |
||
| 1013 | 'payment' => $Order->getPayment(), |
||
| 1014 | 'message' => $message, |
||
| 1015 | )); |
||
| 1016 | |||
| 1017 | $builder |
||
| 1018 | ->add('shippings', CollectionType::class, array( |
||
| 1019 | 'entry_type' => ShippingItemType::class, |
||
| 1020 | 'data' => $Order->getShippings(), |
||
| 1021 | )); |
||
| 1022 | |||
| 1023 | $form = $builder->getForm(); |
||
| 1024 | |||
| 1025 | return $form; |
||
| 1026 | |||
| 1027 | } |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * お届け先ごとにFormBuilderを作成 |
||
| 1031 | * |
||
| 1032 | * @param Order $Order |
||
| 1033 | * @return \Symfony\Component\Form\FormBuilderInterface |
||
| 1034 | * |
||
| 1035 | * @deprecated 利用している箇所なし |
||
| 1036 | */ |
||
| 1037 | View Code Duplication | public function getShippingFormBuilder(Order $Order) |
|
| 1038 | { |
||
| 1039 | $message = $Order->getMessage(); |
||
| 1040 | |||
| 1041 | $deliveries = $this->getDeliveriesOrder($Order); |
||
| 1042 | |||
| 1043 | // 配送業者の支払方法を取得 |
||
| 1044 | $payments = $this->getFormPayments($deliveries, $Order); |
||
| 1045 | |||
| 1046 | $builder = $this->formFactory->createBuilder('shopping', null, array( |
||
| 1047 | 'payments' => $payments, |
||
| 1048 | 'payment' => $Order->getPayment(), |
||
| 1049 | 'message' => $message, |
||
| 1050 | )); |
||
| 1051 | |||
| 1052 | $builder |
||
| 1053 | ->add('shippings', CollectionType::class, array( |
||
| 1054 | 'entry_type' => ShippingItemType::class, |
||
| 1055 | 'data' => $Order->getShippings(), |
||
| 1056 | )); |
||
| 1057 | |||
| 1058 | return $builder; |
||
| 1059 | |||
| 1060 | } |
||
| 1061 | |||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * フォームデータを更新 |
||
| 1065 | * |
||
| 1066 | * @param Order $Order |
||
| 1067 | * @param array $data |
||
| 1068 | * |
||
| 1069 | * @deprecated |
||
| 1070 | */ |
||
| 1071 | 1 | public function setFormData(Order $Order, array $data) |
|
| 1072 | { |
||
| 1073 | |||
| 1074 | // お問い合わせ |
||
| 1075 | 1 | $Order->setMessage($data['message']); |
|
| 1076 | |||
| 1077 | // お届け先情報を更新 |
||
| 1078 | 1 | $shippings = $data['shippings']; |
|
| 1079 | 1 | foreach ($shippings as $Shipping) { |
|
| 1080 | |||
| 1081 | 1 | $deliveryTime = $Shipping->getDeliveryTime(); |
|
| 1082 | 1 | if (!empty($deliveryTime)) { |
|
| 1083 | $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime()); |
||
| 1084 | 1 | $Shipping->setTimeId($deliveryTime->getId()); |
|
| 1085 | } |
||
| 1086 | |||
| 1087 | } |
||
| 1088 | |||
| 1089 | } |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * 配送料の合計金額を計算 |
||
| 1093 | * |
||
| 1094 | * @param Order $Order |
||
| 1095 | * @return Order |
||
| 1096 | */ |
||
| 1097 | 2 | public function calculateDeliveryFee(Order $Order) |
|
| 1098 | { |
||
| 1099 | |||
| 1100 | // 配送業者を取得 |
||
| 1101 | 2 | $shippings = $Order->getShippings(); |
|
| 1102 | |||
| 1103 | // 配送料合計金額 |
||
| 1104 | // TODO CalculateDeliveryFeeStrategy でセットする |
||
| 1105 | // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings)); |
||
| 1106 | |||
| 1107 | // 配送料無料条件(合計金額) |
||
| 1108 | 2 | $this->setDeliveryFreeAmount($Order); |
|
| 1109 | |||
| 1110 | // 配送料無料条件(合計数量) |
||
| 1111 | 2 | $this->setDeliveryFreeQuantity($Order); |
|
| 1112 | |||
| 1113 | 2 | return $Order; |
|
| 1114 | |||
| 1115 | } |
||
| 1116 | |||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * 購入処理を行う |
||
| 1120 | * |
||
| 1121 | * @param Order $Order |
||
| 1122 | * @throws ShoppingException |
||
| 1123 | */ |
||
| 1124 | 2 | public function processPurchase(Order $Order) |
|
| 1125 | { |
||
| 1126 | |||
| 1127 | 2 | $em = $this->entityManager; |
|
| 1128 | |||
| 1129 | // 受注情報、配送情報を更新 |
||
| 1130 | 2 | $Order = $this->calculateDeliveryFee($Order); |
|
| 1131 | 2 | $this->setOrderUpdateData($Order); |
|
| 1132 | |||
| 1133 | 2 | if ($this->app->isGranted('ROLE_USER')) { |
|
| 1134 | // 会員の場合、購入金額を更新 |
||
| 1135 | 1 | $this->setCustomerUpdate($Order, $this->app->user()); |
|
| 1136 | } |
||
| 1137 | } |
||
| 1138 | |||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * 値引き可能かチェック |
||
| 1142 | * |
||
| 1143 | * @param Order $Order |
||
| 1144 | * @param $discount |
||
| 1145 | * @return bool |
||
| 1146 | */ |
||
| 1147 | public function isDiscount(Order $Order, $discount) |
||
| 1156 | |||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * 値引き金額をセット |
||
| 1160 | * |
||
| 1161 | * @param Order $Order |
||
| 1162 | * @param $discount |
||
| 1163 | */ |
||
| 1164 | public function setDiscount(Order $Order, $discount) |
||
| 1170 | |||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * 合計金額を計算 |
||
| 1174 | * |
||
| 1175 | * @param Order $Order |
||
| 1176 | * @return Order |
||
| 1177 | */ |
||
| 1178 | 1 | public function calculatePrice(Order $Order) |
|
| 1194 | |||
| 1195 | /** |
||
| 1196 | * 受注ステータスをセット |
||
| 1197 | * |
||
| 1198 | * @param Order $Order |
||
| 1199 | * @param $status |
||
| 1200 | * @return Order |
||
| 1201 | */ |
||
| 1202 | 3 | public function setOrderStatus(Order $Order, $status) |
|
| 1219 | |||
| 1220 | /** |
||
| 1221 | * 受注メール送信を行う |
||
| 1222 | * |
||
| 1223 | * @param Order $Order |
||
| 1224 | * @return MailHistory |
||
| 1225 | */ |
||
| 1226 | 2 | public function sendOrderMail(Order $Order) |
|
| 1227 | { |
||
| 1228 | |||
| 1229 | // メール送信 |
||
| 1230 | 2 | $message = $this->mailService->sendOrderMail($Order); |
|
| 1231 | |||
| 1232 | // 送信履歴を保存. |
||
| 1233 | 2 | $MailHistory = new MailHistory(); |
|
| 1234 | $MailHistory |
||
| 1235 | 2 | ->setSubject($message->getSubject()) |
|
| 1236 | 2 | ->setMailBody($message->getBody()) |
|
| 1237 | 2 | ->setSendDate(new \DateTime()) |
|
| 1238 | 2 | ->setOrder($Order); |
|
| 1239 | |||
| 1240 | 2 | $this->entityManager->persist($MailHistory); |
|
| 1241 | 2 | $this->entityManager->flush($MailHistory); |
|
| 1242 | |||
| 1243 | 2 | return $MailHistory; |
|
| 1244 | |||
| 1245 | } |
||
| 1246 | |||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * 受注処理完了通知 |
||
| 1250 | * |
||
| 1251 | * @param Order $Order |
||
| 1252 | */ |
||
| 1253 | public function notifyComplete(Order $Order) |
||
| 1265 | |||
| 1266 | |||
| 1267 | } |
||
| 1268 |