-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Translate order getCreatedAtFormatted() to store locale #10491
Conversation
You cannot add new methods into existing |
@orlangur creating a new implementation and use that in |
I think Any idea why So, I wouldn't recommend to introduce any |
@orlangur After some more debugging I found the real issue.
Then in the In my opinion the best solution would be to emulate the store locale in |
Do we need to really emulate locale or it's enough to pass proper locale in
? |
@orlangur Yes, if you have the proper locale you can insert it there. Using |
Not sure, please try it. Please go this way, if Please force push into the same branch with a single commit when it is ready (i.e. works & builds are green). |
@orlangur Tested and works. Tests are green, only one job exceeded the maximum time limit for jobs, and has been terminated. |
@@ -214,6 +216,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface | |||
protected $_currencyFactory; | |||
|
|||
/** | |||
* @var \Magento\Eav\Model\Config | |||
*/ | |||
protected $_eavConfig; |
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.
Thanks for noticing this 👍
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.
No need to make it private I believe, not sure it will even pass the tests this way.
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.
@orlangur It was dynamically declared (read: public), making it private may break things in 3rd party code?
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.
I would give it a try and if no core tests are broken leave it private
.
I believe if any extension relied on this property as public it's totally weird, inheritance from core classes is not recommended and property is not marked as @api
.
@@ -269,6 +276,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface | |||
protected $timezone; | |||
|
|||
/** | |||
* @var ResolverInterface | |||
*/ | |||
protected $localeResolver; |
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.
Please make it private (this is a rule for any new class properties/methods).
@@ -1831,7 +1847,7 @@ public function getCreatedAtFormatted($format) | |||
new \DateTime($this->getCreatedAt()), | |||
$format, | |||
$format, | |||
null, | |||
$this->localeResolver->getDefaultLocale(), |
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.
Seems like this public method can be easily covered with unit test, however, as there is no logic and we just call method of another class with a bunch of arguments I do not insist.
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.
It indeed calls public methods, making a test would be duplicate I guess?
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.
Nope, mock this dependency, the only thing to be asserted that we are passing concrete locale and not null
.
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.
Will do that later today and notify you when ready!
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.
Thanks for keeping me updated, waiting for a ping.
@JeroenVanLeusden cool job! Please do an amend commit + force push (only protected -> private for one field is a necessary field, other is at your discretion) and I will proceed with merging. |
@orlangur Want to test if the dependency is not
Or if the |
@JeroenVanLeusden NotNull is bad practice, some good-looking locale string like |
@orlangur Still getting used to Magento's tests please bare with me :)
Taken this looking from other tests but this doesn't work, method isn't being called. Also would like to test with some different languages then just |
@JeroenVanLeusden just make sure that you passed As I mentioned, better use some non-default locale like There is no need to assert that |
@JeroenVanLeusden feel free to push your test even if it does not work yet, I'll do necessary changes, push and then you'll squash all changes into single commit again. |
@orlangur Pushed my changes so far. |
@orlangur Any progress with the tests? Would love to see this merged. |
@JeroenVanLeusden, yeah, I'll have some time to work on this today, stay tuned. |
So, here is an example of appropriate test: orlangur@9e58ec2 Main idea behind unit tests is that we call only public methods of object under test and all other classes should be replaced with mocks (so, for example, Please rebase against |
@orlangur Getting an |
@JeroenVanLeusden, I mentioned this, it is called now |
…always backend language
@orlangur My bad, all good now! |
Description
Updated version of #10390, added new interface method en deprecated the current one.
Add
getDefaultStoreLocale()
to allow fetching scoped values. Use this ingetCreatedAtFormatted()
socreated_at
date of order will be translated in emails to locale being used in that store view.Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist