Completed
Push — master ( 122bdb...4f8f85 )
by Jens
10:49 queued 41s
created

DiscountedPricePerQuantity::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Cart;
7
8
use Commercetools\Core\Model\Common\JsonObject;
9
use Commercetools\Core\Model\Common\Money;
10
11
/**
12
 * @package Commercetools\Core\Model\Cart
13
 * @link https://dev.commercetools.com/http-api-projects-carts.html#discountedlineitempriceforquantity
14
 * @method int getQuantity()
15
 * @method DiscountedPricePerQuantity setQuantity(int $quantity = null)
16
 * @method DiscountedLineItemPrice getDiscountedPrice()
17
 * @method DiscountedPricePerQuantity setDiscountedPrice(DiscountedLineItemPrice $discountedPrice = null)
18
 */
19
class DiscountedPricePerQuantity extends JsonObject
20
{
21 2
    public function fieldDefinitions()
22
    {
23
        return [
24 2
            'quantity' => [static::TYPE => 'int'],
25 2
            'discountedPrice' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedLineItemPrice']
26
        ];
27
    }
28
29
    /**
30
     * @return Money
31
     */
32
    public function getDiscountedTotal()
33
    {
34
        return Money::ofCurrencyAndAmount(
35
            $this->getDiscountedPrice()->getValue()->getCurrencyCode(),
36
            $this->getDiscountedPrice()->getValue()->getCentAmount() * $this->getQuantity()
37
        );
38
    }
39
}
40