-
Notifications
You must be signed in to change notification settings - Fork 89
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
Allow customizing picked up cart's locale #644
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Dimosthenis,
thanks for your proposal. Changing cart locale makes absolute sense. However, instead of adding query
parameter to the request, it should be fetched from LocaleContext to allow different ways of fetching it.
I have made the requested changes so that For |
Yeah localization is indeed still a problem in the ShopApi. But this looks good. I would prefer to move it in to the main provider and then add an interface that only specifies the class PickUpCartCommand implements LocaleNeededInterface {
private $localeCode;
// Normal code
public function setLocale(string $localeCode): void
{
$this->localeCode = $localeCode;
}
} and then public function getCommand(Request $httpRequest): CommandInterface
{
$command = $this->transformHttpRequest($httpRequest)->getCommand();
if ($command instanceof LocaleNeededInterface) {
// Get locale somehow
$command->setLocale($locale);
}
return $command;
} Maybe even the |
That approach makes a lot of sense. I'll try to implement it that way and get back. |
@mamazu I have reimplemented it the way you mentioned. I didn't use Symfony's I implemented it in a way that allows localeContext to be nullable to avoid BC breaks if someone has decorated the provider or extended the command. I can't see a way that it might break but if you do please let me know. |
Looks good. This could be then extended to all other commands. |
Thank you, Dimosthenis! 🎉 |
{ | ||
Assert::implementsInterface($requestClass, ChannelBasedRequestInterface::class); | ||
|
||
$this->requestClass = $requestClass; | ||
$this->validator = $validator; | ||
$this->localeContext = $localeContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should trigger error if it won't be defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean because of backwards compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to inform people that it will be in future required and not passing it is deprecated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Currently when picking up a new cart, the default channel locale is always used.
This PR fixes this by enabling the use of an optional ?locale URL parameter to customize the cart's locale.