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

Commit 940e90a

Browse files
author
jayS-de
committed
Merge pull request #216 from sphereio/feature-js-cart_tax_modes_#207
Cart tax modes #207
2 parents e4c10ed + 57f9b0e commit 940e90a

19 files changed

+906
-5
lines changed

src/Model/Cart/Cart.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@
5757
* @method Cart setCustom(CustomFieldObject $custom = null)
5858
* @method PaymentInfo getPaymentInfo()
5959
* @method Cart setPaymentInfo(PaymentInfo $paymentInfo = null)
60+
* @method string getTaxMode()
61+
* @method Cart setTaxMode(string $taxMode = null)
6062
* @method CartReference getReference()
6163
*/
6264
class Cart extends Resource
6365
{
66+
const TAX_MODE_PLATFORM = 'Platform';
67+
const TAX_MODE_EXTERNAL = 'External';
68+
const TAX_MODE_DISABLED = 'Disabled';
69+
6470
public function fieldDefinitions()
6571
{
6672
return [
@@ -90,6 +96,7 @@ public function fieldDefinitions()
9096
'discountCodes' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountCodeInfoCollection'],
9197
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
9298
'paymentInfo' => [static::TYPE => '\Commercetools\Core\Model\Payment\PaymentInfo'],
99+
'taxMode' => [static::TYPE => 'string'],
93100
];
94101
}
95102

src/Model/Cart/CartDraft.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
* @method CartDraft setShippingMethod(ShippingMethodReference $shippingMethod = null)
3737
* @method CustomLineItemDraftCollection getCustomLineItems()
3838
* @method CartDraft setCustomLineItems(CustomLineItemDraftCollection $customLineItems = null)
39+
* @method string getTaxMode()
40+
* @method CartDraft setTaxMode(string $taxMode = null)
3941
*/
4042
class CartDraft extends JsonObject
4143
{
@@ -53,6 +55,7 @@ public function fieldDefinitions()
5355
'billingAddress' => [static::TYPE => '\Commercetools\Core\Model\Common\Address'],
5456
'shippingMethod' => [static::TYPE => '\Commercetools\Core\Model\ShippingMethod\ShippingMethodReference'],
5557
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
58+
'taxMode' => [static::TYPE => 'string'],
5659
];
5760
}
5861

src/Model/Cart/CustomLineItemDraft.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
1313
use Commercetools\Core\Model\TaxCategory\TaxRate;
1414
use Commercetools\Core\Model\CustomField\CustomFieldObject;
15+
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
1516

1617
/**
1718
* @package Commercetools\Core\Model\Cart
@@ -28,6 +29,8 @@
2829
* @method CustomLineItemDraft setTaxCategory(TaxCategoryReference $taxCategory = null)
2930
* @method CustomFieldObject getCustom()
3031
* @method CustomLineItemDraft setCustom(CustomFieldObject $custom = null)
32+
* @method ExternalTaxRateDraft getExternalTaxRate()
33+
* @method CustomLineItemDraft setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
3134
*/
3235
class CustomLineItemDraft extends JsonObject
3336
{
@@ -39,6 +42,7 @@ public function fieldDefinitions()
3942
'slug' => [static::TYPE => 'string'],
4043
'quantity' => [static::TYPE => 'int'],
4144
'taxCategory' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference'],
45+
'externalTaxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft'],
4246
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
4347
];
4448
}

src/Model/Cart/LineItemDraft.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Commercetools\Core\Model\Product\ProductVariant;
1616
use Commercetools\Core\Model\TaxCategory\TaxRate;
1717
use Commercetools\Core\Model\CustomField\CustomFieldObject;
18+
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
1819

1920
/**
2021
* @package Commercetools\Core\Model\Cart
@@ -31,6 +32,8 @@
3132
* @method LineItemDraft setDistributionChannel(ChannelReference $distributionChannel = null)
3233
* @method CustomFieldObject getCustom()
3334
* @method LineItemDraft setCustom(CustomFieldObject $custom = null)
35+
* @method ExternalTaxRateDraft getExternalTaxRate()
36+
* @method LineItemDraft setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
3437
*/
3538
class LineItemDraft extends JsonObject
3639
{
@@ -42,6 +45,7 @@ public function fieldDefinitions()
4245
'quantity' => [static::TYPE => 'int'],
4346
'supplyChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
4447
'distributionChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
48+
'externalTaxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft'],
4549
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
4650
];
4751
}

src/Model/Common/TaxPortion.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
* @method TaxPortion setRate(float $rate = null)
1313
* @method Money getAmount()
1414
* @method TaxPortion setAmount(Money $amount = null)
15+
* @method string getName()
16+
* @method TaxPortion setName(string $name = null)
1517
*/
1618
class TaxPortion extends JsonObject
1719
{
1820
public function fieldDefinitions()
1921
{
2022
return [
23+
'name' => [static::TYPE => 'string'],
2124
'rate' => [static::TYPE => 'float'],
2225
'amount' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
2326
];
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\TaxCategory;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\TaxCategory
12+
* @link http://dev.commercetools.com/http-api-projects-carts.html#externaltaxratedraft
13+
* @method string getName()
14+
* @method ExternalTaxRateDraft setName(string $name = null)
15+
* @method float getAmount()
16+
* @method ExternalTaxRateDraft setAmount(float $amount = null)
17+
* @method string getCountry()
18+
* @method ExternalTaxRateDraft setCountry(string $country = null)
19+
* @method string getState()
20+
* @method ExternalTaxRateDraft setState(string $state = null)
21+
* @method SubRateCollection getSubRates()
22+
* @method ExternalTaxRateDraft setSubRates(SubRateCollection $subRates = null)
23+
*/
24+
class ExternalTaxRateDraft extends JsonObject
25+
{
26+
public function fieldDefinitions()
27+
{
28+
return [
29+
'name' => [self::TYPE => 'string'],
30+
'amount' => [self::TYPE => 'float'],
31+
'country' => [self::TYPE => 'string'],
32+
'state' => [self::TYPE => 'string'],
33+
'subRates' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\SubRateCollection']
34+
];
35+
}
36+
37+
/**
38+
* @param string $name
39+
* @param string $country
40+
* @param float $amount
41+
* @return ExternalTaxRateDraft
42+
*/
43+
public static function ofNameCountryAndAmount($name, $country, $amount)
44+
{
45+
return static::of()->setName($name)->setCountry($country)->setAmount($amount);
46+
}
47+
48+
/**
49+
* @param string $name
50+
* @param string $country
51+
* @param float $amount
52+
* @param SubRateCollection $subRates
53+
* @return ExternalTaxRateDraft
54+
*/
55+
public static function ofNameCountryAmountAndSubRates($name, $country, $amount, SubRateCollection $subRates)
56+
{
57+
return static::of()->setName($name)->setCountry($country)->setAmount($amount)->setSubRates($subRates);
58+
}
59+
60+
/**
61+
* @param string $name
62+
* @param string $country
63+
* @param SubRateCollection $subRates
64+
* @return ExternalTaxRateDraft
65+
*/
66+
public static function ofNameCountryAndSubRates($name, $country, SubRateCollection $subRates)
67+
{
68+
return static::of()->setName($name)->setCountry($country)->setSubRates($subRates);
69+
}
70+
}

src/Model/TaxCategory/SubRate.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\TaxCategory;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\TaxCategory
12+
*
13+
* @method string getName()
14+
* @method SubRate setName(string $name = null)
15+
* @method float getAmount()
16+
* @method SubRate setAmount(float $amount = null)
17+
*/
18+
class SubRate extends JsonObject
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'name' => [self::TYPE => 'string'],
24+
'amount' => [self::TYPE => 'float'],
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 @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\TaxCategory;
7+
8+
use Commercetools\Core\Model\Common\Collection;
9+
10+
/**
11+
* @package Commercetools\Core\Model\TaxCategory
12+
*
13+
* @method SubRateCollection add(SubRate $element)
14+
* @method SubRate current()
15+
* @method SubRate getAt($offset)
16+
*/
17+
class SubRateCollection extends Collection
18+
{
19+
protected $type = '\Commercetools\Core\Model\TaxCategory\SubRate';
20+
}

src/Model/TaxCategory/TaxRate.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @method TaxRate setCountry(string $country = null)
2323
* @method string getState()
2424
* @method TaxRate setState(string $state = null)
25+
* @method SubRateCollection getSubRates()
26+
* @method TaxRate setSubRates(SubRateCollection $subRates = null)
2527
*/
2628
class TaxRate extends JsonObject
2729
{
@@ -33,7 +35,8 @@ public function fieldDefinitions()
3335
'amount' => [self::TYPE => 'float'],
3436
'includedInPrice' => [self::TYPE => 'bool'],
3537
'country' => [self::TYPE => 'string'],
36-
'state' => [self::TYPE => 'string']
38+
'state' => [self::TYPE => 'string'],
39+
'subRates' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\SubRateCollection']
3740
];
3841
}
3942
}

src/Request/Carts/Command/CartAddCustomLineItemAction.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Commercetools\Core\Request\AbstractAction;
1313
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
1414
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
15+
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
1516

1617
/**
1718
* @package Commercetools\Core\Request\Carts\Command
@@ -30,6 +31,8 @@
3031
* @method CartAddCustomLineItemAction setTaxCategory(TaxCategoryReference $taxCategory = null)
3132
* @method CustomFieldObjectDraft getCustom()
3233
* @method CartAddCustomLineItemAction setCustom(CustomFieldObjectDraft $custom = null)
34+
* @method ExternalTaxRateDraft getExternalTaxRate()
35+
* @method CartAddCustomLineItemAction setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
3336
*/
3437
class CartAddCustomLineItemAction extends AbstractAction
3538
{
@@ -43,6 +46,7 @@ public function fieldDefinitions()
4346
'slug' => [static::TYPE => 'string'],
4447
'taxCategory' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference'],
4548
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
49+
'externalTaxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft'],
4650
];
4751
}
4852

@@ -80,4 +84,20 @@ public static function ofNameQuantityMoneySlugAndTaxCategory(
8084
->setSlug($slug)
8185
->setTaxCategory($taxCategory);
8286
}
87+
88+
public static function ofNameQuantityMoneySlugAndExternalTaxRate(
89+
LocalizedString $name,
90+
$quantity,
91+
Money $money,
92+
$slug,
93+
ExternalTaxRateDraft $externalTaxRate,
94+
$context = null
95+
) {
96+
return static::of($context)
97+
->setName($name)
98+
->setQuantity($quantity)
99+
->setMoney($money)
100+
->setSlug($slug)
101+
->setExternalTaxRate($externalTaxRate);
102+
}
83103
}

0 commit comments

Comments
 (0)