mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
feature #13930 [API][Behat] Cover scenarios for applying correct taxes (GSadee)
This PR was merged into the 1.12-dev branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | master | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Related tickets | | | License | MIT | <!-- - Bug fixes must be submitted against the 1.10 or 1.11 branch(the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits -------a6fcfd884e[API] Save customer's default address on cart during picking it up49cb6262e9[API][Behat] Cover scenarios for applying correct taxes
This commit is contained in:
commit
dfa8dc513a
9 changed files with 63 additions and 15 deletions
|
|
@ -15,7 +15,7 @@ Feature: Apply correct taxes based on customer data
|
|||
And it belongs to "Clothes" tax category
|
||||
And there is user "john@example.com" with "Germany" as shipping country
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Proper taxes for logged in Customer
|
||||
Given I am logged in as "john@example.com"
|
||||
When I add product "PHP T-Shirt" to the cart
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ Feature: Apply correct taxes for items with the same tax rate
|
|||
Then my cart total should be "$73.80"
|
||||
And my cart taxes should be "$13.80"
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Proper taxes after changing item quantity
|
||||
Given I have 3 products "PHP T-Shirt" in the cart
|
||||
And I have 2 products "Symfony Hat" in the cart
|
||||
When I change "PHP T-Shirt" quantity to 1
|
||||
When I change product "PHP T-Shirt" quantity to 1 in my cart
|
||||
Then my cart total should be "$196.80"
|
||||
And my cart taxes should be "$36.80"
|
||||
|
|
|
|||
|
|
@ -19,34 +19,34 @@ Feature: Apply correct taxes for products with different tax rates for different
|
|||
And it belongs to "Mugs" tax category
|
||||
And I am a logged in customer
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Displaying correct tax before specifying shipping address
|
||||
When I add product "PHP T-Shirt" to the cart
|
||||
Then my cart total should be "$100.00"
|
||||
And there should be no taxes charged
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Displaying correct tax after specifying billing address
|
||||
Given I have product "PHP T-Shirt" in the cart
|
||||
When I proceed selecting "Germany" as billing country
|
||||
Then my cart total should be "$123.00"
|
||||
And my cart taxes should be "$23.00"
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Displaying correct taxes for multiple products after specifying billing address
|
||||
Given I have 3 products "PHP T-Shirt" in the cart
|
||||
When I proceed selecting "Germany" as billing country
|
||||
Then my cart total should be "$369.00"
|
||||
And my cart taxes should be "$69.00"
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Displaying correct taxes for multiple products from different zones before specifying shipping address
|
||||
When I add product "PHP T-Shirt" to the cart
|
||||
And I add 2 products "Symfony Mug" to the cart
|
||||
Then my cart total should be "$205.00"
|
||||
And my cart taxes should be "$5.00"
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Displaying correct taxes for multiple products from different zones after specifying billing address
|
||||
Given I have product "PHP T-Shirt" in the cart
|
||||
And I have 2 products "Symfony Mug" in the cart
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ Feature: Apply correct taxes on visitor cart
|
|||
Then my cart total should be "$123.00"
|
||||
And my cart taxes should be "$23.00"
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Proper taxes after specifying shipping address
|
||||
Given I have product "PHP T-Shirt" in the cart
|
||||
When I proceed as guest "john@example.com" with "Austria" as billing country
|
||||
|
|
|
|||
|
|
@ -10,14 +10,12 @@ Feature: Apply different taxes for variants with different tax category
|
|||
And the store has "US VAT" tax rate of 23% for "Mugs" within the "US" zone
|
||||
And the store has "Low VAT" tax rate of 5% for "Cheap Mugs" within the "US" zone
|
||||
And the store has a product "PHP Mug"
|
||||
And it comes in the following variations:
|
||||
| name | price |
|
||||
| Medium Mug | $100.00 |
|
||||
| Large Mug | $40.00 |
|
||||
And this product has "Medium Mug" variant priced at "$100.00"
|
||||
And this product has "Large Mug" variant priced at "$40.00"
|
||||
And "Medium Mug" variant of product "PHP Mug" belongs to "Cheap Mugs" tax category
|
||||
And "Large Mug" variant of product "PHP Mug" belongs to "Mugs" tax category
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Proper taxes for different taxed variants
|
||||
When I add "Medium Mug" variant of product "PHP Mug" to the cart
|
||||
And I add "Large Mug" variant of product "PHP Mug" to the cart
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ final class CartContext implements Context
|
|||
|
||||
/**
|
||||
* @When /^I change (product "[^"]+") quantity to (\d+) in my (cart)$/
|
||||
* @Given I change :productName quantity to :quantity
|
||||
* @When /^the (?:visitor|customer) change (product "[^"]+") quantity to (\d+) in his (cart)$/
|
||||
* @When /^the visitor try to change (product "[^"]+") quantity to (\d+) in the customer (cart)$/
|
||||
* @When /^I try to change (product "[^"]+") quantity to (\d+) in my (cart)$/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Sylius\Behat\Client\RequestFactoryInterface;
|
|||
use Sylius\Behat\Client\ResponseCheckerInterface;
|
||||
use Sylius\Behat\Context\Api\Resources;
|
||||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Component\Addressing\Model\CountryInterface;
|
||||
use Sylius\Component\Addressing\Model\ProvinceInterface;
|
||||
use Sylius\Component\Core\Formatter\StringInflector;
|
||||
use Sylius\Component\Core\Model\AddressInterface;
|
||||
|
|
@ -331,6 +332,22 @@ final class CheckoutContext implements Context
|
|||
$this->content = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I proceed as guest :email with :country as billing country
|
||||
*/
|
||||
public function iProceedLoggingAsGuestWithAsBillingCountry(string $email, CountryInterface $country): void
|
||||
{
|
||||
$this->addressOrderWithCountryAndEmail($country, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I proceed selecting :country as billing country
|
||||
*/
|
||||
public function iProceedSelectingCountryAsBillingCountry(CountryInterface $country): void
|
||||
{
|
||||
$this->addressOrderWithCountryAndEmail($country);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I provide additional note like :notes
|
||||
*/
|
||||
|
|
@ -1193,6 +1210,21 @@ final class CheckoutContext implements Context
|
|||
return false;
|
||||
}
|
||||
|
||||
private function addressOrderWithCountryAndEmail(CountryInterface $country, ?string $email = null): void
|
||||
{
|
||||
$this->addressOrder([
|
||||
'email' => $email,
|
||||
'billingAddress' => [
|
||||
'city' => 'Madrid',
|
||||
'street' => 'Av. de Concha Espina',
|
||||
'postcode' => '28036',
|
||||
'countryCode' => $country->getCode(),
|
||||
'firstName' => 'Santiago',
|
||||
'lastName' => 'Bernabeu',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function addressOrder(array $content): void
|
||||
{
|
||||
if (!array_key_exists('email', $content)) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Sylius\Bundle\ApiBundle\CommandHandler\Cart;
|
|||
use Doctrine\Persistence\ObjectManager;
|
||||
use Sylius\Bundle\ApiBundle\Command\Cart\PickupCart;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Model\AddressInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\CustomerInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
|
|
@ -72,6 +73,7 @@ final class PickupCartHandler implements MessageHandlerInterface
|
|||
$cart->setTokenValue($pickupCart->tokenValue ?? $this->generator->generateUriSafeString(10));
|
||||
if ($customer !== null) {
|
||||
$cart->setCustomer($customer);
|
||||
$cart->setBillingAddress($this->getDefaultAddress($customer));
|
||||
}
|
||||
|
||||
$this->orderManager->persist($cart);
|
||||
|
|
@ -108,4 +110,15 @@ final class PickupCartHandler implements MessageHandlerInterface
|
|||
|
||||
return $localeCode;
|
||||
}
|
||||
|
||||
private function getDefaultAddress(CustomerInterface $customer): ?AddressInterface
|
||||
{
|
||||
$defaultAddress = $customer->getDefaultAddress();
|
||||
if (null !== $defaultAddress) {
|
||||
$clonedAddress = clone $defaultAddress;
|
||||
$clonedAddress->setCustomer(null);
|
||||
}
|
||||
|
||||
return $clonedAddress ?? null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use PhpSpec\ObjectBehavior;
|
|||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ApiBundle\Command\Cart\PickupCart;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Model\AddressInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\CustomerInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
|
|
@ -66,7 +67,8 @@ final class PickupCartHandlerSpec extends ObjectBehavior
|
|||
OrderInterface $cart,
|
||||
ChannelInterface $channel,
|
||||
CurrencyInterface $currency,
|
||||
LocaleInterface $locale
|
||||
LocaleInterface $locale,
|
||||
AddressInterface $address
|
||||
): void {
|
||||
$pickupCart = new PickupCart();
|
||||
$pickupCart->setChannelCode('code');
|
||||
|
|
@ -77,6 +79,7 @@ final class PickupCartHandlerSpec extends ObjectBehavior
|
|||
$channel->getDefaultLocale()->willReturn($locale);
|
||||
|
||||
$customerRepository->findOneBy(['email' => 'sample@email.com'])->willReturn($customer);
|
||||
$customer->getDefaultAddress()->willReturn($address);
|
||||
|
||||
$cartRepository->findLatestNotEmptyCartByChannelAndCustomer($channel, $customer)->willReturn(null);
|
||||
|
||||
|
|
@ -88,6 +91,7 @@ final class PickupCartHandlerSpec extends ObjectBehavior
|
|||
|
||||
$cartFactory->createNew()->willReturn($cart);
|
||||
$cart->setCustomer($customer)->shouldBeCalled();
|
||||
$cart->setBillingAddress($address)->shouldBeCalled();
|
||||
$cart->setChannel($channel)->shouldBeCalled();
|
||||
$cart->setCurrencyCode('USD')->shouldBeCalled();
|
||||
$cart->setLocaleCode('en_US')->shouldBeCalled();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue