1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
<?php
namespace Commercetools\Core\Model\Cart;
use Commercetools\Core\Model\CartDiscount\CartDiscountReferenceCollection;
use Commercetools\Core\Model\Common\Address;
use Commercetools\Core\Model\Common\AddressCollection;
use Commercetools\Core\Model\Common\CreatedBy;
use Commercetools\Core\Model\Common\LastModifiedBy;
use Commercetools\Core\Model\Common\LocaleTrait;
use Commercetools\Core\Model\Common\Resource;
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Common\TaxedPrice;
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use Commercetools\Core\Model\Payment\PaymentInfo;
use Commercetools\Core\Model\Store\StoreReference;
use DateTime;
class Cart extends Resource
{
use LocaleTrait;
const TAX_MODE_PLATFORM = 'Platform';
const TAX_MODE_EXTERNAL = 'External';
const TAX_MODE_DISABLED = 'Disabled';
const TAX_MODE_EXTERNAL_AMOUNT = 'ExternalAmount';
const TAX_ROUNDING_MODE_HALF_EVEN = 'HalfEven';
const TAX_ROUNDING_MODE_HALF_UP = 'HalfUp';
const TAX_ROUNDING_MODE_HALF_DOWN = 'HalfDown';
const ORIGIN_CUSTOMER = 'Customer';
const ORIGIN_MERCHANT = 'Merchant';
const TAX_CALCULATION_MODE_LINE_ITEM_LEVEL = 'LineItemLevel';
const TAX_CALCULATION_MODE_UNIT_PRICE_LEVEL = 'UnitPriceLevel';
public function fieldDefinitions()
{
return [
'id' => [static::TYPE => 'string'],
'key' => [static::TYPE => 'string', static::OPTIONAL => true],
'version' => [static::TYPE => 'int'],
'createdAt' => [
static::TYPE => DateTime::class,
static::DECORATOR => DateTimeDecorator::class
],
'lastModifiedAt' => [
static::TYPE => DateTime::class,
static::DECORATOR => DateTimeDecorator::class
],
'customerId' => [static::TYPE => 'string', static::OPTIONAL => true],
'customerEmail' => [static::TYPE => 'string', static::OPTIONAL => true],
'lineItems' => [static::TYPE => LineItemCollection::class],
'customLineItems' => [static::TYPE => CustomLineItemCollection::class],
'totalPrice' => [static::TYPE => Money::class],
'taxedPrice' => [static::TYPE => TaxedPrice::class, static::OPTIONAL => true],
'cartState' => [static::TYPE => 'string'],
'shippingAddress' => [static::TYPE => Address::class, static::OPTIONAL => true],
'billingAddress' => [static::TYPE => Address::class, static::OPTIONAL => true],
'inventoryMode' => [static::TYPE => 'string', static::OPTIONAL => true],
'customerGroup' => [static::TYPE => CustomerGroupReference::class, static::OPTIONAL => true],
'country' => [static::TYPE => 'string', static::OPTIONAL => true],
'shippingInfo' => [static::TYPE => ShippingInfo::class, static::OPTIONAL => true],
'discountCodes' => [static::TYPE => DiscountCodeInfoCollection::class, static::OPTIONAL => true],
'custom' => [static::TYPE => CustomFieldObject::class, static::OPTIONAL => true],
'paymentInfo' => [static::TYPE => PaymentInfo::class, static::OPTIONAL => true],
'taxMode' => [static::TYPE => 'string'],
'anonymousId' => [static::TYPE => 'string', static::OPTIONAL => true],
'locale' => [static::TYPE => 'string', static::OPTIONAL => true],
'taxRoundingMode' => [static::TYPE => 'string'],
'deleteDaysAfterLastModification' => [static::TYPE => 'int', static::OPTIONAL => true],
'refusedGifts' => [static::TYPE => CartDiscountReferenceCollection::class],
'origin' => [static::TYPE => 'string'],
'taxCalculationMode' => [static::TYPE => 'string'],
'shippingRateInput' => [static::TYPE => ShippingRateInput::class, static::OPTIONAL => true],
'itemShippingAddresses' => [static::TYPE => AddressCollection::class, static::OPTIONAL => true],
'store' => [static::TYPE => StoreReference::class, static::OPTIONAL => true],
'createdBy' => [static::TYPE => CreatedBy::class, static::OPTIONAL => true],
'lastModifiedBy' => [static::TYPE => LastModifiedBy::class, static::OPTIONAL => true],
];
}
public function getLineItemCount()
{
$count = 0;
if ($this->getLineItems() instanceof LineItemCollection) {
foreach ($this->getLineItems() as $lineItem) {
$count+= $lineItem->getQuantity();
}
$this->getLineItems()->rewind();
}
return $count;
}
}