Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Shipping methods resolution #13628

Merged
merged 7 commits into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,35 @@
@viewing_shipping_methods
Feature: Viewing available shipping methods based on channel as a Shop User
In order to only see applicable shipping methods
As a Shop User
I want to see the shipping methods that are available to my order based on the channel

Background:
Given the store operates on a channel named "United Kingdom" in "USD" currency and with hostname "uk.cool-clothes.example"
And the store operates on another channel named "United States" in "USD" currency and with hostname "usa.cool-clothes.example"
And the store has a zone "World"
And the store ships to "United States"
And this zone has the "United States" country member
And the store ships everywhere for free for all channels
And the store has "ultra fast" shipping method with "$4.00" fee per unit for "United States" channel
And the store has "uber speedy" shipping method with "$15.00" fee per shipment for "United Kingdom" channel
And the store has a product "T-Shirt" priced at "$20.00" available in channel "United Kingdom" and channel "United States"
And I am a logged in customer

@api @ui
Scenario: Seeing shipping methods that are available in channel as an logged in customer
Given I changed my current channel to "United States"
And I have product "T-Shirt" in the cart
When I specified the billing address
Then I should be on the checkout shipping step
And I should see "ultra fast" shipping method
And I should not see "uber speedy" shipping method

@api @ui
Scenario: Seeing shipping methods that are available in another channel as an logged in customer
Given I changed my current channel to "United Kingdom"
And I have product "T-Shirt" in the cart
When I specified the billing address
Then I should be on the checkout shipping step
And I should see "uber speedy" shipping method
And I should not see "ultra fast" shipping method
@@ -0,0 +1,34 @@
@viewing_shipping_methods
Feature: Viewing available shipping methods based on channel as a Visitor
In order to only see applicable shipping methods
As a Visitor
I want to see the shipping methods that are available to my order based on the channel

Background:
Given the store operates on a channel named "United Kingdom" in "USD" currency and with hostname "uk.cool-clothes.example"
And the store operates on another channel named "United States" in "USD" currency and with hostname "usa.cool-clothes.example"
And the store has a zone "World"
And the store ships to "United States"
And this zone has the "United States" country member
And the store ships everywhere for free for all channels
And the store has "ultra fast" shipping method with "$4.00" fee per unit for "United States" channel
And the store has "uber speedy" shipping method with "$15.00" fee per shipment for "United Kingdom" channel
And the store has a product "T-Shirt" priced at "$20.00" available in channel "United Kingdom" and channel "United States"

@api @ui
Scenario: Seeing shipping methods that are available in channel
Given I changed my current channel to "United States"
And I have product "T-Shirt" in the cart
When I complete addressing step with email "john@example.com" and "United States" based billing address
Then I should be on the checkout shipping step
And I should see "ultra fast" shipping method
And I should not see "uber speedy" shipping method

@api @ui
Scenario: Seeing shipping methods that are available in another channel
Given I changed my current channel to "United Kingdom"
And I have product "T-Shirt" in the cart
When I complete addressing step with email "john@example.com" and "United States" based billing address
Then I should be on the checkout shipping step
And I should see "uber speedy" shipping method
And I should not see "ultra fast" shipping method
8 changes: 8 additions & 0 deletions psalm.xml
Expand Up @@ -127,9 +127,17 @@
<errorLevel type="info">
<referencedMethod name="PHPUnit\Framework\TestCase::__construct" />
<referencedMethod name="Symfony\Bundle\SecurityBundle\Security\_FirewallMap::getFirewallConfig" />
<referencedMethod name="ApiPlatform\Core\Util\RequestParser::getQueryString" />
<referencedMethod name="ApiPlatform\Core\Util\RequestParser::parseRequestParams" />
</errorLevel>
</InternalMethod>

<InternalClass>
<errorLevel type="info">
<referencedClass name="ApiPlatform\Core\Util\RequestParser" />
</errorLevel>
</InternalClass>

<InvalidDocblock>
<errorLevel type="info">
<file name="vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php" />
Expand Down
19 changes: 9 additions & 10 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Expand Up @@ -49,6 +49,8 @@ final class CheckoutContext implements Context

private ApiClientInterface $addressesClient;

private ApiClientInterface $shippingMethodsClient;

private ResponseCheckerInterface $responseChecker;

private RepositoryInterface $shippingMethodRepository;
Expand All @@ -73,6 +75,7 @@ final class CheckoutContext implements Context
public function __construct(
ApiClientInterface $ordersClient,
ApiClientInterface $addressesClient,
ApiClientInterface $shippingMethodsClient,
ResponseCheckerInterface $responseChecker,
RepositoryInterface $shippingMethodRepository,
OrderRepositoryInterface $orderRepository,
Expand All @@ -85,6 +88,7 @@ public function __construct(
) {
$this->ordersClient = $ordersClient;
$this->addressesClient = $addressesClient;
$this->shippingMethodsClient = $shippingMethodsClient;
$this->responseChecker = $responseChecker;
$this->shippingMethodRepository = $shippingMethodRepository;
$this->orderRepository = $orderRepository;
Expand Down Expand Up @@ -1195,17 +1199,12 @@ private function getCheckoutState(): string

private function getCartShippingMethods(array $cart): array
{
$request = Request::customItemAction(
'shop',
'orders',
$cart['tokenValue'],
HTTPRequest::METHOD_GET,
sprintf('shipments/%s/methods', $cart['shipments'][0]['id'])
);

$this->ordersClient->executeCustomRequest($request);
$this->shippingMethodsClient->index();
$this->shippingMethodsClient->addFilter('tokenValue', $cart['tokenValue']);
$this->shippingMethodsClient->addFilter('shipmentId', $cart['shipments'][0]['id']);
$this->shippingMethodsClient->filter();

return $this->responseChecker->getCollection($this->ordersClient->getLastResponse());
return $this->responseChecker->getCollection($this->shippingMethodsClient->getLastResponse());
}

private function hasShippingMethod(ShippingMethodInterface $shippingMethod): bool
Expand Down
22 changes: 22 additions & 0 deletions src/Sylius/Behat/Context/Setup/ShippingContext.php
Expand Up @@ -258,6 +258,28 @@ public function storeHasShippingMethodWithFeePerShipmentForChannels(
]));
}

/**
* @Given /^the store has "([^"]+)" shipping method with ("[^"]+") fee per shipment for ("[^"]+" channel)$/
*/
public function storeHasShippingMethodWithFeePerShipmentForChannel(
string $shippingMethodName,
string $fee,
ChannelInterface $channel,
): void {
$configuration = [$channel->getCode() => ['amount' => $fee]];

$this->saveShippingMethod($this->shippingMethodExampleFactory->create([
'name' => $shippingMethodName,
'enabled' => true,
'zone' => $this->getShippingZone(),
'calculator' => [
'type' => DefaultCalculators::FLAT_RATE,
'configuration' => $configuration,
],
'channels' => [$channel],
]));
}

/**
* @Given /^the store has "([^"]+)" shipping method with ("[^"]+") fee per unit for ("[^"]+" channel)$/
* @Given /^the store has "([^"]+)" shipping method with ("[^"]+") fee per unit for ("[^"]+" channel) and ("[^"]+") for ("[^"]+" channel)$/
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Resources/config/services/api.xml
Expand Up @@ -24,6 +24,11 @@
<argument>shop</argument>
</service>

<service id="sylius.behat.api_platform_client.shop.shipping_methods" class="Sylius\Behat\Client\ApiPlatformClient" parent="sylius.behat.api_platform_client">
<argument>shipping-methods</argument>
<argument>shop</argument>
</service>

<service id="sylius.behat.api_platform_client.administrator" class="Sylius\Behat\Client\ApiPlatformClient" parent="sylius.behat.api_platform_client">
<argument>administrators</argument>
<argument>admin</argument>
Expand Down
Expand Up @@ -68,6 +68,7 @@
<service id="sylius.behat.context.api.shop.checkout" class="Sylius\Behat\Context\Api\Shop\CheckoutContext">
<argument type="service" id="sylius.behat.api_platform_client.shop.order" />
<argument type="service" id="sylius.behat.api_platform_client.shop.address" />
<argument type="service" id="sylius.behat.api_platform_client.shop.shipping_methods" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.repository.shipping_method" />
<argument type="service" id="sylius.repository.order" />
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Resources/config/suites.yml
Expand Up @@ -41,6 +41,7 @@ imports:
- suites/api/promotion/managing_promotions.yml
- suites/api/promotion/receiving_discount.yml
- suites/api/shipping/applying_shipping_method_rules.yml
- suites/api/shipping/viewing_shipping_methods.yml
- suites/api/shipping/managing_shipments.yml
- suites/api/shipping/managing_shipping_categories.yml
- suites/api/shipping/managing_shipping_methods.yml
Expand Down Expand Up @@ -113,6 +114,7 @@ imports:
- suites/ui/promotion/receiving_discount.yml
- suites/ui/shipping/applying_shipping_fee.yml
- suites/ui/shipping/applying_shipping_method_rules.yml
- suites/ui/shipping/viewing_shipping_methods.yml
- suites/ui/shipping/managing_shipments.yml
- suites/ui/shipping/managing_shipping_categories.yml
- suites/ui/shipping/managing_shipping_methods.yml
Expand Down
@@ -0,0 +1,38 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
api_viewing_shipping_methods:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.address
- sylius.behat.context.transform.cart
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.country
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shipping_method
- sylius.behat.context.transform.tax_category
- sylius.behat.context.transform.zone

- sylius.behat.context.transform.shared_storage

- sylius.behat.context.setup.address
- sylius.behat.context.setup.cart
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shop_security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.taxation
- sylius.behat.context.setup.zone

- sylius.behat.context.api.shop.cart
- sylius.behat.context.api.shop.checkout

filters:
tags: "@viewing_shipping_methods&&@api"
@@ -0,0 +1,38 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
ui_viewing_shipping_methods:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.address
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.country
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shipping_method
- sylius.behat.context.transform.tax_category
- sylius.behat.context.transform.zone

- sylius.behat.context.transform.shared_storage

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shop_security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.taxation
- sylius.behat.context.setup.zone

- sylius.behat.context.ui.shop.cart
- sylius.behat.context.ui.shop.checkout
- sylius.behat.context.ui.shop.checkout.addressing
- sylius.behat.context.ui.shop.checkout.payment
- sylius.behat.context.ui.shop.checkout.shipping

filters:
tags: "@viewing_shipping_methods&&@ui"

This file was deleted.