|
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\Resource; |
|
10
|
|
|
use Commercetools\Core\Model\Common\Money; |
|
11
|
|
|
use Commercetools\Core\Model\Common\TaxedPrice; |
|
12
|
|
|
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference; |
|
13
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObject; |
|
14
|
|
|
use Commercetools\Core\Model\Common\DateTimeDecorator; |
|
15
|
|
|
use Commercetools\Core\Model\Payment\PaymentInfo; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @package Commercetools\Core\Model\Cart |
|
19
|
|
|
* @link https://dev.commercetools.com/http-api-projects-carts.html#cart |
|
20
|
|
|
* @method string getId() |
|
21
|
|
|
* @method Cart setId(string $id = null) |
|
22
|
|
|
* @method int getVersion() |
|
23
|
|
|
* @method Cart setVersion(int $version = null) |
|
24
|
|
|
* @method DateTimeDecorator getCreatedAt() |
|
25
|
|
|
* @method Cart setCreatedAt(\DateTime $createdAt = null) |
|
26
|
|
|
* @method DateTimeDecorator getLastModifiedAt() |
|
27
|
|
|
* @method Cart setLastModifiedAt(\DateTime $lastModifiedAt = null) |
|
28
|
|
|
* @method string getCustomerId() |
|
29
|
|
|
* @method Cart setCustomerId(string $customerId = null) |
|
30
|
|
|
* @method string getCustomerEmail() |
|
31
|
|
|
* @method Cart setCustomerEmail(string $customerEmail = null) |
|
32
|
|
|
* @method LineItemCollection getLineItems() |
|
33
|
|
|
* @method Cart setLineItems(LineItemCollection $lineItems = null) |
|
34
|
|
|
* @method CustomLineItemCollection getCustomLineItems() |
|
35
|
|
|
* @method Cart setCustomLineItems(CustomLineItemCollection $customLineItems = null) |
|
36
|
|
|
* @method Money getTotalPrice() |
|
37
|
|
|
* @method Cart setTotalPrice(Money $totalPrice = null) |
|
38
|
|
|
* @method TaxedPrice getTaxedPrice() |
|
39
|
|
|
* @method Cart setTaxedPrice(TaxedPrice $taxedPrice = null) |
|
40
|
|
|
* @method string getCartState() |
|
41
|
|
|
* @method Cart setCartState(string $cartState = null) |
|
42
|
|
|
* @method Address getShippingAddress() |
|
43
|
|
|
* @method Cart setShippingAddress(Address $shippingAddress = null) |
|
44
|
|
|
* @method Address getBillingAddress() |
|
45
|
|
|
* @method Cart setBillingAddress(Address $billingAddress = null) |
|
46
|
|
|
* @method string getInventoryMode() |
|
47
|
|
|
* @method Cart setInventoryMode(string $inventoryMode = null) |
|
48
|
|
|
* @method CustomerGroupReference getCustomerGroup() |
|
49
|
|
|
* @method Cart setCustomerGroup(CustomerGroupReference $customerGroup = null) |
|
50
|
|
|
* @method string getCountry() |
|
51
|
|
|
* @method Cart setCountry(string $country = null) |
|
52
|
|
|
* @method ShippingInfo getShippingInfo() |
|
53
|
|
|
* @method Cart setShippingInfo(ShippingInfo $shippingInfo = null) |
|
54
|
|
|
* @method DiscountCodeInfoCollection getDiscountCodes() |
|
55
|
|
|
* @method Cart setDiscountCodes(DiscountCodeInfoCollection $discountCodes = null) |
|
56
|
|
|
* @method CustomFieldObject getCustom() |
|
57
|
|
|
* @method Cart setCustom(CustomFieldObject $custom = null) |
|
58
|
|
|
* @method PaymentInfo getPaymentInfo() |
|
59
|
|
|
* @method Cart setPaymentInfo(PaymentInfo $paymentInfo = null) |
|
60
|
|
|
* @method CartReference getReference() |
|
61
|
|
|
*/ |
|
62
|
|
|
class Cart extends Resource |
|
63
|
|
|
{ |
|
64
|
43 |
|
public function fieldDefinitions() |
|
65
|
|
|
{ |
|
66
|
|
|
return [ |
|
67
|
43 |
|
'id' => [static::TYPE => 'string'], |
|
68
|
43 |
|
'version' => [static::TYPE => 'int'], |
|
69
|
|
|
'createdAt' => [ |
|
70
|
43 |
|
static::TYPE => '\DateTime', |
|
71
|
43 |
|
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
|
72
|
|
|
], |
|
73
|
|
|
'lastModifiedAt' => [ |
|
74
|
43 |
|
static::TYPE => '\DateTime', |
|
75
|
43 |
|
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
|
76
|
|
|
], |
|
77
|
43 |
|
'customerId' => [static::TYPE => 'string'], |
|
78
|
43 |
|
'customerEmail' => [static::TYPE => 'string'], |
|
79
|
43 |
|
'lineItems' => [static::TYPE => '\Commercetools\Core\Model\Cart\LineItemCollection'], |
|
80
|
43 |
|
'customLineItems' => [static::TYPE => '\Commercetools\Core\Model\Cart\CustomLineItemCollection'], |
|
81
|
43 |
|
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'], |
|
82
|
43 |
|
'taxedPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\TaxedPrice'], |
|
83
|
43 |
|
'cartState' => [static::TYPE => 'string'], |
|
84
|
43 |
|
'shippingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'], |
|
85
|
43 |
|
'billingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'], |
|
86
|
43 |
|
'inventoryMode' => [static::TYPE => 'string'], |
|
87
|
43 |
|
'customerGroup' => [static::TYPE => '\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference'], |
|
88
|
43 |
|
'country' => [static::TYPE => 'string'], |
|
89
|
43 |
|
'shippingInfo' => [static::TYPE => '\Commercetools\Core\Model\Cart\ShippingInfo'], |
|
90
|
43 |
|
'discountCodes' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountCodeInfoCollection'], |
|
91
|
43 |
|
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'], |
|
92
|
43 |
|
'paymentInfo' => [static::TYPE => '\Commercetools\Core\Model\Payment\PaymentInfo'], |
|
93
|
|
|
]; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
4 |
|
public function getLineItemCount() |
|
97
|
|
|
{ |
|
98
|
4 |
|
$count = 0; |
|
99
|
4 |
|
if ($this->getLineItems() instanceof LineItemCollection) { |
|
100
|
3 |
|
foreach ($this->getLineItems() as $lineItem) { |
|
101
|
2 |
|
$count+= $lineItem->getQuantity(); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
4 |
|
return $count; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|