Completed
Push — develop ( 17c567...8b47e8 )
by Jens
08:20
created

Cart::setLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Cart;
7
8
use Commercetools\Core\Model\Common\Address;
9
use Commercetools\Core\Model\Common\LocaleTrait;
10
use Commercetools\Core\Model\Common\Resource;
11
use Commercetools\Core\Model\Common\Money;
12
use Commercetools\Core\Model\Common\TaxedPrice;
13
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
14
use Commercetools\Core\Model\CustomField\CustomFieldObject;
15
use Commercetools\Core\Model\Common\DateTimeDecorator;
16
use Commercetools\Core\Model\Payment\PaymentInfo;
17
18
/**
19
 * @package Commercetools\Core\Model\Cart
20
 * @link https://dev.commercetools.com/http-api-projects-carts.html#cart
21
 * @method string getId()
22
 * @method Cart setId(string $id = null)
23
 * @method int getVersion()
24
 * @method Cart setVersion(int $version = null)
25
 * @method DateTimeDecorator getCreatedAt()
26
 * @method Cart setCreatedAt(\DateTime $createdAt = null)
27
 * @method DateTimeDecorator getLastModifiedAt()
28
 * @method Cart setLastModifiedAt(\DateTime $lastModifiedAt = null)
29
 * @method string getCustomerId()
30
 * @method Cart setCustomerId(string $customerId = null)
31
 * @method string getCustomerEmail()
32
 * @method Cart setCustomerEmail(string $customerEmail = null)
33
 * @method LineItemCollection getLineItems()
34
 * @method Cart setLineItems(LineItemCollection $lineItems = null)
35
 * @method CustomLineItemCollection getCustomLineItems()
36
 * @method Cart setCustomLineItems(CustomLineItemCollection $customLineItems = null)
37
 * @method Money getTotalPrice()
38
 * @method Cart setTotalPrice(Money $totalPrice = null)
39
 * @method TaxedPrice getTaxedPrice()
40
 * @method Cart setTaxedPrice(TaxedPrice $taxedPrice = null)
41
 * @method string getCartState()
42
 * @method Cart setCartState(string $cartState = null)
43
 * @method Address getShippingAddress()
44
 * @method Cart setShippingAddress(Address $shippingAddress = null)
45
 * @method Address getBillingAddress()
46
 * @method Cart setBillingAddress(Address $billingAddress = null)
47
 * @method string getInventoryMode()
48
 * @method Cart setInventoryMode(string $inventoryMode = null)
49
 * @method CustomerGroupReference getCustomerGroup()
50
 * @method Cart setCustomerGroup(CustomerGroupReference $customerGroup = null)
51
 * @method string getCountry()
52
 * @method Cart setCountry(string $country = null)
53
 * @method ShippingInfo getShippingInfo()
54
 * @method Cart setShippingInfo(ShippingInfo $shippingInfo = null)
55
 * @method DiscountCodeInfoCollection getDiscountCodes()
56
 * @method Cart setDiscountCodes(DiscountCodeInfoCollection $discountCodes = null)
57
 * @method CustomFieldObject getCustom()
58
 * @method Cart setCustom(CustomFieldObject $custom = null)
59
 * @method PaymentInfo getPaymentInfo()
60
 * @method Cart setPaymentInfo(PaymentInfo $paymentInfo = null)
61
 * @method string getTaxMode()
62
 * @method Cart setTaxMode(string $taxMode = null)
63
 * @method string getAnonymousId()
64
 * @method Cart setAnonymousId(string $anonymousId = null)
65
 * @method string getLocale()
66
 * @method CartReference getReference()
67
 */
68
class Cart extends Resource
69
{
70
    use LocaleTrait;
71
72
    const TAX_MODE_PLATFORM = 'Platform';
73
    const TAX_MODE_EXTERNAL = 'External';
74
    const TAX_MODE_DISABLED = 'Disabled';
75
76 107
    public function fieldDefinitions()
77
    {
78
        return [
79 107
            'id' => [static::TYPE => 'string'],
80 107
            'version' => [static::TYPE => 'int'],
81
            'createdAt' => [
82 107
                static::TYPE => '\DateTime',
83 107
                static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
84
            ],
85
            'lastModifiedAt' => [
86 107
                static::TYPE => '\DateTime',
87 107
                static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
88
            ],
89 107
            'customerId' => [static::TYPE => 'string'],
90 107
            'customerEmail' => [static::TYPE => 'string'],
91 107
            'lineItems' => [static::TYPE => '\Commercetools\Core\Model\Cart\LineItemCollection'],
92 107
            'customLineItems' => [static::TYPE => '\Commercetools\Core\Model\Cart\CustomLineItemCollection'],
93 107
            'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
94 107
            'taxedPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\TaxedPrice'],
95 107
            'cartState' => [static::TYPE => 'string'],
96 107
            'shippingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'],
97 107
            'billingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'],
98 107
            'inventoryMode' => [static::TYPE => 'string'],
99 107
            'customerGroup' => [static::TYPE => '\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference'],
100 107
            'country' => [static::TYPE => 'string'],
101 107
            'shippingInfo' => [static::TYPE => '\Commercetools\Core\Model\Cart\ShippingInfo'],
102 107
            'discountCodes' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountCodeInfoCollection'],
103 107
            'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
104 107
            'paymentInfo' => [static::TYPE => '\Commercetools\Core\Model\Payment\PaymentInfo'],
105 107
            'taxMode' => [static::TYPE => 'string'],
106 107
            'anonymousId' => [static::TYPE => 'string'],
107 107
            'locale' => [static::TYPE => 'string'],
108
        ];
109
    }
110
111 4
    public function getLineItemCount()
112
    {
113 4
        $count = 0;
114 4
        if ($this->getLineItems() instanceof LineItemCollection) {
115 3
            foreach ($this->getLineItems() as $lineItem) {
116 2
                $count+= $lineItem->getQuantity();
117
            }
118
        }
119 4
        return $count;
120
    }
121
}
122