Failed Conditions
Pull Request — experimental/sf (#3247)
by Kiyotaka
114:07 queued 103:28
created

PriceChangeValidator::process()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0488

Importance

Changes 0
Metric Value
cc 5
nc 7
nop 2
dl 0
loc 32
ccs 14
cts 16
cp 0.875
crap 5.0488
rs 9.0968
c 0
b 0
f 0
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\ItemValidator;
19
use Eccube\Service\PurchaseFlow\PurchaseContext;
20
21
/**
22
 * 販売価格の変更検知.
23
 */
24
class PriceChangeValidator extends ItemValidator
25
{
26
    /**
27
     * @param ItemInterface $item
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
28
     * @param PurchaseContext $context
29
     *
30
     * @throws \Eccube\Service\PurchaseFlow\InvalidItemException
31
     */
32 80
    public function validate(ItemInterface $item, PurchaseContext $context)
33
    {
34 80
        if (!$item->isProduct()) {
35 51
            return;
36
        }
37
38 80
        if ($item instanceof OrderItem) {
39 51
            $price = $item->getPriceIncTax();
40
        } else {
41
            // CartItem::priceは税込金額.
42 80
            $price = $item->getPrice();
43
        }
44
45 80
        $realPrice = $item->getProductClass()->getPrice02IncTax();
46 80
        if ($price != $realPrice) {
47 1
            if ($item instanceof OrderItem) {
48
                $item->setPrice($item->getProductClass()->getPrice02());
49
50
                $this->throwInvalidItemException('cart.product.price.change', $item->getProductClass());
51
            } else {
52
                // CartItem::priceは税込金額.
53 1
                $item->setPrice($realPrice);
54 1
                $this->throwInvalidItemException('cart.product.price.change', $item->getProductClass());
55
            }
56
        }
57
    }
58
}
59