Passed
Push — develop ( 2123c4...47647c )
by
unknown
15:28 queued 14s
created

CartDraft::ofCurrencyAndShippingCountry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Cart;
7
8
use Commercetools\Core\Model\Common\AddressCollection;
9
use Commercetools\Core\Model\Common\Context;
10
use Commercetools\Core\Model\Common\JsonObject;
11
use Commercetools\Core\Model\Common\LocaleTrait;
12
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
13
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
14
use Commercetools\Core\Model\Common\Address;
15
use Commercetools\Core\Model\ShippingMethod\ShippingMethodReference;
16
use Commercetools\Core\Model\Store\StoreReference;
17
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
18
19
/**
20
 * @package Commercetools\Core\Model\Cart
21
 * @link https://docs.commercetools.com/http-api-projects-carts.html#cartdraft
22
 * @method string getCurrency()
23
 * @method string getCustomerId()
24
 * @method string getCountry()
25
 * @method string getInventoryMode()
26
 * @method CartDraft setCurrency(string $currency = null)
27
 * @method CartDraft setCustomerId(string $customerId = null)
28
 * @method CartDraft setCountry(string $country = null)
29
 * @method CartDraft setInventoryMode(string $inventoryMode = null)
30
 * @method CustomFieldObjectDraft getCustom()
31
 * @method CartDraft setCustom(CustomFieldObjectDraft $custom = null)
32
 * @method string getCustomerEmail()
33
 * @method CartDraft setCustomerEmail(string $customerEmail = null)
34
 * @method LineItemDraftCollection getLineItems()
35
 * @method CartDraft setLineItems(LineItemDraftCollection $lineItems = null)
36
 * @method Address getShippingAddress()
37
 * @method CartDraft setShippingAddress(Address $shippingAddress = null)
38
 * @method Address getBillingAddress()
39
 * @method CartDraft setBillingAddress(Address $billingAddress = null)
40
 * @method ShippingMethodReference getShippingMethod()
41
 * @method CartDraft setShippingMethod(ShippingMethodReference $shippingMethod = null)
42
 * @method CustomLineItemDraftCollection getCustomLineItems()
43
 * @method CartDraft setCustomLineItems(CustomLineItemDraftCollection $customLineItems = null)
44
 * @method string getTaxMode()
45
 * @method CartDraft setTaxMode(string $taxMode = null)
46
 * @method string getAnonymousId()
47
 * @method CartDraft setAnonymousId(string $anonymousId = null)
48
 * @method string getLocale()
49
 * @method string getTaxRoundingMode()
50
 * @method CartDraft setTaxRoundingMode(string $taxRoundingMode = null)
51
 * @method int getDeleteDaysAfterLastModification()
52
 * @method CartDraft setDeleteDaysAfterLastModification(int $deleteDaysAfterLastModification = null)
53
 * @method CustomerGroupReference getCustomerGroup()
54
 * @method CartDraft setCustomerGroup(CustomerGroupReference $customerGroup = null)
55
 * @method string getOrigin()
56
 * @method CartDraft setOrigin(string $origin = null)
57
 * @method string getTaxCalculationMode()
58
 * @method CartDraft setTaxCalculationMode(string $taxCalculationMode = null)
59
 * @method ExternalTaxRateDraft getExternalTaxRateForShippingMethod()
60
 * @method CartDraft setExternalTaxRateForShippingMethod(ExternalTaxRateDraft $externalTaxRateForShippingMethod = null)
61
 * @method ShippingRateInputDraft getShippingRateInput()
62
 * @method CartDraft setShippingRateInput(ShippingRateInputDraft $shippingRateInput = null)
63
 * @method AddressCollection getItemShippingAddresses()
64
 * @method CartDraft setItemShippingAddresses(AddressCollection $itemShippingAddresses = null)
65
 * @method StoreReference getStore()
66
 * @method CartDraft setStore(StoreReference $store = null)
67
 */
68
class CartDraft extends JsonObject
69
{
70
    use LocaleTrait;
71
72 260
    public function fieldDefinitions()
73
    {
74
        return [
75 260
            'currency' => [static::TYPE => 'string'],
76 260
            'customerId' => [static::TYPE => 'string'],
77 260
            'customerEmail' => [static::TYPE => 'string'],
78 260
            'country' => [static::TYPE => 'string'],
79 260
            'inventoryMode' => [static::TYPE => 'string'],
80 260
            'lineItems' => [static::TYPE => LineItemDraftCollection::class],
81 260
            'customLineItems' => [static::TYPE => CustomLineItemDraftCollection::class],
82 260
            'shippingAddress' => [static::TYPE => Address::class],
83 260
            'billingAddress' => [static::TYPE => Address::class],
84 260
            'shippingMethod' => [static::TYPE => ShippingMethodReference::class],
85 260
            'custom' => [static::TYPE => CustomFieldObjectDraft::class],
86 260
            'taxMode' => [static::TYPE => 'string'],
87 260
            'anonymousId' => [static::TYPE => 'string'],
88 260
            'locale' => [static::TYPE => 'string'],
89 260
            'taxRoundingMode' => [static::TYPE => 'string'],
90 260
            'deleteDaysAfterLastModification' => [static::TYPE => 'int'],
91 260
            'customerGroup' => [static::TYPE => CustomerGroupReference::class],
92 260
            'origin' => [static::TYPE => 'string'],
93 260
            'taxCalculationMode' => [static::TYPE => 'string'],
94 260
            'externalTaxRateForShippingMethod' => [static::TYPE => ExternalTaxRateDraft::class],
95 260
            'shippingRateInput' => [static::TYPE => ShippingRateInputDraft::class],
96 260
            'itemShippingAddresses' => [static::TYPE => AddressCollection::class],
97 260
            'store' => [static::TYPE => StoreReference::class],
98
        ];
99
    }
100
101
    /**
102
     * @param string $currency
103
     * @param Context|callable $context
104
     * @return CartDraft
105
     */
106 253
    public static function ofCurrency($currency, $context = null)
107
    {
108 253
        $draft = static::of($context);
109 253
        return $draft->setCurrency($currency);
110
    }
111
112
    /**
113
     * @param string $currency
114
     * @param string $country
115
     * @param Context|callable $context
116
     * @return CartDraft
117
     */
118 4
    public static function ofCurrencyAndShippingCountry($currency, $country, $context = null)
119
    {
120 4
        $draft = static::of($context);
121
122 4
        return $draft->setCurrency($currency)
123 4
            ->setCountry($country)
124 4
            ->setShippingAddress(Address::of()->setCountry($country));
125
    }
126
}
127