1
|
|
|
<?php |
2
|
|
|
namespace Eccube\Service\Calculator\Strategy; |
3
|
|
|
|
4
|
|
|
use Eccube\Application; |
5
|
|
|
use Eccube\Entity\Master\OrderItemType; |
6
|
|
|
use Eccube\Entity\Master\TaxType; |
7
|
|
|
use Eccube\Entity\Master\TaxDisplayType; |
8
|
|
|
use Eccube\Entity\Order; |
9
|
|
|
use Eccube\Entity\PurchaseInterface; |
10
|
|
|
use Eccube\Entity\ShipmentItem; |
11
|
|
|
use Eccube\Entity\Shipping; |
12
|
|
|
use Eccube\Repository\Master\OrderItemTypeRepository; |
13
|
|
|
use Eccube\Service\Calculator\ShipmentItemCollection; |
14
|
|
|
|
15
|
|
|
class ShippingStrategy implements CalculateStrategyInterface |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/* @var Application $app */ |
18
|
|
|
protected $app; |
19
|
|
|
|
20
|
|
|
/* @var Order $Order */ |
21
|
|
|
protected $Order; |
22
|
|
|
|
23
|
|
|
/** @var OrderItemTypeRepository */ |
24
|
|
|
protected $OrderItemTypeRepository; |
25
|
|
|
|
26
|
|
|
public function execute(ShipmentItemCollection $ShipmentItems) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
// 送料の受注明細区分 |
29
|
|
|
$DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE); |
30
|
|
|
// TODO |
31
|
|
|
$TaxInclude = $this->app['orm.em']->getRepository(TaxDisplayType::class)->find(TaxDisplayType::INCLUDED); |
32
|
|
|
$Taxion = $this->app['orm.em']->getRepository(TaxType::class)->find(TaxType::TAXATION); |
33
|
|
|
|
34
|
|
|
// 配送ごとに送料の明細を作成 |
35
|
|
|
foreach ($this->Order->getShippings() as $Shipping) { |
36
|
|
|
/* @var Shipping $Shipping */ |
37
|
|
|
$sio = new ShipmentItemCollection($Shipping->getShipmentItems()->toArray()); |
38
|
|
View Code Duplication |
if (!$sio->hasItemByOrderItemType($DeliveryFeeType)) { |
39
|
|
|
$ShipmentItem = new ShipmentItem(); |
40
|
|
|
$ShipmentItem->setProductName("送料") |
41
|
|
|
->setPrice($Shipping->getShippingDeliveryFee()) |
42
|
|
|
->setPriceIncTax($Shipping->getShippingDeliveryFee()) |
43
|
|
|
->setTaxRate(8) |
44
|
|
|
->setQuantity(1) |
45
|
|
|
->setOrderItemType($DeliveryFeeType) |
46
|
|
|
->setShipping($Shipping) |
47
|
|
|
->setTaxDisplayType($TaxInclude) |
48
|
|
|
->setTaxType($Taxion); |
49
|
|
|
$ShipmentItems->add($ShipmentItem); |
50
|
|
|
$Shipping->addShipmentItem($ShipmentItem); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setApplication(Application $app) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$this->app = $app; |
58
|
|
|
return $this; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setOrder(PurchaseInterface $Order) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->Order = $Order; |
|
|
|
|
64
|
|
|
return $this; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getTargetTypes() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
return [Order::class]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|