diff --git a/doc/swagger.yml b/doc/swagger.yml index 9f82f59cb..3c17b7a76 100644 --- a/doc/swagger.yml +++ b/doc/swagger.yml @@ -876,7 +876,6 @@ definitions: description: "Body of request used to put item to the cart." required: - "productCode" - - "quantity" properties: productCode: type: "string" @@ -885,6 +884,7 @@ definitions: type: "integer" minimum: 1 example: 3 + default: 1 variantCode: type: "string" example: "SMALL_LOGAN_T_SHIRT_CODE" diff --git a/src/Request/ChangeItemQuantityRequest.php b/src/Request/ChangeItemQuantityRequest.php index c99f67de5..fed35b221 100644 --- a/src/Request/ChangeItemQuantityRequest.php +++ b/src/Request/ChangeItemQuantityRequest.php @@ -31,7 +31,7 @@ public function __construct(Request $request) { $this->token = $request->attributes->get('token'); $this->id = $request->attributes->get('id'); - $this->quantity = $request->request->get('quantity'); + $this->quantity = $request->request->getInt('quantity'); } /** diff --git a/src/Request/PutOptionBasedConfigurableItemToCartRequest.php b/src/Request/PutOptionBasedConfigurableItemToCartRequest.php index 490ea392a..82089974f 100644 --- a/src/Request/PutOptionBasedConfigurableItemToCartRequest.php +++ b/src/Request/PutOptionBasedConfigurableItemToCartRequest.php @@ -44,7 +44,7 @@ public static function fromArray(array $item) public static function fromRequest(Request $request) { - return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('options'), $request->request->get('quantity')); + return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('options'), $request->request->getInt('quantity', 1)); } /** diff --git a/src/Request/PutSimpleItemToCartRequest.php b/src/Request/PutSimpleItemToCartRequest.php index 817729620..0e824823b 100644 --- a/src/Request/PutSimpleItemToCartRequest.php +++ b/src/Request/PutSimpleItemToCartRequest.php @@ -38,7 +38,7 @@ public static function fromArray(array $item) public static function fromRequest(Request $request) { - return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('quantity')); + return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->getInt('quantity', 1)); } /** diff --git a/src/Request/PutVariantBasedConfigurableItemToCartRequest.php b/src/Request/PutVariantBasedConfigurableItemToCartRequest.php index 25d087404..1564abbe0 100644 --- a/src/Request/PutVariantBasedConfigurableItemToCartRequest.php +++ b/src/Request/PutVariantBasedConfigurableItemToCartRequest.php @@ -44,7 +44,7 @@ public static function fromArray(array $item) public static function fromRequest(Request $request) { - return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('variantCode'), $request->request->get('quantity')); + return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('variantCode'), $request->request->getInt('quantity', 1)); } /** diff --git a/tests/Controller/CartChangeItemQuantityApiTest.php b/tests/Controller/CartChangeItemQuantityApiTest.php index 7a3ae87b8..0190e4bef 100644 --- a/tests/Controller/CartChangeItemQuantityApiTest.php +++ b/tests/Controller/CartChangeItemQuantityApiTest.php @@ -102,7 +102,7 @@ public function it_does_not_allow_to_change_quantity_without_quantity_defined() $this->client->request('PUT', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/1', [], [], static::$acceptAndContentTypeHeader); $response = $this->client->getResponse(); - $this->assertResponse($response, 'cart/validation_quantity_not_defined_response', Response::HTTP_BAD_REQUEST); + $this->assertResponse($response, 'cart/validation_quantity_lower_than_one_response', Response::HTTP_BAD_REQUEST); } /** diff --git a/tests/Controller/CartPutItemToCartApiTest.php b/tests/Controller/CartPutItemToCartApiTest.php index d1cc782eb..da10633e7 100644 --- a/tests/Controller/CartPutItemToCartApiTest.php +++ b/tests/Controller/CartPutItemToCartApiTest.php @@ -99,31 +99,6 @@ public function it_validates_if_product_is_simple_during_add_simple_product() $this->assertResponse($response, 'cart/validation_product_not_simple_response', Response::HTTP_BAD_REQUEST); } - /** - * @test - */ - public function it_validates_if_request_has_quantity_during_add_simple_product() - { - $this->loadFixturesFromFile('shop.yml'); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var CommandBus $bus */ - $bus = $this->get('tactician.commandbus'); - $bus->handle(new PickupCart($token, 'WEB_GB')); - - $data = -<<client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], static::$acceptAndContentTypeHeader, $data); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'cart/validation_quantity_not_defined_response', Response::HTTP_BAD_REQUEST); - } - /** * @test */ @@ -153,7 +128,7 @@ public function it_validates_if_quantity_is_larger_than_0_during_add_simple_prod /** * @test */ - public function it_validates_if_quantity_is_is_an_integer_during_add_simple_product() + public function it_converts_quantity_as_an_integer_and_adds_simple_product() { $this->loadFixturesFromFile('shop.yml'); @@ -173,7 +148,7 @@ public function it_validates_if_quantity_is_is_an_integer_during_add_simple_prod $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], static::$acceptAndContentTypeHeader, $data); $response = $this->client->getResponse(); - $this->assertResponse($response, 'cart/validation_quantity_not_integer_response', Response::HTTP_BAD_REQUEST); + $this->assertResponse($response, 'cart/add_simple_product_to_cart_response', Response::HTTP_CREATED); } /** @@ -361,32 +336,6 @@ public function it_increases_quantity_of_existing_item_if_the_same_variant_is_ad $this->assertResponse($response, 'cart/add_product_variant_multiple_times_to_cart_response', Response::HTTP_CREATED); } - /** - * @test - */ - public function it_validates_if_request_has_quantity_during_add_variant_based_configurable_product() - { - $this->loadFixturesFromFile('shop.yml'); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var CommandBus $bus */ - $bus = $this->get('tactician.commandbus'); - $bus->handle(new PickupCart($token, 'WEB_GB')); - - $data = -<<client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], static::$acceptAndContentTypeHeader, $data); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'cart/validation_quantity_not_defined_response', Response::HTTP_BAD_REQUEST); - } - /** * @test */ @@ -417,7 +366,7 @@ public function it_validates_if_quantity_is_larger_than_0_during_add_variant_bas /** * @test */ - public function it_validates_if_quantity_is_is_an_integer_during_add_variant_based_configurable_product() + public function it_converts_quantity_as_an_integer_and_adds_variant_based_configurable_product() { $this->loadFixturesFromFile('shop.yml'); @@ -438,7 +387,7 @@ public function it_validates_if_quantity_is_is_an_integer_during_add_variant_bas $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], static::$acceptAndContentTypeHeader, $data); $response = $this->client->getResponse(); - $this->assertResponse($response, 'cart/validation_quantity_not_integer_response', Response::HTTP_BAD_REQUEST); + $this->assertResponse($response, 'cart/add_product_variant_to_cart_response', Response::HTTP_CREATED); } /** diff --git a/tests/Responses/Expected/cart/validation_quantity_not_defined_response.json b/tests/Responses/Expected/cart/validation_quantity_not_defined_response.json deleted file mode 100644 index 2f4d2a462..000000000 --- a/tests/Responses/Expected/cart/validation_quantity_not_defined_response.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "code": 400, - "message": "Validation failed", - "errors": { - "quantity": [ - "sylius.shop_api.quantity.not_null" - ] - } -} diff --git a/tests/Responses/Expected/cart/validation_quantity_not_integer_response.json b/tests/Responses/Expected/cart/validation_quantity_not_integer_response.json deleted file mode 100644 index c2a66cdf9..000000000 --- a/tests/Responses/Expected/cart/validation_quantity_not_integer_response.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "code": 400, - "message": "Validation failed", - "errors": { - "quantity": [ - "sylius.shop_api.quantity.type_integer" - ] - } -}