|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author @jenschude <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Cart; |
|
7
|
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Channel\ChannelReference; |
|
9
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
|
10
|
|
|
use Commercetools\Core\Model\Common\LocalizedString; |
|
11
|
|
|
use Commercetools\Core\Model\Common\Money; |
|
12
|
|
|
use Commercetools\Core\Model\Common\Price; |
|
13
|
|
|
use Commercetools\Core\Model\Order\ItemStateCollection; |
|
14
|
|
|
use Commercetools\Core\Model\Product\ProductVariant; |
|
15
|
|
|
use Commercetools\Core\Model\TaxCategory\TaxRate; |
|
16
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObject; |
|
17
|
|
|
use Commercetools\Core\Model\Common\TaxedItemPrice; |
|
18
|
|
|
use Commercetools\Core\Model\ProductType\ProductTypeReference; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @package Commercetools\Core\Model\Cart |
|
22
|
|
|
* @link https://docs.commercetools.com/http-api-projects-carts.html#lineitem |
|
23
|
|
|
* @method string getId() |
|
24
|
|
|
* @method LineItem setId(string $id = null) |
|
25
|
|
|
* @method string getProductId() |
|
26
|
|
|
* @method LineItem setProductId(string $productId = null) |
|
27
|
|
|
* @method LocalizedString getName() |
|
28
|
|
|
* @method LineItem setName(LocalizedString $name = null) |
|
29
|
|
|
* @method ProductVariant getVariant() |
|
30
|
|
|
* @method LineItem setVariant(ProductVariant $variant = null) |
|
31
|
|
|
* @method Price getPrice() |
|
32
|
|
|
* @method LineItem setPrice(Price $price = null) |
|
33
|
|
|
* @method int getQuantity() |
|
34
|
|
|
* @method LineItem setQuantity(int $quantity = null) |
|
35
|
|
|
* @method ItemStateCollection getState() |
|
36
|
|
|
* @method LineItem setState(ItemStateCollection $state = null) |
|
37
|
|
|
* @method TaxRate getTaxRate() |
|
38
|
|
|
* @method LineItem setTaxRate(TaxRate $taxRate = null) |
|
39
|
|
|
* @method ChannelReference getSupplyChannel() |
|
40
|
|
|
* @method LineItem setSupplyChannel(ChannelReference $supplyChannel = null) |
|
41
|
|
|
* @method LocalizedString getProductSlug() |
|
42
|
|
|
* @method LineItem setProductSlug(LocalizedString $productSlug = null) |
|
43
|
|
|
* @method ChannelReference getDistributionChannel() |
|
44
|
|
|
* @method LineItem setDistributionChannel(ChannelReference $distributionChannel = null) |
|
45
|
|
|
* @method CustomFieldObject getCustom() |
|
46
|
|
|
* @method LineItem setCustom(CustomFieldObject $custom = null) |
|
47
|
|
|
* @method Money getTotalPrice() |
|
48
|
|
|
* @method LineItem setTotalPrice(Money $totalPrice = null) |
|
49
|
|
|
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity() |
|
50
|
|
|
* @method TaxedItemPrice getTaxedPrice() |
|
51
|
|
|
* @method LineItem setTaxedPrice(TaxedItemPrice $taxedPrice = null) |
|
52
|
|
|
* @method string getPriceMode() |
|
53
|
|
|
* @method LineItem setPriceMode(string $priceMode = null) |
|
54
|
|
|
* @method ProductTypeReference getProductType() |
|
55
|
|
|
* @method LineItem setProductType(ProductTypeReference $productType = null) |
|
56
|
|
|
* @method string getLineItemMode() |
|
57
|
|
|
* @method LineItem setLineItemMode(string $lineItemMode = null) |
|
58
|
|
|
*/ |
|
59
|
|
|
class LineItem extends JsonObject |
|
60
|
|
|
{ |
|
61
|
|
|
const PRICE_MODE_PLATFORM = 'Platform'; |
|
62
|
|
|
const PRICE_MODE_EXTERNAL_TOTAL = 'ExternalTotal'; |
|
63
|
|
|
const PRICE_MODE_EXTERNAL_PRICE = 'ExternalPrice'; |
|
64
|
|
|
|
|
65
|
|
|
const LINE_ITEM_MODE_STANDARD = 'Standard'; |
|
66
|
|
|
const LINE_ITEM_MODE_GIFT_LINE_ITEM = 'GiftLineItem'; |
|
67
|
|
|
|
|
68
|
38 |
|
public function fieldDefinitions() |
|
69
|
|
|
{ |
|
70
|
|
|
return [ |
|
71
|
38 |
|
'id' => [static::TYPE => 'string'], |
|
72
|
38 |
|
'productId' => [static::TYPE => 'string'], |
|
73
|
38 |
|
'name' => [static::TYPE => LocalizedString::class], |
|
74
|
38 |
|
'productSlug' => [static::TYPE => LocalizedString::class], |
|
75
|
38 |
|
'variant' => [static::TYPE => ProductVariant::class], |
|
76
|
38 |
|
'price' => [static::TYPE => Price::class], |
|
77
|
38 |
|
'taxedPrice' => [static::TYPE => TaxedItemPrice::class], |
|
78
|
38 |
|
'quantity' => [static::TYPE => 'int'], |
|
79
|
38 |
|
'state' => [static::TYPE => ItemStateCollection::class], |
|
80
|
38 |
|
'taxRate' => [static::TYPE => TaxRate::class], |
|
81
|
38 |
|
'supplyChannel' => [static::TYPE => ChannelReference::class], |
|
82
|
38 |
|
'distributionChannel' => [static::TYPE => ChannelReference::class], |
|
83
|
38 |
|
'custom' => [static::TYPE => CustomFieldObject::class], |
|
84
|
38 |
|
'totalPrice' => [static::TYPE => Money::class], |
|
85
|
|
|
'discountedPricePerQuantity' => [ |
|
86
|
38 |
|
static::TYPE => DiscountedPricePerQuantityCollection::class |
|
87
|
|
|
], |
|
88
|
38 |
|
'priceMode' => [static::TYPE => 'string'], |
|
89
|
38 |
|
'lineItemMode' => [static::TYPE => 'string'], |
|
90
|
38 |
|
'productType' => [static::TYPE => ProductTypeReference::class], |
|
91
|
|
|
]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param DiscountedPricePerQuantityCollection $discountedPricePerQuantity |
|
96
|
|
|
* @return static |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setDiscountedPricePerQuantity( |
|
99
|
|
|
DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null |
|
100
|
|
|
) { |
|
101
|
|
|
return parent::setDiscountedPricePerQuantity($discountedPricePerQuantity); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return Money |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getDiscountedPrice() |
|
108
|
|
|
{ |
|
109
|
|
|
$centAmount = 0; |
|
110
|
|
|
$currencyCode = $this->getPrice()->getValue()->getCurrencyCode(); |
|
111
|
|
|
foreach ($this->getDiscountedPricePerQuantity() as $discountedPricePerQuantity) { |
|
112
|
|
|
$centAmount += $discountedPricePerQuantity->getDiscountedTotal()->getCentAmount(); |
|
113
|
|
|
} |
|
114
|
|
|
$this->getDiscountedPricePerQuantity()->rewind(); |
|
115
|
|
|
return Money::ofCurrencyAndAmount($currencyCode, $centAmount); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|