|
11 | 11 | use Commercetools\Core\Model\Cart\CustomLineItemDraft; |
12 | 12 | use Commercetools\Core\Model\Cart\CustomLineItemDraftCollection; |
13 | 13 | use Commercetools\Core\Model\Cart\ExternalLineItemTotalPrice; |
| 14 | +use Commercetools\Core\Model\Cart\ExternalTaxAmountDraft; |
14 | 15 | use Commercetools\Core\Model\Cart\LineItem; |
15 | 16 | use Commercetools\Core\Model\Cart\LineItemCollection; |
16 | 17 | use Commercetools\Core\Model\Cart\LineItemDraft; |
|
31 | 32 | use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
32 | 33 | use Commercetools\Core\Model\CustomField\FieldContainer; |
33 | 34 | use Commercetools\Core\Model\ShippingMethod\ShippingRate; |
| 35 | +use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft; |
34 | 36 | use Commercetools\Core\Request\CartDiscounts\CartDiscountCreateRequest; |
35 | 37 | use Commercetools\Core\Request\Carts\CartByIdGetRequest; |
36 | 38 | use Commercetools\Core\Request\Carts\CartCreateRequest; |
|
52 | 54 | use Commercetools\Core\Request\Carts\Command\CartRemovePaymentAction; |
53 | 55 | use Commercetools\Core\Request\Carts\Command\CartSetAnonymousIdAction; |
54 | 56 | use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressAction; |
| 57 | +use Commercetools\Core\Request\Carts\Command\CartSetCartTotalTaxAction; |
55 | 58 | use Commercetools\Core\Request\Carts\Command\CartSetCountryAction; |
56 | 59 | use Commercetools\Core\Request\Carts\Command\CartSetCustomerEmailAction; |
57 | 60 | use Commercetools\Core\Request\Carts\Command\CartSetCustomerGroupAction; |
58 | 61 | use Commercetools\Core\Request\Carts\Command\CartSetCustomerIdAction; |
59 | 62 | use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomFieldAction; |
60 | 63 | use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomTypeAction; |
| 64 | +use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxAmountAction; |
61 | 65 | use Commercetools\Core\Request\Carts\Command\CartSetCustomShippingMethodAction; |
62 | 66 | use Commercetools\Core\Request\Carts\Command\CartSetDeleteDaysAfterLastModificationAction; |
63 | 67 | use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction; |
64 | 68 | use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction; |
65 | 69 | use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction; |
| 70 | +use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction; |
66 | 71 | use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction; |
67 | 72 | use Commercetools\Core\Request\Carts\Command\CartSetLocaleAction; |
68 | 73 | use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressAction; |
69 | 74 | use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodAction; |
| 75 | +use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxAmountAction; |
70 | 76 | use Commercetools\Core\Request\Customers\CustomerLoginRequest; |
71 | 77 | use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction; |
72 | 78 | use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction; |
@@ -1512,6 +1518,119 @@ public function testGiftLineItem() |
1512 | 1518 | $this->assertTrue($giftLineItemIncluded); |
1513 | 1519 | } |
1514 | 1520 |
|
| 1521 | + public function testSetLineItemTaxAmount() |
| 1522 | + { |
| 1523 | + $product = $this->getProduct(); |
| 1524 | + $variant = $product->getMasterData()->getCurrent()->getMasterVariant(); |
| 1525 | + |
| 1526 | + $draft = $this->getDraft(); |
| 1527 | + $draft->setLineItems(LineItemDraftCollection::of()->add(LineItemDraft::ofSku($variant->getSku()))); |
| 1528 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL_AMOUNT); |
| 1529 | + $cart = $this->createCart($draft); |
| 1530 | + |
| 1531 | + $taxAmount = mt_rand(1, 100000); |
| 1532 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1533 | + ->addAction( |
| 1534 | + CartSetLineItemTaxAmountAction::of() |
| 1535 | + ->setLineItemId($cart->getLineItems()->current()->getId()) |
| 1536 | + ->setExternalTaxAmount( |
| 1537 | + ExternalTaxAmountDraft::of() |
| 1538 | + ->setTotalGross(Money::ofCurrencyAndAmount('EUR', $taxAmount)) |
| 1539 | + ->setTaxRate(ExternalTaxRateDraft::ofNameCountryAndAmount('test', 'DE', 1.0)) |
| 1540 | + ) |
| 1541 | + ); |
| 1542 | + $response = $request->executeWithClient($this->getClient()); |
| 1543 | + $cart = $request->mapResponse($response); |
| 1544 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1545 | + |
| 1546 | + $this->assertSame($taxAmount, $cart->getLineItems()->current()->getTaxedPrice()->getTotalGross()->getCentAmount()); |
| 1547 | + } |
| 1548 | + |
| 1549 | + public function testSetCustomLineItemTaxAmount() |
| 1550 | + { |
| 1551 | + $draft = $this->getDraft(); |
| 1552 | + $draft->setCustomLineItems( |
| 1553 | + CustomLineItemDraftCollection::of() |
| 1554 | + ->add( |
| 1555 | + CustomLineItemDraft::of() |
| 1556 | + ->setName(LocalizedString::ofLangAndText('en','test')) |
| 1557 | + ->setQuantity(1) |
| 1558 | + ->setMoney(Money::ofCurrencyAndAmount('EUR', 100)) |
| 1559 | + ->setSlug('test-124') |
| 1560 | + ) |
| 1561 | + ); |
| 1562 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL_AMOUNT); |
| 1563 | + $cart = $this->createCart($draft); |
| 1564 | + |
| 1565 | + $taxAmount = mt_rand(1, 100000); |
| 1566 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1567 | + ->addAction( |
| 1568 | + CartSetCustomLineItemTaxAmountAction::of() |
| 1569 | + ->setCustomLineItemId($cart->getCustomLineItems()->current()->getId()) |
| 1570 | + ->setExternalTaxAmount( |
| 1571 | + ExternalTaxAmountDraft::of() |
| 1572 | + ->setTotalGross(Money::ofCurrencyAndAmount('EUR', $taxAmount)) |
| 1573 | + ->setTaxRate(ExternalTaxRateDraft::ofNameCountryAndAmount('test', 'DE', 1.0)) |
| 1574 | + ) |
| 1575 | + ); |
| 1576 | + $response = $request->executeWithClient($this->getClient()); |
| 1577 | + $cart = $request->mapResponse($response); |
| 1578 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1579 | + |
| 1580 | + $this->assertSame($taxAmount, $cart->getCustomLineItems()->current()->getTaxedPrice()->getTotalGross()->getCentAmount()); |
| 1581 | + } |
| 1582 | + |
| 1583 | + public function testSetShippingMethodTaxAmount() |
| 1584 | + { |
| 1585 | + $shippingMethod = $this->getShippingMethod(); |
| 1586 | + $draft = $this->getDraft(); |
| 1587 | + $draft->setShippingAddress(Address::of()->setCountry('DE')->setState($this->getRegion())); |
| 1588 | + $draft->setShippingMethod($shippingMethod->getReference()); |
| 1589 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL_AMOUNT); |
| 1590 | + $cart = $this->createCart($draft); |
| 1591 | + |
| 1592 | + $taxAmount = mt_rand(1, 100000); |
| 1593 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1594 | + ->addAction( |
| 1595 | + CartSetShippingMethodTaxAmountAction::of() |
| 1596 | + ->setExternalTaxAmount( |
| 1597 | + ExternalTaxAmountDraft::of() |
| 1598 | + ->setTotalGross(Money::ofCurrencyAndAmount('EUR', $taxAmount)) |
| 1599 | + ->setTaxRate(ExternalTaxRateDraft::ofNameCountryAndAmount('test', 'DE', 1.0)) |
| 1600 | + ) |
| 1601 | + ); |
| 1602 | + $response = $request->executeWithClient($this->getClient()); |
| 1603 | + $cart = $request->mapResponse($response); |
| 1604 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1605 | + |
| 1606 | + $this->assertSame($taxAmount, $cart->getShippingInfo()->getTaxedPrice()->getTotalGross()->getCentAmount()); |
| 1607 | + } |
| 1608 | + |
| 1609 | + public function testSetTotalTaxAmount() |
| 1610 | + { |
| 1611 | + $product = $this->getProduct(); |
| 1612 | + $variant = $product->getMasterData()->getCurrent()->getMasterVariant(); |
| 1613 | + |
| 1614 | + $draft = $this->getDraft(); |
| 1615 | + $draft->setLineItems(LineItemDraftCollection::of()->add(LineItemDraft::ofSku($variant->getSku()))); |
| 1616 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL_AMOUNT); |
| 1617 | + $cart = $this->createCart($draft); |
| 1618 | + |
| 1619 | + $taxAmount = mt_rand(1, 100000); |
| 1620 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1621 | + ->addAction( |
| 1622 | + CartSetCartTotalTaxAction::of() |
| 1623 | + ->setExternalTotalGross( |
| 1624 | + Money::ofCurrencyAndAmount('EUR', $taxAmount) |
| 1625 | + ) |
| 1626 | + ); |
| 1627 | + $response = $request->executeWithClient($this->getClient()); |
| 1628 | + $cart = $request->mapResponse($response); |
| 1629 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1630 | + |
| 1631 | + $this->assertSame($taxAmount, $cart->getTaxedPrice()->getTotalGross()->getCentAmount()); |
| 1632 | + } |
| 1633 | + |
1515 | 1634 | /** |
1516 | 1635 | * @return CartDraft |
1517 | 1636 | */ |
|
0 commit comments