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