Composable Commerce PHP SDKPHP SDK
  • Namespace
  • Class
  • Tree

Namespaces

  • Commercetools
    • Commons
      • Helper
    • Core
      • Builder
        • Request
        • Update
      • Cache
      • Client
        • Adapter
        • OAuth
      • Error
      • Helper
        • Annotate
        • State
          • Renderer
        • Subscriber
          • Log
      • Model
        • ApiClient
        • Cart
        • CartDiscount
        • Category
        • Channel
        • Common
        • Customer
        • CustomerGroup
        • CustomField
        • CustomObject
        • DiscountCode
        • Extension
        • Inventory
        • Message
        • Order
        • OrderEdit
        • Payment
        • Product
          • Search
        • ProductDiscount
        • ProductSelection
        • ProductType
        • Project
        • Review
        • ShippingMethod
        • ShoppingList
        • State
        • Store
        • Subscription
        • TaxCategory
        • Type
        • Zone
      • Request
        • ApiClients
        • CartDiscounts
          • Command
        • Carts
          • Command
        • Categories
          • Command
        • Channels
          • Command
        • CustomerGroups
          • Command
        • Customers
          • Command
        • CustomField
          • Command
        • CustomObjects
        • DiscountCodes
          • Command
        • Extensions
          • Command
        • GraphQL
        • InStores
        • Inventory
          • Command
        • Me
          • Command
        • Messages
        • OrderEdits
          • Command
          • StagedOrder
            • Command
        • Orders
          • Command
        • Payments
          • Command
        • ProductDiscounts
          • Command
        • Products
          • Command
        • ProductSelections
          • Command
        • ProductTypes
          • Command
        • Project
          • Command
        • Query
        • Reviews
          • Command
        • ShippingMethods
          • Command
        • ShoppingLists
          • Command
        • States
          • Command
        • Stores
          • Command
        • Subscriptions
          • Command
        • TaxCategories
          • Command
        • Types
          • Command
        • Zones
          • Command
      • Response

Classes

  • Cart
  • CartCollection
  • CartDiscountCodeState
  • CartDraft
  • CartReference
  • CartState
  • ClassificationShippingRateInput
  • ClassificationShippingRateInputDraft
  • CustomLineItem
  • CustomLineItemCollection
  • CustomLineItemDraft
  • CustomLineItemDraftCollection
  • DiscountCodeInfo
  • DiscountCodeInfoCollection
  • DiscountedLineItemPortion
  • DiscountedLineItemPortionCollection
  • DiscountedLineItemPrice
  • DiscountedPricePerQuantity
  • DiscountedPricePerQuantityCollection
  • ExternalLineItemTotalPrice
  • ExternalTaxAmountDraft
  • InventoryMode
  • ItemShippingDetails
  • ItemShippingDetailsDraft
  • ItemShippingTarget
  • ItemShippingTargetCollection
  • LineItem
  • LineItemCollection
  • LineItemDraft
  • LineItemDraftCollection
  • MyCartDraft
  • MyLineItemDraft
  • MyLineItemDraftCollection
  • ReplicaCartDraft
  • ScoreShippingRateInput
  • ScoreShippingRateInputDraft
  • ShippingInfo
  • ShippingRateInput
  • ShippingRateInputDraft
  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
/**
 * @author @jenschude <jens.schulze@commercetools.de>
 */

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;

/**
 * @package Commercetools\Core\Model\Cart
 * @link https://docs.commercetools.com/http-api-projects-carts.html#cart
 * @method string getId()
 * @method Cart setId(string $id = null)
 * @method int getVersion()
 * @method Cart setVersion(int $version = null)
 * @method DateTimeDecorator getCreatedAt()
 * @method Cart setCreatedAt(DateTime $createdAt = null)
 * @method DateTimeDecorator getLastModifiedAt()
 * @method Cart setLastModifiedAt(DateTime $lastModifiedAt = null)
 * @method string getCustomerId()
 * @method Cart setCustomerId(string $customerId = null)
 * @method string getCustomerEmail()
 * @method Cart setCustomerEmail(string $customerEmail = null)
 * @method LineItemCollection getLineItems()
 * @method Cart setLineItems(LineItemCollection $lineItems = null)
 * @method CustomLineItemCollection getCustomLineItems()
 * @method Cart setCustomLineItems(CustomLineItemCollection $customLineItems = null)
 * @method Money getTotalPrice()
 * @method Cart setTotalPrice(Money $totalPrice = null)
 * @method TaxedPrice getTaxedPrice()
 * @method Cart setTaxedPrice(TaxedPrice $taxedPrice = null)
 * @method string getCartState()
 * @method Cart setCartState(string $cartState = null)
 * @method Address getShippingAddress()
 * @method Cart setShippingAddress(Address $shippingAddress = null)
 * @method Address getBillingAddress()
 * @method Cart setBillingAddress(Address $billingAddress = null)
 * @method string getInventoryMode()
 * @method Cart setInventoryMode(string $inventoryMode = null)
 * @method CustomerGroupReference getCustomerGroup()
 * @method Cart setCustomerGroup(CustomerGroupReference $customerGroup = null)
 * @method string getCountry()
 * @method Cart setCountry(string $country = null)
 * @method ShippingInfo getShippingInfo()
 * @method Cart setShippingInfo(ShippingInfo $shippingInfo = null)
 * @method DiscountCodeInfoCollection getDiscountCodes()
 * @method Cart setDiscountCodes(DiscountCodeInfoCollection $discountCodes = null)
 * @method CustomFieldObject getCustom()
 * @method Cart setCustom(CustomFieldObject $custom = null)
 * @method PaymentInfo getPaymentInfo()
 * @method Cart setPaymentInfo(PaymentInfo $paymentInfo = null)
 * @method string getTaxMode()
 * @method Cart setTaxMode(string $taxMode = null)
 * @method string getAnonymousId()
 * @method Cart setAnonymousId(string $anonymousId = null)
 * @method string getLocale()
 * @method string getTaxRoundingMode()
 * @method Cart setTaxRoundingMode(string $taxRoundingMode = null)
 * @method int getDeleteDaysAfterLastModification()
 * @method Cart setDeleteDaysAfterLastModification(int $deleteDaysAfterLastModification = null)
 * @method CartDiscountReferenceCollection getRefusedGifts()
 * @method Cart setRefusedGifts(CartDiscountReferenceCollection $refusedGifts = null)
 * @method string getOrigin()
 * @method Cart setOrigin(string $origin = null)
 * @method string getTaxCalculationMode()
 * @method Cart setTaxCalculationMode(string $taxCalculationMode = null)
 * @method ShippingRateInput getShippingRateInput()
 * @method Cart setShippingRateInput(ShippingRateInput $shippingRateInput = null)
 * @method AddressCollection getItemShippingAddresses()
 * @method Cart setItemShippingAddresses(AddressCollection $itemShippingAddresses = null)
 * @method StoreReference getStore()
 * @method Cart setStore(StoreReference $store = null)
 * @method CreatedBy getCreatedBy()
 * @method Cart setCreatedBy(CreatedBy $createdBy = null)
 * @method LastModifiedBy getLastModifiedBy()
 * @method Cart setLastModifiedBy(LastModifiedBy $lastModifiedBy = null)
 * @method string getKey()
 * @method Cart setKey(string $key = null)
 * @method CartReference getReference()
 */
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;
    }
}
PHP SDK API documentation generated by ApiGen