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] Add itemsTotal field to order resource #12661

Merged
merged 4 commits into from
May 24, 2021
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
@@ -0,0 +1,21 @@
@shopping_cart
Feature: Seeing detailed information of cart
In order to know more about status of my cart
As a Visitor
I want to be able to see detailed information of my cart

Background:
Given the store operates on a single channel in "United States"
And the store has a product "T-shirt banana" priced at "$12.54"

@api
Scenario: Viewing items of my cart
When I add 5 of them to my cart
And I check items in my cart
Then my cart should have quantity of 5 items of product "T-shirt banana"

@api
Scenario: Viewing items total of my cart
When I add 5 of them to my cart
And I check details of my cart
Then my cart should have "$62.70" items total
arti0090 marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 0 additions & 15 deletions features/cart/shopping_cart/seeing_order_items_in_cart.feature

This file was deleted.

12 changes: 12 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,20 @@ public function iCheckItemsOfMyCart(string $tokenValue): void
$this->cartsClient->executeCustomRequest($request);
}

/**
* @Then /^my cart should have ("[^"]+") items total$/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/^my cart should have ("[^"]+") items total$/ -> my cart should have :itemsTotal items total?

Copy link
Contributor Author

@arti0090 arti0090 May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work at first it will return (using 12.34 as example) $12.34 but i need 1234 as API returns int number. With ("[^"]+") I am getting the transformed value of 1234.

*/
public function myCartShouldHaveItemsTotal(int $itemsTotal): void
{
Assert::same(
$this->responseChecker->getValue($this->cartsClient->getLastResponse(), 'itemsTotal'),
$itemsTotal
);
}

/**
* @Then /^my cart should have (\d+) items of (product "([^"]+)")$/
* @Then /^my cart should have quantity of (\d+) items of (product "([^"]+)")$/
*/
public function myCartShouldHaveItems(int $quantity, ProductInterface $product): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Api/Shop/OrderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function iShouldHaveChosenPaymentMethodForMyOrder(PaymentMethodInterface
->getValue($this->client->show($this->sharedStorage->get('cart_token')), 'payments')[0]
;

Assert::same($this->iriConverter->getIriFromItem($paymentMethod), $payment['method']);
Assert::same($this->iriConverter->getIriFromItem($paymentMethod), $payment['method']['@id']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<itemOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">/shop/orders/{tokenValue}</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:cart:read</attribute>
</attribute>
</itemOperation>

<itemOperation name="shop_delete">
Expand All @@ -70,6 +73,9 @@
<attribute name="openapi_context">
<attribute name="summary">Deletes cart</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:order:read</attribute>
</attribute>
</itemOperation>

<itemOperation name="admin_cancel">
Expand Down Expand Up @@ -410,6 +416,7 @@
<subresource resourceClass="%sylius.model.order_item.class%" />
</property>
<property name="notes" writable="true" />
<property name="itemsTotal" readable="true" />
<property name="taxTotal" readable="true"/>
<property name="adjustments" writable="false">
<subresource resourceClass="%sylius.model.adjustment.class%" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@

<attribute name="paymentState">
<group>admin:order:read</group>
<group>shop:cart:read</group>
</attribute>

<attribute name="shippingState">
<group>admin:order:read</group>
<group>shop:cart:read</group>
</attribute>

<attribute name="total">
Expand Down Expand Up @@ -102,6 +104,12 @@
<group>admin:order:read</group>
</attribute>

<attribute name="itemsTotal">
<group>shop:cart:read</group>
<group>shop:order:read</group>
<group>shop:order:account:read</group>
</attribute>

<attribute name="taxTotal">
<group>admin:order:read</group>
<group>shop:cart:read</group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<attribute name="subtotal">
<group>admin:order:read</group>
<group>admin:order_item:read</group>
<group>shop:cart:read</group>
<group>shop:order_item:read</group>
</attribute>
<attribute name="total">
Expand Down