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

Commit 1c22189

Browse files
author
Jens Schulze
committed
feat(Cart): support tax rounding mode
Closes #290
1 parent e617272 commit 1c22189

File tree

7 files changed

+103
-2
lines changed

7 files changed

+103
-2
lines changed

src/Model/Cart/Cart.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
* @method string getAnonymousId()
6464
* @method Cart setAnonymousId(string $anonymousId = null)
6565
* @method string getLocale()
66+
* @method string getTaxRoundingMode()
67+
* @method Cart setTaxRoundingMode(string $taxRoundingMode = null)
6668
* @method CartReference getReference()
6769
*/
6870
class Cart extends Resource
@@ -72,6 +74,9 @@ class Cart extends Resource
7274
const TAX_MODE_PLATFORM = 'Platform';
7375
const TAX_MODE_EXTERNAL = 'External';
7476
const TAX_MODE_DISABLED = 'Disabled';
77+
const TAX_ROUNDING_MODE_HALF_EVEN = 'HalfEven';
78+
const TAX_ROUNDING_MODE_HALF_UP = 'HalfUp';
79+
const TAX_ROUNDING_MODE_HALF_DOWN = 'HalfDown';
7580

7681
public function fieldDefinitions()
7782
{
@@ -105,6 +110,7 @@ public function fieldDefinitions()
105110
'taxMode' => [static::TYPE => 'string'],
106111
'anonymousId' => [static::TYPE => 'string'],
107112
'locale' => [static::TYPE => 'string'],
113+
'taxRoundingMode' => [static::TYPE => 'string'],
108114
];
109115
}
110116

src/Model/Cart/CartDraft.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
* @method string getAnonymousId()
4343
* @method CartDraft setAnonymousId(string $anonymousId = null)
4444
* @method string getLocale()
45+
* @method string getTaxRoundingMode()
46+
* @method CartDraft setTaxRoundingMode(string $taxRoundingMode = null)
4547
*/
4648
class CartDraft extends JsonObject
4749
{
@@ -64,6 +66,7 @@ public function fieldDefinitions()
6466
'taxMode' => [static::TYPE => 'string'],
6567
'anonymousId' => [static::TYPE => 'string'],
6668
'locale' => [static::TYPE => 'string'],
69+
'taxRoundingMode' => [static::TYPE => 'string'],
6770
];
6871
}
6972

src/Model/Order/ImportOrder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
* @method ImportOrder setCustom(CustomFieldObjectDraft $custom = null)
5555
* @method string getInventoryMode()
5656
* @method ImportOrder setInventoryMode(string $inventoryMode = null)
57+
* @method string getTaxRoundingMode()
58+
* @method ImportOrder setTaxRoundingMode(string $taxRoundingMode = null)
5759
*/
5860
class ImportOrder extends JsonObject
5961
{
@@ -81,6 +83,7 @@ public function fieldDefinitions()
8183
],
8284
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
8385
'inventoryMode' => [static::TYPE => 'string'],
86+
'taxRoundingMode' => [static::TYPE => 'string'],
8487
];
8588
}
8689
}

src/Model/Order/Order.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@
8585
* @method string getAnonymousId()
8686
* @method Order setAnonymousId(string $anonymousId = null)
8787
* @method string getLocale()
88+
* @method string getTaxRoundingMode()
89+
* @method Order setTaxRoundingMode(string $taxRoundingMode = null)
8890
* @method OrderReference getReference()
8991
*/
9092
class Order extends Resource
9193
{
94+
const TAX_MODE_PLATFORM = 'Platform';
95+
const TAX_MODE_EXTERNAL = 'External';
96+
const TAX_MODE_DISABLED = 'Disabled';
97+
const TAX_ROUNDING_MODE_HALF_EVEN = 'HalfEven';
98+
const TAX_ROUNDING_MODE_HALF_UP = 'HalfUp';
99+
const TAX_ROUNDING_MODE_HALF_DOWN = 'HalfDown';
100+
92101
use LocaleTrait;
93102

94103
public function fieldDefinitions()
@@ -134,6 +143,7 @@ public function fieldDefinitions()
134143
'paymentInfo' => [static::TYPE => '\Commercetools\Core\Model\Payment\PaymentInfo'],
135144
'anonymousId' => [static::TYPE => 'string'],
136145
'locale' => [static::TYPE => 'string'],
146+
'taxRoundingMode' => [static::TYPE => 'string'],
137147
];
138148
}
139149
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Carts\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Carts\Command
13+
* @link http://dev.commercetools.com/http-api-projects-carts.html#change-tax-roundingmode
14+
* @method string getAction()
15+
* @method CartChangeTaxRoundingModeAction setAction(string $action = null)
16+
* @method string getTaxRoundingMode()
17+
* @method CartChangeTaxRoundingModeAction setTaxRoundingMode(string $taxRoundingMode = null)
18+
*/
19+
class CartChangeTaxRoundingModeAction extends AbstractAction
20+
{
21+
public function fieldDefinitions()
22+
{
23+
return [
24+
'action' => [static::TYPE => 'string'],
25+
'taxRoundingMode' => [static::TYPE => 'string'],
26+
];
27+
}
28+
29+
/**
30+
* @param array $data
31+
* @param Context|callable $context
32+
*/
33+
public function __construct(array $data = [], $context = null)
34+
{
35+
parent::__construct($data, $context);
36+
$this->setAction('changeTaxRoundingMode');
37+
}
38+
39+
/**
40+
* @param string $roundingMode
41+
* @param Context|callable $context
42+
* @return CartChangeLineItemQuantityAction
43+
*/
44+
public static function ofTaxRoundingMode($roundingMode, $context = null)
45+
{
46+
return static::of($context)->setTaxRoundingMode($roundingMode);
47+
}
48+
}

tests/fixtures/models.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cart:
2525
- taxMode
2626
- anonymousId
2727
- locale
28+
- taxRoundingMode
2829
lineItem:
2930
domain: cart
3031
model: LineItem
@@ -365,6 +366,7 @@ order:
365366
- paymentInfo
366367
- anonymousId
367368
- locale
369+
- taxRoundingMode
368370
syncInfo:
369371
domain: order
370372
model: SyncInfo
@@ -850,7 +852,7 @@ importOrder:
850852
- completedAt
851853
- custom
852854
- inventoryMode
853-
855+
- taxRoundingMode
854856
lineItemImportDraft:
855857
domain: order
856858
model: lineItemImportDraft

tests/integration/Cart/CartUpdateRequestTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Commercetools\Core\Cart;
77

88
use Commercetools\Core\ApiTestCase;
9+
use Commercetools\Core\Model\Cart\Cart;
910
use Commercetools\Core\Model\Cart\CartDraft;
1011
use Commercetools\Core\Model\Cart\CustomLineItemDraft;
1112
use Commercetools\Core\Model\Cart\CustomLineItemDraftCollection;
@@ -39,6 +40,7 @@
3940
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemMoneyAction;
4041
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemQuantityAction;
4142
use Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction;
43+
use Commercetools\Core\Request\Carts\Command\CartChangeTaxRoundingModeAction;
4244
use Commercetools\Core\Request\Carts\Command\CartRecalculateAction;
4345
use Commercetools\Core\Request\Carts\Command\CartRemoveCustomLineItemAction;
4446
use Commercetools\Core\Request\Carts\Command\CartRemoveDiscountCodeAction;
@@ -276,7 +278,7 @@ public function testUnsetExternalLineItemPriceQuantityChange()
276278
$this->assertSame(100, $cart->getLineItems()->current()->getPrice()->getValue()->getCentAmount());
277279
$this->assertSame(200, $cart->getLineItems()->current()->getTotalPrice()->getCentAmount());
278280
}
279-
281+
280282
public function testCustomLineItem()
281283
{
282284
$draft = $this->getDraft();
@@ -1112,6 +1114,33 @@ public function testInvalidLocale($locale)
11121114
$this->assertTrue($response->isError());
11131115
}
11141116

1117+
public function testTaxRoundingMode()
1118+
{
1119+
$draft = $this->getDraft();
1120+
$cart = $this->createCart($draft);
1121+
1122+
$this->assertSame(Cart::TAX_ROUNDING_MODE_HALF_EVEN, $cart->getTaxRoundingMode());
1123+
1124+
$request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion())
1125+
->addAction(CartChangeTaxRoundingModeAction::ofTaxRoundingMode(Cart::TAX_ROUNDING_MODE_HALF_DOWN))
1126+
;
1127+
$response = $request->executeWithClient($this->getClient());
1128+
$cart = $request->mapResponse($response);
1129+
1130+
$this->deleteRequest->setVersion($cart->getVersion());
1131+
1132+
$this->assertSame(Cart::TAX_ROUNDING_MODE_HALF_DOWN, $cart->getTaxRoundingMode());
1133+
}
1134+
1135+
public function testCreateWithTaxRoundingMode()
1136+
{
1137+
$draft = $this->getDraft();
1138+
$draft->setTaxRoundingMode(Cart::TAX_ROUNDING_MODE_HALF_DOWN);
1139+
$cart = $this->createCart($draft);
1140+
1141+
$this->assertSame(Cart::TAX_ROUNDING_MODE_HALF_DOWN, $cart->getTaxRoundingMode());
1142+
}
1143+
11151144
/**
11161145
* @return CartDraft
11171146
*/

0 commit comments

Comments
 (0)