|
14 | 14 | use Commercetools\Core\Model\Cart\CustomLineItemCollection; |
15 | 15 | use Commercetools\Core\Model\Cart\CustomLineItemDraft; |
16 | 16 | use Commercetools\Core\Model\Cart\CustomLineItemDraftCollection; |
| 17 | +use Commercetools\Core\Model\Cart\LineItemCollection; |
| 18 | +use Commercetools\Core\Model\Cart\LineItemDraft; |
| 19 | +use Commercetools\Core\Model\Cart\LineItemDraftCollection; |
17 | 20 | use Commercetools\Core\Model\Common\Address; |
18 | 21 | use Commercetools\Core\Model\Common\LocalizedString; |
19 | 22 | use Commercetools\Core\Model\Common\Money; |
|
33 | 36 | use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction; |
34 | 37 | use Commercetools\Core\Request\Carts\Command\CartAddPaymentAction; |
35 | 38 | use Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction; |
| 39 | +use Commercetools\Core\Request\Carts\Command\CartChangeTaxModeAction; |
36 | 40 | use Commercetools\Core\Request\Carts\Command\CartRecalculateAction; |
37 | 41 | use Commercetools\Core\Request\Carts\Command\CartRemoveCustomLineItemAction; |
38 | 42 | use Commercetools\Core\Request\Carts\Command\CartRemoveDiscountCodeAction; |
|
44 | 48 | use Commercetools\Core\Request\Carts\Command\CartSetCustomerIdAction; |
45 | 49 | use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomFieldAction; |
46 | 50 | use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomTypeAction; |
| 51 | +use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxRateAction; |
47 | 52 | use Commercetools\Core\Request\Carts\Command\CartSetCustomShippingMethodAction; |
48 | 53 | use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction; |
49 | 54 | use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction; |
| 55 | +use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxRateAction; |
50 | 56 | use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressAction; |
51 | 57 | use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodAction; |
| 58 | +use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxRateAction; |
52 | 59 | use Commercetools\Core\Request\Customers\CustomerLoginRequest; |
53 | 60 | use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction; |
54 | 61 | use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction; |
@@ -356,6 +363,168 @@ public function testAddCustomLineItemExternalTaxSubRatesOnly() |
356 | 363 | $this->assertContains($subRate2, $subRates); |
357 | 364 | } |
358 | 365 |
|
| 366 | + public function testSetCustomLineItemExternalTaxRate() |
| 367 | + { |
| 368 | + $draft = $this->getDraft(); |
| 369 | + $draft->setCustomLineItems( |
| 370 | + CustomLineItemDraftCollection::of()->add( |
| 371 | + CustomLineItemDraft::of() |
| 372 | + ->setName(LocalizedString::ofLangAndText('en', 'Test')) |
| 373 | + ->setQuantity(1) |
| 374 | + ->setMoney(Money::ofCurrencyAndAmount('EUR', 100)) |
| 375 | + ->setSlug('test') |
| 376 | + ) |
| 377 | + ); |
| 378 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL); |
| 379 | + $cart = $this->createCart($draft); |
| 380 | + |
| 381 | + $taxRateName = 'test'; |
| 382 | + $taxRateCountry = 'DE'; |
| 383 | + $taxRate = 0.1; |
| 384 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 385 | + ->addAction( |
| 386 | + CartSetCustomLineItemTaxRateAction::ofCustomLineItemId($cart->getCustomLineItems()->current()->getId()) |
| 387 | + ->setExternalTaxRate( |
| 388 | + ExternalTaxRateDraft::ofNameCountryAndAmount( |
| 389 | + $taxRateName, |
| 390 | + $taxRateCountry, |
| 391 | + $taxRate |
| 392 | + ) |
| 393 | + ) |
| 394 | + ) |
| 395 | + ; |
| 396 | + |
| 397 | + $response = $request->executeWithClient($this->getClient()); |
| 398 | + $cart = $request->mapResponse($response); |
| 399 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 400 | + |
| 401 | + $this->assertSame($taxRateName, $cart->getCustomLineItems()->current()->getTaxRate()->getName()); |
| 402 | + $this->assertSame($taxRateCountry, $cart->getCustomLineItems()->current()->getTaxRate()->getCountry()); |
| 403 | + $this->assertSame($taxRate, $cart->getCustomLineItems()->current()->getTaxRate()->getAmount()); |
| 404 | + } |
| 405 | + |
| 406 | + public function testSetLineItemExternalTaxRate() |
| 407 | + { |
| 408 | + $product = $this->getProduct(); |
| 409 | + |
| 410 | + $draft = $this->getDraft(); |
| 411 | + $draft->setLineItems( |
| 412 | + LineItemDraftCollection::of()->add( |
| 413 | + LineItemDraft::of() |
| 414 | + ->setProductId($product->getId()) |
| 415 | + ->setQuantity(1) |
| 416 | + ->setVariantId($product->getMasterData()->getCurrent()->getMasterVariant()->getId()) |
| 417 | + ) |
| 418 | + ); |
| 419 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL); |
| 420 | + $cart = $this->createCart($draft); |
| 421 | + |
| 422 | + $taxRateName = 'test'; |
| 423 | + $taxRateCountry = 'DE'; |
| 424 | + $taxRate = 0.1; |
| 425 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 426 | + ->addAction( |
| 427 | + CartSetLineItemTaxRateAction::ofLineItemId($cart->getLineItems()->current()->getId()) |
| 428 | + ->setExternalTaxRate( |
| 429 | + ExternalTaxRateDraft::ofNameCountryAndAmount( |
| 430 | + $taxRateName, |
| 431 | + $taxRateCountry, |
| 432 | + $taxRate |
| 433 | + ) |
| 434 | + ) |
| 435 | + ) |
| 436 | + ; |
| 437 | + |
| 438 | + $response = $request->executeWithClient($this->getClient()); |
| 439 | + $cart = $request->mapResponse($response); |
| 440 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 441 | + |
| 442 | + $this->assertSame($taxRateName, $cart->getLineItems()->current()->getTaxRate()->getName()); |
| 443 | + $this->assertSame($taxRateCountry, $cart->getLineItems()->current()->getTaxRate()->getCountry()); |
| 444 | + $this->assertSame($taxRate, $cart->getLineItems()->current()->getTaxRate()->getAmount()); |
| 445 | + } |
| 446 | + |
| 447 | + public function testSetShippingMethodExternalTaxRate() |
| 448 | + { |
| 449 | + $shippingMethod = $this->getShippingMethod(); |
| 450 | + |
| 451 | + $draft = $this->getDraft(); |
| 452 | + $draft->setShippingAddress(Address::of()->setCountry('DE')->setState($this->getRegion())); |
| 453 | + $draft->setShippingMethod( |
| 454 | + $shippingMethod->getReference() |
| 455 | + ); |
| 456 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL); |
| 457 | + $cart = $this->createCart($draft); |
| 458 | + |
| 459 | + $taxRateName = 'test'; |
| 460 | + $taxRateCountry = 'DE'; |
| 461 | + $taxRate = 0.1; |
| 462 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 463 | + ->addAction( |
| 464 | + CartSetShippingMethodTaxRateAction::of() |
| 465 | + ->setExternalTaxRate( |
| 466 | + ExternalTaxRateDraft::ofNameCountryAndAmount( |
| 467 | + $taxRateName, |
| 468 | + $taxRateCountry, |
| 469 | + $taxRate |
| 470 | + ) |
| 471 | + ) |
| 472 | + ) |
| 473 | + ; |
| 474 | + |
| 475 | + $response = $request->executeWithClient($this->getClient()); |
| 476 | + $cart = $request->mapResponse($response); |
| 477 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 478 | + |
| 479 | + $this->assertSame($taxRateName, $cart->getShippingInfo()->getTaxRate()->getName()); |
| 480 | + $this->assertSame($taxRateCountry, $cart->getShippingInfo()->getTaxRate()->getCountry()); |
| 481 | + $this->assertSame($taxRate, $cart->getShippingInfo()->getTaxRate()->getAmount()); |
| 482 | + } |
| 483 | + |
| 484 | + public function testChangeTaxMode() |
| 485 | + { |
| 486 | + $product = $this->getProduct(); |
| 487 | + $draft = $this->getDraft(); |
| 488 | + |
| 489 | + $taxRateName = 'test'; |
| 490 | + $taxRateCountry = 'DE'; |
| 491 | + $taxRate = 0.1; |
| 492 | + |
| 493 | + $draft->setLineItems( |
| 494 | + LineItemDraftCollection::of()->add( |
| 495 | + LineItemDraft::of() |
| 496 | + ->setProductId($product->getId()) |
| 497 | + ->setQuantity(1) |
| 498 | + ->setVariantId($product->getMasterData()->getCurrent()->getMasterVariant()->getId()) |
| 499 | + ->setExternalTaxRate( |
| 500 | + ExternalTaxRateDraft::ofNameCountryAndAmount( |
| 501 | + $taxRateName, |
| 502 | + $taxRateCountry, |
| 503 | + $taxRate |
| 504 | + ) |
| 505 | + ) |
| 506 | + ) |
| 507 | + ); |
| 508 | + $draft->setTaxMode(Cart::TAX_MODE_EXTERNAL); |
| 509 | + $cart = $this->createCart($draft); |
| 510 | + |
| 511 | + $this->assertSame($taxRateName, $cart->getLineItems()->current()->getTaxRate()->getName()); |
| 512 | + $this->assertSame($taxRateCountry, $cart->getLineItems()->current()->getTaxRate()->getCountry()); |
| 513 | + $this->assertSame($taxRate, $cart->getLineItems()->current()->getTaxRate()->getAmount()); |
| 514 | + |
| 515 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 516 | + ->addAction( |
| 517 | + CartChangeTaxModeAction::of()->setTaxMode(Cart::TAX_MODE_PLATFORM) |
| 518 | + ) |
| 519 | + ; |
| 520 | + |
| 521 | + $response = $request->executeWithClient($this->getClient()); |
| 522 | + $cart = $request->mapResponse($response); |
| 523 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 524 | + |
| 525 | + $this->assertNull($cart->getLineItems()->current()->getTaxRate()); |
| 526 | + } |
| 527 | + |
359 | 528 | /** |
360 | 529 | * @return CartDraft |
361 | 530 | */ |
|
0 commit comments