diff --git a/features/order/managing_orders/order_filtration/filtering_orders_by_channel.feature b/features/order/managing_orders/order_filtration/filtering_orders_by_channel.feature index 97ef558a16e..8e38ba6a207 100644 --- a/features/order/managing_orders/order_filtration/filtering_orders_by_channel.feature +++ b/features/order/managing_orders/order_filtration/filtering_orders_by_channel.feature @@ -13,7 +13,7 @@ Feature: Filtering orders by a channel And this customer has also placed an order "#00000003" on a channel "Web-US" And I am logged in as an administrator - @ui + @ui @api Scenario: Filtering orders by a chosen channel When I browse orders And I choose "Web-EU" as a channel filter @@ -23,7 +23,7 @@ Feature: Filtering orders by a channel And I should see an order with "#00000002" number But I should not see an order with "#00000003" number - @ui + @ui @api Scenario: Filtering orders by an another channel When I browse orders And I choose "Web-US" as a channel filter diff --git a/features/order/managing_orders/order_filtration/filtering_orders_by_date.feature b/features/order/managing_orders/order_filtration/filtering_orders_by_date.feature index 0d8324b199a..e6b39dd5aba 100644 --- a/features/order/managing_orders/order_filtration/filtering_orders_by_date.feature +++ b/features/order/managing_orders/order_filtration/filtering_orders_by_date.feature @@ -12,7 +12,7 @@ Feature: Filtering orders And this customer has also placed an order "#00000003" at "2016-12-06 10:00" And I am logged in as an administrator - @ui + @ui @api Scenario: Filtering orders by date from When I browse orders And I specify filter date from as "2016-12-05 08:30" @@ -22,7 +22,7 @@ Feature: Filtering orders And I should see an order with "#00000003" number But I should not see an order with "#00000001" number - @ui + @ui @api Scenario: Filtering orders by date to When I browse orders And I specify filter date to as "2016-12-05 09:30" @@ -32,7 +32,7 @@ Feature: Filtering orders And I should see an order with "#00000002" number But I should not see an order with "#00000003" number - @ui + @ui @api Scenario: Filtering orders by date from to When I browse orders And I specify filter date from as "2016-12-05 08:30" @@ -43,25 +43,25 @@ Feature: Filtering orders But I should not see an order with "#00000001" number And I should not see an order with "#00000003" number - @ui + @ui @api Scenario: Filtering orders by date from without time When I browse orders And I specify filter date from as "2016-12-05" - And I specify filter date to as "2016-12-06" + And I specify filter date to as "2016-12-07" And I filter Then I should see 2 orders in the list And I should see an order with "#00000002" number And I should see an order with "#00000003" number But I should not see an order with "#00000001" number - @ui + @ui @api Scenario: Filtering orders placed at midnight or just before midnight Given this customer has placed an order "#00000004" at "2016-12-10 00:00" And this customer has also placed an order "#00000005" at "2016-12-11 23:59" And this customer has also placed an order "#00000006" at "2016-12-12 00:00" When I browse orders And I specify filter date from as "2016-12-10" - And I specify filter date to as "2016-12-11" + And I specify filter date to as "2016-12-11 23:59" And I filter Then I should see 2 orders in the list And I should see an order with "#00000004" number diff --git a/features/order/managing_orders/order_filtration/filtering_orders_by_products.feature b/features/order/managing_orders/order_filtration/filtering_orders_by_products.feature index 42f3e1051c5..f8d0eb40a7e 100644 --- a/features/order/managing_orders/order_filtration/filtering_orders_by_products.feature +++ b/features/order/managing_orders/order_filtration/filtering_orders_by_products.feature @@ -17,7 +17,7 @@ Feature: Filtering orders by products And the customer chose "Free" shipping method to "United States" with "Offline" payment And I am logged in as an administrator - @ui @javascript + @ui @api @javascript Scenario: Filtering orders by product When I browse orders And I filter by product "Galaxy T-Shirt" @@ -25,7 +25,7 @@ Feature: Filtering orders by products And I should see an order with "#0000001" number And I should see an order with "#0000003" number - @ui @javascript + @ui @api @javascript Scenario: Filtering orders by multiple products When I browse orders And I filter by products "Galaxy T-Shirt" and "Space Dress" diff --git a/features/order/managing_orders/order_filtration/filtering_orders_by_shipping_method.feature b/features/order/managing_orders/order_filtration/filtering_orders_by_shipping_method.feature index 68bc72f8c37..23ea1472620 100644 --- a/features/order/managing_orders/order_filtration/filtering_orders_by_shipping_method.feature +++ b/features/order/managing_orders/order_filtration/filtering_orders_by_shipping_method.feature @@ -23,7 +23,7 @@ Feature: Filtering orders by a shipping method And the customer chose "DHL" shipping method to "United States" with "Offline" payment And I am logged in as an administrator - @ui + @ui @api Scenario: Filtering orders by DHL shipping method When I browse orders And I choose "DHL" as a shipping method filter @@ -32,7 +32,7 @@ Feature: Filtering orders by a shipping method And I should see an order with "#000001338" number And I should not see an order with "#000001337" number - @ui + @ui @api Scenario: Filtering orders by an another shipping method When I browse orders And I choose "Free" as a shipping method filter diff --git a/features/order/managing_orders/order_filtration/filtering_orders_by_total_in_different_currencies.feature b/features/order/managing_orders/order_filtration/filtering_orders_by_total_in_different_currencies.feature index a9fb895296e..61515626a08 100644 --- a/features/order/managing_orders/order_filtration/filtering_orders_by_total_in_different_currencies.feature +++ b/features/order/managing_orders/order_filtration/filtering_orders_by_total_in_different_currencies.feature @@ -18,14 +18,14 @@ Feature: Filtering orders by total in different currencies And I am logged in as an administrator And I am browsing orders - @ui + @ui @api Scenario: Filtering orders by currency alone When I choose "British Pound" as the filter currency And I filter Then I should see 3 orders in the list But I should not see any orders with currency "USD" - @ui + @ui @api Scenario: Filtering orders with total greater than specified amount When I choose "US Dollar" as the filter currency And I specify filter total being greater than 100 @@ -36,7 +36,7 @@ Feature: Filtering orders by total in different currencies But I should not see an order with "#00000001" number And I should not see any orders with currency "GBP" - @ui + @ui @api Scenario: Filtering orders with total less than specified amount When I choose "US Dollar" as the filter currency And I specify filter total being less than 200 @@ -47,7 +47,7 @@ Feature: Filtering orders by total in different currencies But I should not see an order with "#00000002" number And I should not see any orders with currency "GBP" - @ui + @ui @api Scenario: Filtering order with total from a specified range When I choose "British Pound" as the filter currency And I specify filter total being greater than 150.50 @@ -59,7 +59,7 @@ Feature: Filtering orders by total in different currencies And I should not see an order with "#00000006" number And I should not see any orders with currency "USD" - @ui + @ui @api Scenario: Filtering orders by total in given range but with no currency provided When I specify filter total being greater than 150 And I specify filter total being less than 200 diff --git a/features/order/managing_orders/order_filtration/filtering_orders_by_variants.feature b/features/order/managing_orders/order_filtration/filtering_orders_by_variants.feature index 0cff953c571..0aa5162ebda 100644 --- a/features/order/managing_orders/order_filtration/filtering_orders_by_variants.feature +++ b/features/order/managing_orders/order_filtration/filtering_orders_by_variants.feature @@ -26,7 +26,7 @@ Feature: Filtering orders by variants And the customer chose "Free" shipping method to "United States" with "Offline" payment And I am logged in as an administrator - @ui @javascript + @ui @api @javascript Scenario: Filtering orders by variant When I browse orders And I filter by variant "Sundress" @@ -34,7 +34,7 @@ Feature: Filtering orders by variants And I should see an order with "#0000002" number And I should see an order with "#0000003" number - @ui @javascript + @ui @api @javascript Scenario: Filtering orders by multiple variants of the same product When I browse orders And I filter by variants "Nebula Top" and "Neutron Sleeveless" @@ -42,7 +42,7 @@ Feature: Filtering orders by variants And I should see an order with "#0000001" number And I should see an order with "#0000002" number - @ui @javascript + @ui @api @javascript Scenario: Filtering orders by multiple variants of different products When I browse orders And I filter by variants "Neutron Sleeveless" and "Sundress" diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingOrdersContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingOrdersContext.php index 23f09558a3e..df207f40c49 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingOrdersContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingOrdersContext.php @@ -22,8 +22,11 @@ use Sylius\Behat\Service\SharedSecurityServiceInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\AdminUserInterface; +use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\Model\ShippingMethodInterface; +use Sylius\Component\Currency\Model\CurrencyInterface; use Sylius\Component\Order\OrderTransitions; use Sylius\Component\Payment\PaymentTransitions; use Sylius\Component\Shipping\ShipmentTransitions; @@ -62,6 +65,113 @@ public function iBrowseOrders(): void $this->client->index(Resources::ORDERS); } + /** + * @When I filter + */ + public function iFilter(): void + { + $this->client->filter(); + } + + /** + * @When I choose :channel as a channel filter + */ + public function iChooseChannelAsAChannelFilter(ChannelInterface $channel): void + { + $this->client->addFilter('channel.code', $channel->getCode()); + } + + /** + * @When I specify filter date from as :dateTime + */ + public function iSpecifyFilterDateFromAs(string $dateTime): void + { + $this->client->addFilter('checkoutCompletedAt[after]', $dateTime); + } + + /** + * @When I specify filter date to as :dateTime + */ + public function iSpecifyFilterDateToAs(string $dateTime): void + { + $this->client->addFilter('checkoutCompletedAt[before]', $dateTime); + } + + + /** + * @When I filter by product :productName + * @When I filter by products :firstProduct and :secondProduct + */ + public function iFilterByProduct(string ...$productNames): void + { + foreach ($productNames as $productName) { + $this->client->addFilter('items.productName[]', $productName); + } + + $this->client->filter(); + } + + /** + * @When I choose :shippingMethod as a shipping method filter + */ + public function iChooseAsAShippingMethodFilter(ShippingMethodInterface $shippingMethod): void + { + $this->client->addFilter('shipments.method.code', $shippingMethod->getCode()); + } + + /** + * @When I choose :currency as the filter currency + */ + public function iChooseCurrencyAsTheFilterCurrency(CurrencyInterface $currency): void + { + $this->client->addFilter('currencyCode', $currency->getCode()); + } + + /** + * @When I specify filter total being greater than :total + */ + public function iSpecifyFilterTotalBeingGreaterThan(string $total): void + { + if (str_contains($total, '.')) { + $total = str_replace('.', '', $total); + $this->client->addFilter('total[gt]', $total); + + return; + } + + $this->client->addFilter('total[gt]', $total . '00'); + } + + /** + * @When I specify filter total being less than :total + */ + public function iSpecifyFilterTotalBeingLessThan(string $total): void + { + $this->client->addFilter('total[lt]', $total. '00'); + } + + /** + * @When I filter by variant :variantName + * @When I filter by variants :firstVariant and :secondVariant + */ + public function iFilterByVariant(string ...$variantsNames): void + { + foreach ($variantsNames as $variantName) { + $this->client->addFilter('items.variant.translations.name[]', $variantName); + } + + $this->client->filter(); + } + + /** + * @When I switch the way orders are sorted by :fieldName + */ + public function iSwitchSortingBy(string $fieldName): void + { + $this->client->addFilter('order[number]', 'asc'); + $this->client->filter(); + } + /** * @When /^I cancel (this order)$/ */ @@ -107,15 +217,6 @@ public function iLimitNumberOfItemsTo(int $limit): void $this->client->filter(); } - /** - * @When I switch the way orders are sorted by :fieldName - */ - public function iSwitchSortingBy(string $fieldName): void - { - $this->client->addFilter(sprintf('order[%s]', $fieldName), 'asc'); - $this->client->filter(); - } - /** * @Then I should see a single order from customer :customer */ @@ -133,10 +234,11 @@ public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer): /** * @Then I should see a single order in the list + * @Then I should see :number orders in the list */ - public function iShouldSeeASingleOrderInTheList(): void + public function iShouldSeeASingleOrderInTheList(int $number = 1): void { - Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), 1); + Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $number); } /** @@ -344,6 +446,32 @@ public function iShouldSeeOrderWithNumber(string $orderNumber): void ); } + /** + * @Then I should not see an order with :orderNumber number + */ + public function iShouldNotSeeOrderWithNumber(string $orderNumber) + { + $response = $this->client->getLastResponse(); + + Assert::false( + $this->responseChecker->hasItemWithValue($response, 'number', $orderNumber), + sprintf('The order with number "%s" has been found, but should not.', $orderNumber), + ); + } + + /** + * @Then I should not see any orders with currency :currencyCode + */ + public function iShouldNotSeeAnyOrderWithCurrency(string $currencyCode): void + { + $response = $this->client->getLastResponse(); + + Assert::false( + $this->responseChecker->hasItemWithValue($response, 'currencyCode', $currencyCode), + sprintf('The order with currency code "%s" has been found, but should not.', $currencyCode), + ); + } + /** * @Then the first order should have number :number */ diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml index 3744f220ac6..4686633b874 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml @@ -23,9 +23,15 @@ GET /admin/orders - sylius.api.order_number_filter + sylius.api.order_channel_filter + sylius.api.order_currency_filter sylius.api.order_customer_filter - sylius.api.order_channel_order_filter + sylius.api.order_date_filter + sylius.api.order_number_filter + sylius.api.order_product_filter + sylius.api.order_shipping_method_filter + sylius.api.order_total_filter + sylius.api.order_variants_filter DESC diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml index e38efcd1d35..760a1457a57 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml @@ -85,6 +85,55 @@ + + + exclude_null + + + + + + + exact + + + + + + + exact + + + + + + + exact + + + + + + + exact + + + + + + + exact + + + + + + + + + + + @@ -239,13 +288,6 @@ - - - - - - - exact diff --git a/tests/Api/Responses/Expected/admin/order/gets_orders_for_customer_response.json b/tests/Api/Responses/Expected/admin/order/gets_orders_for_customer_response.json index 0ed81fc820e..3766159c110 100644 --- a/tests/Api/Responses/Expected/admin/order/gets_orders_for_customer_response.json +++ b/tests/Api/Responses/Expected/admin/order/gets_orders_for_customer_response.json @@ -62,13 +62,25 @@ }, "hydra:search": { "@type": "hydra:IriTemplate", - "hydra:template": "\/api\/v2\/admin\/orders{?order[number],customer.id,customer.id[],order[channel.code]}", + "hydra:template": "\/api\/v2\/admin\/orders{?channel.code,currencyCode,currencyCode[],customer.id,customer.id[],checkoutCompletedAt[before],checkoutCompletedAt[strictly_before],checkoutCompletedAt[after],checkoutCompletedAt[strictly_after],order[number],items.productName,items.productName[],shipments.method.code,shipments.method.code[],total[between],total[gt],total[gte],total[lt],total[lte],items.variant.translations.name,items.variant.translations.name[]}", "hydra:variableRepresentation": "BasicRepresentation", "hydra:mapping": [ { "@type": "IriTemplateMapping", - "variable": "order[number]", - "property": "number", + "variable": "channel.code", + "property": "channel.code", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "currencyCode", + "property": "currencyCode", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "currencyCode[]", + "property": "currencyCode", "required": false }, { @@ -85,8 +97,98 @@ }, { "@type": "IriTemplateMapping", - "variable": "order[channel.code]", - "property": "channel.code", + "variable": "checkoutCompletedAt[before]", + "property": "checkoutCompletedAt", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "checkoutCompletedAt[strictly_before]", + "property": "checkoutCompletedAt", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "checkoutCompletedAt[after]", + "property": "checkoutCompletedAt", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "checkoutCompletedAt[strictly_after]", + "property": "checkoutCompletedAt", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "order[number]", + "property": "number", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "items.productName", + "property": "items.productName", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "items.productName[]", + "property": "items.productName", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "shipments.method.code", + "property": "shipments.method.code", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "shipments.method.code[]", + "property": "shipments.method.code", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "total[between]", + "property": "total", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "total[gt]", + "property": "total", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "total[gte]", + "property": "total", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "total[lt]", + "property": "total", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "total[lte]", + "property": "total", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "items.variant.translations.name", + "property": "items.variant.translations.name", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "items.variant.translations.name[]", + "property": "items.variant.translations.name", "required": false } ]