1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Service\PurchaseFlow\Processor; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
17
|
|
|
use Eccube\Entity\BaseInfo; |
18
|
|
|
use Eccube\Entity\ItemHolderInterface; |
19
|
|
|
use Eccube\Service\PurchaseFlow\ItemHolderProcessor; |
20
|
|
|
use Eccube\Service\PurchaseFlow\ProcessResult; |
21
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* 加算ポイント. |
25
|
|
|
*/ |
26
|
|
|
class AddPointProcessor implements ItemHolderProcessor |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var EntityManagerInterface |
30
|
|
|
*/ |
31
|
|
|
protected $entityManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var BaseInfo |
35
|
|
|
*/ |
36
|
|
|
protected $BaseInfo; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* AddPointProcessor constructor. |
40
|
|
|
* |
41
|
|
|
* @param EntityManagerInterface $entityManager |
42
|
|
|
* @param BaseInfo $BaseInfo |
43
|
|
|
*/ |
44
|
|
|
public function __construct(EntityManagerInterface $entityManager, BaseInfo $BaseInfo) |
45
|
|
|
{ |
46
|
|
|
$this->entityManager = $entityManager; |
47
|
|
|
$this->BaseInfo = $BaseInfo; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param ItemHolderInterface $itemHolder |
52
|
|
|
* @param PurchaseContext $context |
53
|
|
|
* |
54
|
|
|
* @return ProcessResult |
55
|
|
|
*/ |
56
|
|
|
public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
57
|
|
|
{ |
58
|
|
|
$addPoint = 0; |
59
|
|
|
foreach ($itemHolder->getItems() as $item) { |
60
|
|
|
$rate = $item->getPointRate(); |
61
|
|
|
if ($rate === null) { |
62
|
|
|
$rate = $this->BaseInfo->getBasicPointRate(); |
63
|
|
|
} |
64
|
|
|
$addPoint += $this->priceToAddPoint($rate, $item->getPriceIncTax(), $item->getQuantity()); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
$itemHolder->setAddPoint($addPoint); |
67
|
|
|
|
68
|
|
|
return ProcessResult::success(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* 単価と数量から加算ポイントに換算する. |
73
|
|
|
* |
74
|
|
|
* @param integer $pointRate ポイント付与率(%) |
75
|
|
|
* @param integer $price 単価 |
76
|
|
|
* @param integer $quantity 数量 |
77
|
|
|
* |
78
|
|
|
* @return double additional point |
79
|
|
|
*/ |
80
|
|
|
protected function priceToAddPoint($pointRate, $price, $quantity) |
81
|
|
|
{ |
82
|
|
|
return round($price * ($pointRate / 100)) * $quantity; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.