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]Seeing shipping cost of order #11939

Merged
merged 5 commits into from
Oct 21, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Feature: Viewing a cart summary with correct default shipping method based on va
And the store has a product "T-shirt banana" priced at "$9.99"
And this product belongs to "Free" shipping category

@ui
@ui @api
Scenario:
Given I added product "Star Trek Table Linen" to the cart
When I see the summary of my cart
Then my cart shipping total should be "$5.00"

@ui
@ui @api
Scenario:
Given I have product "T-shirt banana" in the cart
When I see the summary of my cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ Feature: Seeing shipping costs only when order requires shipping
And the store has "SHL" shipping method with "$5.00" fee
And I am a logged in customer

@ui
@ui @api
Scenario: Not seeing shipping cost if none of the order items require shipping
Given I have "Guards! Guards! - ebook" variant of product "Guards! Guards!" in the cart
Given I have "Guards! Guards! - ebook" variant of this product in the cart
When I see the summary of my cart
Then I should not see shipping total for my cart

@ui
@ui @api
Scenario: Seeing shipping cost if some of the order items require shipping
Given I have "Guards! Guards! - book" variant of product "Guards! Guards!" in the cart
And I have "Guards! Guards! - ebook" variant of product "Guards! Guards!" in the cart
When I see the summary of my cart
Given I have "Guards! Guards! - book" variant of this product in the cart
When I add "Guards! Guards! - ebook" variant of this product to the cart
And I see the summary of my cart
Then my cart shipping total should be "$5.00"

@ui
@ui @api
Scenario: Not seeing free cost if the order items that require shipping are removed
Given I have "Guards! Guards! - book" variant of product "Guards! Guards!" in the cart
And I have "Guards! Guards! - ebook" variant of product "Guards! Guards!" in the cart
When I remove product "Guards! Guards!" from the cart
And I see the summary of my cart
Then I should not see shipping total for my cart
Given I have "Guards! Guards! - book" variant of this product in the cart
When I add "Guards! Guards! - ebook" variant of this product to the cart
And I remove product "Guards! Guards!" from the cart
Then I see the summary of my cart
And I should not see shipping total for my cart
19 changes: 16 additions & 3 deletions src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ public function myCartShouldHaveItems(int $quantity, ProductInterface $product):
Assert::true($this->hasItemWithNameAndQuantity($response, $product->getName(), $quantity));
}

/**
* @Then /^my cart shipping total should be ("[^"]+")$/
* @Then I should not see shipping total for my cart
*/
public function myCartShippingFeeShouldBe(int $shippingTotal = 0): void
{
$response = $this->cartsClient->getLastResponse();

Assert::same(
$this->responseChecker->getValue($response, 'shippingTotal'),
$shippingTotal);
}

private function pickupCart(): string
{
$this->cartsClient->buildCreateRequest();
Expand Down Expand Up @@ -416,15 +429,15 @@ private function getProductForItem(array $item, bool $shopSection = true): Respo
}

$variantIri = $shopSection ? $this->adminToShopIriConverter->convert($item['variant']) : $item['variant'];
$response = $this->cartsClient->executeCustomRequest(Request::custom($variantIri, HttpRequest::METHOD_GET));
$response = $this->cartsClient->showByIri(urldecode($variantIri));

$product = $this->responseChecker->getValue($response, 'product');

$pathElements = explode('/', $product);

$productCode = $pathElements[array_key_last($pathElements)];
$productCode = urldecode($pathElements[array_key_last($pathElements)]);

return $this->productsClient->show(StringInflector::nameToSlug($productCode));
return $this->productsClient->show(StringInflector::nameToSlug(urldecode($productCode)));
}

private function getProductVariantForItem(array $item): Response
Expand Down
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Context/Setup/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ public function iAddedProductToTheCart(ProductInterface $product, ?string $token
$this->sharedStorage->set('product', $product);
}

/**
* @Given /^I have ("[^"]+" variant of this product) in the (cart)$/
*/
public function iHaveVariantOfProductInTheCart(ProductVariantInterface $productVariant, ?string $tokenValue): void
{
if ($tokenValue === null) {
$tokenValue = $this->pickupCart();
}

$this->commandBus->dispatch(AddItemToCart::createFromData(
$tokenValue,
$productVariant->getProduct()->getCode(),
$productVariant->getCode(),
1
));

$this->sharedStorage->set('product', $productVariant->getProduct());
}

/**
* @Given /^I have (product "[^"]+") with (product option "[^"]+") ([^"]+) in the (cart)$/
*/
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Ui/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public function iAddMultipleProductsToTheCart(array $products)
* @When I add :variantName variant of product :product to the cart
* @When /^I add "([^"]+)" variant of (this product) to the cart$/
* @Given I have :variantName variant of product :product in the cart
* @Given /^I have "([^"]+)" variant of (this product) in the cart$/
*/
public function iAddProductToTheCartSelectingVariant($variantName, ProductInterface $product)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ default:
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.shipping_category
- sylius.behat.context.setup.shop_api_security
- sylius.behat.context.setup.user

Expand All @@ -19,6 +20,7 @@ default:
- sylius.behat.context.transform.product
- sylius.behat.context.transform.product_variant
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.shipping_category

- sylius.behat.context.api.shop.cart
- sylius.behat.context.api.shop.login
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

<attribute name="shippingTotal">
<group>checkout:read</group>
<group>order:read</group>
</attribute>

<attribute name="shippingAddress">
Expand Down