Completed
Pull Request — master (#121)
by Dmitry
07:20
created

MultiCurrencyException::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 3
crap 6
1
<?php
2
3
namespace hipanel\modules\finance\cart;
4
5
use hiqdev\yii2\cart\ShoppingCart;
6
use Yii;
7
8
final class MultiCurrencyException extends NotPurchasableException
9
{
10
    /**
11
     * @var AbstractCartPosition
12
     */
13
    private $position;
14
    /**
15
     * @var ShoppingCart
16
     */
17
    private $shoppingCart;
18
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function __construct(string $message, ShoppingCart $shoppingCart, AbstractCartPosition $position)
23
    {
24
        parent::__construct($message ?: 'Can not add this item to cart because of different currency');
25
        $this->position = $position;
26
        $this->shoppingCart = $shoppingCart;
27
    }
28
29
    public function resolve(): bool
30
    {
31
        Yii::error('Cart position "' . $this->position->getName() . '" was removed from the cart because multi-currency cart is not available for now', 'hipanel.cart');
32
        $this->shoppingCart->remove($this->position);
33
34
        return true;
35
    }
36
}
37