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 
<?php
/**
 * @author @jenschude <jens.schulze@commercetools.de>
 */

namespace Commercetools\Core\Model\Cart;

use Commercetools\Core\Model\Channel\ChannelReference;
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Common\Price;
use Commercetools\Core\Model\Order\ItemStateCollection;
use Commercetools\Core\Model\Product\ProductVariant;
use Commercetools\Core\Model\TaxCategory\TaxRate;
use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\Common\TaxedItemPrice;
use Commercetools\Core\Model\ProductType\ProductTypeReference;
use DateTime;

/**
 * @package Commercetools\Core\Model\Cart
 * @link https://docs.commercetools.com/http-api-projects-carts.html#lineitem
 * @method string getId()
 * @method LineItem setId(string $id = null)
 * @method string getProductId()
 * @method LineItem setProductId(string $productId = null)
 * @method LocalizedString getName()
 * @method LineItem setName(LocalizedString $name = null)
 * @method ProductVariant getVariant()
 * @method LineItem setVariant(ProductVariant $variant = null)
 * @method Price getPrice()
 * @method LineItem setPrice(Price $price = null)
 * @method int getQuantity()
 * @method LineItem setQuantity(int $quantity = null)
 * @method ItemStateCollection getState()
 * @method LineItem setState(ItemStateCollection $state = null)
 * @method TaxRate getTaxRate()
 * @method LineItem setTaxRate(TaxRate $taxRate = null)
 * @method ChannelReference getSupplyChannel()
 * @method LineItem setSupplyChannel(ChannelReference $supplyChannel = null)
 * @method LocalizedString getProductSlug()
 * @method LineItem setProductSlug(LocalizedString $productSlug = null)
 * @method ChannelReference getDistributionChannel()
 * @method LineItem setDistributionChannel(ChannelReference $distributionChannel = null)
 * @method CustomFieldObject getCustom()
 * @method LineItem setCustom(CustomFieldObject $custom = null)
 * @method Money getTotalPrice()
 * @method LineItem setTotalPrice(Money $totalPrice = null)
 * @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
 * @method TaxedItemPrice getTaxedPrice()
 * @method LineItem setTaxedPrice(TaxedItemPrice $taxedPrice = null)
 * @method string getPriceMode()
 * @method LineItem setPriceMode(string $priceMode = null)
 * @method ProductTypeReference getProductType()
 * @method LineItem setProductType(ProductTypeReference $productType = null)
 * @method string getLineItemMode()
 * @method LineItem setLineItemMode(string $lineItemMode = null)
 * @method ItemShippingDetails getShippingDetails()
 * @method LineItem setShippingDetails(ItemShippingDetails $shippingDetails = null)
 * @method DateTime getAddedAt()
 * @method LineItem setAddedAt(DateTime $addedAt = null)
 * @method DateTime getLastModifiedAt()
 * @method LineItem setLastModifiedAt(DateTime $lastModifiedAt = null)
 * @method string getProductKey()
 * @method LineItem setProductKey(string $productKey = null)
 */
class LineItem extends JsonObject
{
    const PRICE_MODE_PLATFORM = 'Platform';
    const PRICE_MODE_EXTERNAL_TOTAL = 'ExternalTotal';
    const PRICE_MODE_EXTERNAL_PRICE = 'ExternalPrice';

    const LINE_ITEM_MODE_STANDARD = 'Standard';
    const LINE_ITEM_MODE_GIFT_LINE_ITEM = 'GiftLineItem';

    public function fieldDefinitions()
    {
        return [
            'id' => [static::TYPE => 'string'],
            'productId' => [static::TYPE => 'string'],
            'productKey' => [static::TYPE => 'string', static::OPTIONAL => true],
            'name' => [static::TYPE => LocalizedString::class],
            'productSlug' => [static::TYPE => LocalizedString::class, static::OPTIONAL => true],
            'variant' => [static::TYPE => ProductVariant::class],
            'price' => [static::TYPE => Price::class],
            'taxedPrice' => [static::TYPE => TaxedItemPrice::class, static::OPTIONAL => true],
            'quantity' => [static::TYPE => 'int'],
            'addedAt' => [static::TYPE => DateTime::class, static::OPTIONAL => true],
            'state' => [static::TYPE => ItemStateCollection::class],
            'taxRate' => [static::TYPE => TaxRate::class, static::OPTIONAL => true],
            'supplyChannel' => [static::TYPE => ChannelReference::class, static::OPTIONAL => true],
            'distributionChannel' => [static::TYPE => ChannelReference::class, static::OPTIONAL => true],
            'custom' => [static::TYPE => CustomFieldObject::class, static::OPTIONAL => true],
            'totalPrice' => [static::TYPE => Money::class],
            'discountedPricePerQuantity' => [
                static::TYPE => DiscountedPricePerQuantityCollection::class
            ],
            'priceMode' => [static::TYPE => 'string'],
            'lineItemMode' => [static::TYPE => 'string'],
            'productType' => [static::TYPE => ProductTypeReference::class],
            'shippingDetails' => [static::TYPE => ItemShippingDetails::class, static::OPTIONAL => true],
            'lastModifiedAt' => [static::TYPE => DateTime::class, static::OPTIONAL => true],
        ];
    }

    /**
     * @param DiscountedPricePerQuantityCollection $discountedPricePerQuantity
     * @return static
     */
    public function setDiscountedPricePerQuantity(
        DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null
    ) {
        return parent::setDiscountedPricePerQuantity($discountedPricePerQuantity);
    }

    /**
     * @return Money
     */
    public function getDiscountedPrice()
    {
        $centAmount = 0;
        $currencyCode = $this->getPrice()->getValue()->getCurrencyCode();
        foreach ($this->getDiscountedPricePerQuantity() as $discountedPricePerQuantity) {
            $centAmount += $discountedPricePerQuantity->getDiscountedTotal()->getCentAmount();
        }
        $this->getDiscountedPricePerQuantity()->rewind();
        return Money::ofCurrencyAndAmount($currencyCode, $centAmount);
    }
}
PHP SDK API documentation generated by ApiGen