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
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;
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],
];
}
public function setDiscountedPricePerQuantity(
DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null
) {
return parent::setDiscountedPricePerQuantity($discountedPricePerQuantity);
}
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);
}
}