Failed Conditions
Branch experimental/sf (68db07)
by Kentaro
42:17 queued 33:39
created

PriceChangeValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 41
rs 10
c 2
b 0
f 0
ccs 14
cts 16
cp 0.875
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 32 5
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 Eccube\Entity\ItemInterface;
17
use Eccube\Entity\OrderItem;
18
use Eccube\Service\PurchaseFlow\ItemProcessor;
19
use Eccube\Service\PurchaseFlow\ProcessResult;
20
use Eccube\Service\PurchaseFlow\PurchaseContext;
21
22
/**
23
 * 販売価格の変更検知.
24
 */
25
class PriceChangeValidator implements ItemProcessor
26
{
27
    /**
28
     * @param ItemInterface $item
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
29
     * @param PurchaseContext $context
30
     *
31
     * @return ProcessResult
32
     */
33 80
    public function process(ItemInterface $item, PurchaseContext $context)
34
    {
35 80
        if (!$item->isProduct()) {
36 15
            return ProcessResult::success();
37
        }
38
39 80
        if ($item instanceof OrderItem) {
40 51
            $price = $item->getPriceIncTax();
41
        } else {
42
            // CartItem::priceは税込金額.
43 80
            $price = $item->getPrice();
44
        }
45
46 80
        $realPrice = $item->getProductClass()->getPrice02IncTax();
47 80
        if ($price != $realPrice) {
48 1
            $message = trans('cart.product.price.change',
49 1
                ['%product%' => $item->getProductClass()->formatedProductName()]);
50
51 1
            if ($item instanceof OrderItem) {
52
                $item->setPrice($item->getProductClass()->getPrice02());
53
54
                return ProcessResult::error($message);
55
            } else {
56
                // CartItem::priceは税込金額.
57 1
                $item->setPrice($realPrice);
58
59 1
                return ProcessResult::warn($message);
60
            }
61
        }
62
63 79
        return ProcessResult::success();
64
    }
65
}
66