Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit b0bf1b7

Browse files
author
Jens Schulze
committed
fix(Cart): add corrected cart discount fields
1 parent ea50790 commit b0bf1b7

File tree

7 files changed

+72
-34
lines changed

7 files changed

+72
-34
lines changed

src/Model/Cart/CustomLineItem.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
* @method CustomLineItem setTaxRate(TaxRate $taxRate = null)
3535
* @method CustomFieldObject getCustom()
3636
* @method CustomLineItem setCustom(CustomFieldObject $custom = null)
37+
* @method Money getTotalPrice()
38+
* @method CustomLineItem setTotalPrice(Money $totalPrice = null)
39+
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
40+
* @codingStandardsIgnoreStart
41+
* @method CustomLineItem setDiscountedPricePerQuantity(DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null)
42+
* @codingStandardsIgnoreEnd
3743
*/
3844
class CustomLineItem extends JsonObject
3945
{
@@ -49,6 +55,10 @@ public function fieldDefinitions()
4955
'taxCategory' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference'],
5056
'taxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxRate'],
5157
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
58+
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
59+
'discountedPricePerQuantity' => [
60+
static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantityCollection'
61+
],
5262
];
5363
}
5464
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
* @apidoc http://dev.sphere.io/http-api-projects-carts.html#discounted-line-item-price-for-quantity
13+
* @method int getQuantity()
14+
* @method DiscountedPricePerQuantity setQuantity(int $quantity = null)
15+
* @method DiscountedLineItemPrice getDiscountedPrice()
16+
* @method DiscountedPricePerQuantity setDiscountedPrice(DiscountedLineItemPrice $discountedPrice = null)
17+
*/
18+
class DiscountedPricePerQuantity extends JsonObject
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'quantity' => [static::TYPE => 'int'],
24+
'discountedPrice' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedLineItemPrice']
25+
];
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\Collection;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
*
13+
* @method DiscountedPricePerQuantityCollection add(DiscountedPricePerQuantity $element)
14+
* @method DiscountedPricePerQuantity current()
15+
* @method DiscountedPricePerQuantity getAt($offset)
16+
*/
17+
class DiscountedPricePerQuantityCollection extends Collection
18+
{
19+
protected $type = '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantity';
20+
}

src/Model/Cart/LineItem.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
* @method LineItem setDistributionChannel(ChannelReference $distributionChannel = null)
4646
* @method CustomFieldObject getCustom()
4747
* @method LineItem setCustom(CustomFieldObject $custom = null)
48+
* @method Money getTotalPrice()
49+
* @method LineItem setTotalPrice(Money $totalPrice = null)
50+
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
51+
* @codingStandardsIgnoreStart
52+
* @method LineItem setDiscountedPricePerQuantity(DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null)
53+
* @codingStandardsIgnoreEnd
4854
*/
4955
class LineItem extends JsonObject
5056
{
@@ -61,19 +67,12 @@ public function fieldDefinitions()
6167
'state' => [static::TYPE => '\Commercetools\Core\Model\Order\ItemStateCollection'],
6268
'taxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxRate'],
6369
'supplyChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
64-
'discountedPrice' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedLineItemPrice'],
6570
'distributionChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
6671
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
72+
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
73+
'discountedPricePerQuantity' => [
74+
static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantityCollection'
75+
],
6776
];
6877
}
69-
70-
/**
71-
* @return Money
72-
*/
73-
public function getTotal()
74-
{
75-
$price = $this->getPrice()->getValue();
76-
$amount = $this->getQuantity() * $price->getCentAmount();
77-
return Money::ofCurrencyAndAmount($price->getCurrencyCode(), $amount, $this->getContext());
78-
}
7978
}

src/Model/Order/Order.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1919
use Commercetools\Core\Model\Common\DateTimeDecorator;
2020
use Commercetools\Core\Model\State\StateReference;
21+
use Commercetools\Core\Model\Payment\PaymentInfo;
2122

2223
/**
2324
* @package Commercetools\Core\Model\Order

tests/fixtures/models.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ lineItem:
3838
- taxRate
3939
- supplyChannel
4040
- distributionChannel
41-
- discountedPrice
4241
- custom
42+
- discountedPricePerQuantity
43+
- totalPrice
4344

4445
customLineItem:
4546
domain: cart
@@ -54,6 +55,8 @@ customLineItem:
5455
- taxCategory
5556
- taxRate
5657
- custom
58+
- discountedPricePerQuantity
59+
- totalPrice
5760

5861
taxedPrice:
5962
domain: common

tests/unit/Model/Cart/LineItemTest.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)