mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Cart] move locale from body to header
This commit is contained in:
parent
089c111f20
commit
5a97ac2586
12 changed files with 121 additions and 40 deletions
|
|
@ -72,6 +72,7 @@ Here is how the response looks like:
|
|||
|
||||
1. The 2nd parameter `MetadataInterface` has been removed from `src/Sylius/Bundle/ApiBundle/CommandHandler/Account/ResetPasswordHandler` and replaced by `Sylius\Component\User\Security\PasswordUpdaterInterface` (previously 3rd parameter). From now on a token TTL value must be used instead as the 3rd parameter.
|
||||
|
||||
<<<<<<< HEAD
|
||||
1. Constructor of `Sylius\Bundle\ApiBundle\CommandHandler\Account\RequestResetPasswordTokenHandler` has been extended with `Sylius\Calendar\Provider\DateTimeProviderInterface` argument:
|
||||
|
||||
```diff
|
||||
|
|
@ -96,3 +97,5 @@ Here is how the response looks like:
|
|||
+ ) {
|
||||
}
|
||||
```
|
||||
|
||||
1. The 2nd parameter `localeCode` has been removed from `src/Sylius/Bundle/ApiBundle/Command/Cart/PickupCart.php` and now is set automatically by `src/Sylius/Bundle/ApiBundle/DataTransformer/LocaleCodeAwareInputCommandDataTransformer.php`.
|
||||
|
|
|
|||
|
|
@ -7,10 +7,17 @@ Feature: Picking up the cart with the locale other than the default
|
|||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And that channel allows to shop using "English (United States)" and "French (France)" locales
|
||||
And this channel uses the "French (France)" locale as default
|
||||
And I am a logged in customer
|
||||
|
||||
@api
|
||||
Scenario: Picking up the cart with the locale other than default
|
||||
When I pick up cart in the "French (France)" locale
|
||||
When I pick up cart in the "English (United States)" locale
|
||||
And I check details of my cart
|
||||
Then my cart's locale should be "English (United States)"
|
||||
|
||||
@api
|
||||
Scenario: Picking up the cart without specified locale
|
||||
When I pick up cart
|
||||
And I check details of my cart
|
||||
Then my cart's locale should be "French (France)"
|
||||
|
|
|
|||
|
|
@ -163,13 +163,15 @@ final class Request implements RequestInterface
|
|||
);
|
||||
}
|
||||
|
||||
public static function custom(string $url, string $method, ?string $token = null): RequestInterface
|
||||
public static function custom(string $url, string $method, array $additionalHeaders = [], ?string $token = null): RequestInterface
|
||||
{
|
||||
$headers = ['CONTENT_TYPE' => self::resolveHttpMethod($method)];
|
||||
if ($token !== null) {
|
||||
$headers['HTTP_Authorization'] = 'Bearer ' . $token;
|
||||
}
|
||||
|
||||
$headers = array_merge($headers, $additionalHeaders);
|
||||
|
||||
return new self($url, $method, $headers);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ interface RequestInterface
|
|||
?string $token = null
|
||||
): self;
|
||||
|
||||
public static function custom(string $url, string $method, ?string $token = null): self;
|
||||
public static function custom(string $url, string $method, array $additionalHeaders = [], ?string $token = null): self;
|
||||
|
||||
public function url(): string;
|
||||
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ final class CartContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @When I pick up my cart (again)
|
||||
* @When I pick up (my )cart (again)
|
||||
* @When I pick up cart in the :localeCode locale
|
||||
* @When the visitor picks up the cart
|
||||
*/
|
||||
|
|
@ -677,10 +677,11 @@ final class CartContext implements Context
|
|||
|
||||
private function pickupCart(?string $localeCode = null): string
|
||||
{
|
||||
$this->cartsClient->buildCreateRequest();
|
||||
$this->cartsClient->addRequestData('localeCode', $localeCode);
|
||||
$request = Request::custom('/api/v2/shop/orders', HttpRequest::METHOD_POST, ['HTTP_ACCEPT_LANGUAGE' => $localeCode]);
|
||||
|
||||
$tokenValue = $this->responseChecker->getValue($this->cartsClient->create(), 'tokenValue');
|
||||
$this->cartsClient->executeCustomRequest($request);
|
||||
|
||||
$tokenValue = $this->responseChecker->getValue($this->cartsClient->getLastResponse(), 'tokenValue');
|
||||
|
||||
$this->sharedStorage->set('cart_token', $tokenValue);
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ final class OrderContext implements Context
|
|||
(string) $order->getPayments()->first()->getId()
|
||||
),
|
||||
HttpRequest::METHOD_PATCH,
|
||||
[],
|
||||
$this->shopOrderClient->getToken()
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ namespace Sylius\Bundle\ApiBundle\Command\Cart;
|
|||
|
||||
use Sylius\Bundle\ApiBundle\Command\CustomerEmailAwareInterface;
|
||||
use Sylius\Bundle\ApiBundle\Command\ChannelCodeAwareInterface;
|
||||
use Sylius\Bundle\ApiBundle\Command\LocaleCodeAwareInterface;
|
||||
|
||||
/** @experimental */
|
||||
class PickupCart implements ChannelCodeAwareInterface, CustomerEmailAwareInterface
|
||||
class PickupCart implements ChannelCodeAwareInterface, CustomerEmailAwareInterface, LocaleCodeAwareInterface
|
||||
{
|
||||
/**
|
||||
* @psalm-immutable
|
||||
|
|
@ -25,7 +26,6 @@ class PickupCart implements ChannelCodeAwareInterface, CustomerEmailAwareInterfa
|
|||
public $tokenValue;
|
||||
|
||||
/**
|
||||
* @psalm-immutable
|
||||
* @var string|null
|
||||
*/
|
||||
public $localeCode;
|
||||
|
|
@ -40,10 +40,9 @@ class PickupCart implements ChannelCodeAwareInterface, CustomerEmailAwareInterfa
|
|||
*/
|
||||
public $email;
|
||||
|
||||
public function __construct(?string $tokenValue = null, ?string $localeCode = null)
|
||||
public function __construct(?string $tokenValue = null)
|
||||
{
|
||||
$this->tokenValue = $tokenValue;
|
||||
$this->localeCode = $localeCode;
|
||||
}
|
||||
|
||||
public function getChannelCode(): ?string
|
||||
|
|
@ -65,4 +64,14 @@ class PickupCart implements ChannelCodeAwareInterface, CustomerEmailAwareInterfa
|
|||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function getLocaleCode(): ?string
|
||||
{
|
||||
return $this->localeCode;
|
||||
}
|
||||
|
||||
public function setLocaleCode(?string $localeCode): void
|
||||
{
|
||||
$this->localeCode = $localeCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@
|
|||
<attribute name="groups">shop:order:create</attribute>
|
||||
</attribute>
|
||||
<attribute name="openapi_context">
|
||||
<attribute name="summary">Pickups a new cart. Provided locale code has to be one of available for a particular channel.</attribute> </attribute>
|
||||
<attribute name="summary">Pickups a new cart</attribute>
|
||||
</attribute>
|
||||
</collectionOperation>
|
||||
|
||||
<collectionOperation name="shop_get">
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" ?>
|
||||
|
||||
<!--
|
||||
|
||||
This file is part of the Sylius package.
|
||||
|
||||
(c) Paweł Jędrzejewski
|
||||
|
||||
For the full copyright and license information, please view the LICENSE
|
||||
file that was distributed with this source code.
|
||||
|
||||
-->
|
||||
|
||||
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
|
||||
>
|
||||
<class name="Sylius\Bundle\ApiBundle\Command\Cart\PickupCart">
|
||||
<attribute name="localeCode">
|
||||
<group>shop:order:create</group>
|
||||
</attribute>
|
||||
</class>
|
||||
</serializer>
|
||||
22
tests/Api/Responses/Expected/shop/create_cart_response.json
Normal file
22
tests/Api/Responses/Expected/shop/create_cart_response.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Order",
|
||||
"@id": @string@,
|
||||
"@type": "Order",
|
||||
"channel": "\/api\/v2\/shop\/channels\/WEB",
|
||||
"payments": [],
|
||||
"shipments": [],
|
||||
"currencyCode": "USD",
|
||||
"localeCode": "pl_PL",
|
||||
"checkoutState": "cart",
|
||||
"paymentState": "cart",
|
||||
"shippingState": "cart",
|
||||
"tokenValue": @string@,
|
||||
"id": @integer@,
|
||||
"items": [],
|
||||
"itemsTotal": 0,
|
||||
"total": 0,
|
||||
"state": "cart",
|
||||
"taxTotal": 0,
|
||||
"shippingTotal": 0,
|
||||
"orderPromotionTotal": 0
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Order",
|
||||
"@id": @string@,
|
||||
"@type": "Order",
|
||||
"channel": "\/api\/v2\/shop\/channels\/WEB",
|
||||
"payments": [],
|
||||
"shipments": [],
|
||||
"currencyCode": "USD",
|
||||
"localeCode": "en_US",
|
||||
"checkoutState": "cart",
|
||||
"paymentState": "cart",
|
||||
"shippingState": "cart",
|
||||
"tokenValue": @string@,
|
||||
"id": @integer@,
|
||||
"items": [],
|
||||
"itemsTotal": 0,
|
||||
"total": 0,
|
||||
"state": "cart",
|
||||
"taxTotal": 0,
|
||||
"shippingTotal": 0,
|
||||
"orderPromotionTotal": 0
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ final class OrdersTest extends JsonApiTestCase
|
|||
/** @var MessageBusInterface $commandBus */
|
||||
$commandBus = $this->get('sylius.command_bus');
|
||||
|
||||
$pickupCartCommand = new PickupCart($tokenValue, 'en_US');
|
||||
$pickupCartCommand = new PickupCart($tokenValue);
|
||||
$pickupCartCommand->setChannelCode('WEB');
|
||||
$commandBus->dispatch($pickupCartCommand);
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ final class OrdersTest extends JsonApiTestCase
|
|||
/** @var MessageBusInterface $commandBus */
|
||||
$commandBus = $this->get('sylius.command_bus');
|
||||
|
||||
$pickupCartCommand = new PickupCart($tokenValue, 'en_US');
|
||||
$pickupCartCommand = new PickupCart($tokenValue);
|
||||
$pickupCartCommand->setChannelCode('WEB');
|
||||
$commandBus->dispatch($pickupCartCommand);
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ final class OrdersTest extends JsonApiTestCase
|
|||
/** @var MessageBusInterface $commandBus */
|
||||
$commandBus = $this->get('sylius.command_bus');
|
||||
|
||||
$pickupCartCommand = new PickupCart($tokenValue, 'en_US');
|
||||
$pickupCartCommand = new PickupCart($tokenValue);
|
||||
$pickupCartCommand->setChannelCode('WEB');
|
||||
$commandBus->dispatch($pickupCartCommand);
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ final class OrdersTest extends JsonApiTestCase
|
|||
/** @var MessageBusInterface $commandBus */
|
||||
$commandBus = $this->get('sylius.command_bus');
|
||||
|
||||
$pickupCartCommand = new PickupCart($tokenValue, 'en_US');
|
||||
$pickupCartCommand = new PickupCart($tokenValue);
|
||||
$pickupCartCommand->setChannelCode('WEB');
|
||||
$commandBus->dispatch($pickupCartCommand);
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ final class OrdersTest extends JsonApiTestCase
|
|||
/** @var MessageBusInterface $commandBus */
|
||||
$commandBus = $this->get('sylius.command_bus');
|
||||
|
||||
$pickupCartCommand = new PickupCart($tokenValue, 'en_US');
|
||||
$pickupCartCommand = new PickupCart($tokenValue);
|
||||
$pickupCartCommand->setChannelCode('WEB');
|
||||
$commandBus->dispatch($pickupCartCommand);
|
||||
|
||||
|
|
@ -220,4 +220,40 @@ final class OrdersTest extends JsonApiTestCase
|
|||
|
||||
$this->assertResponse($response, 'shop/updated_payment_method_on_order_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_empty_cart_with_provided_locale(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml']);
|
||||
|
||||
$this->client->request(
|
||||
'POST',
|
||||
'/api/v2/shop/orders',
|
||||
[],
|
||||
[],
|
||||
['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json', 'HTTP_ACCEPT_LANGUAGE' => 'pl_PL'],
|
||||
json_encode([])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/create_cart_response', Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_empty_cart_with_default_locale(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml']);
|
||||
|
||||
$this->client->request(
|
||||
'POST',
|
||||
'/api/v2/shop/orders',
|
||||
[],
|
||||
[],
|
||||
['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'],
|
||||
json_encode([])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/create_cart_with_default_locale_response', Response::HTTP_CREATED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue