Skip to content
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

[Backport 2.2] Translate order getCreatedAtFormatted() to store locale #11422

Merged
merged 2 commits into from
Nov 25, 2017

Conversation

JeroenVanLeusden
Copy link
Member

@JeroenVanLeusden JeroenVanLeusden commented Oct 13, 2017

Description

Backport of version of #10491.

Add getDefaultStoreLocale() to allow fetching scoped values. Use this in getCreatedAtFormatted() so created_at date of order will be translated in emails to locale being used in that store view.

Fixed Issues (if relevant)

  1. None that I could find.

Manual testing scenarios

  1. Set default locale of your store to any language but English.
  2. Create order and send confirmation email.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@JeroenVanLeusden JeroenVanLeusden changed the title [Backport] Translate order getCreatedAtFormatted() to store locale [Backport 2.2] Translate order getCreatedAtFormatted() to store locale Oct 13, 2017
@@ -213,6 +215,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
protected $_currencyFactory;

/**
* @var \Magento\Eav\Model\Config
*/
private $_eavConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a new variable you do not need the _ at the beginning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a new variable, just a missing phpdoc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In version 2.2-develop of this file there is no such variable. https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Sales/Model/Order.php It seems be have been added to develop in you original PR. I wonder if it is a left over from when the file was created. I will see what I can find out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmanners I remember, variable was already there but never declared as a property.

https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Sales/Model/Order.php#L338

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup seems to be. My guess is we can remove the property and the mapping but leave the injection for BiC reasons. But I will dig a bit deeper to make sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, ping me if you need any changes done in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup so this looks like a left over from the M1 approach of doing things. I cannot find a usage in this class and in the history it was last changed 4 years ago. I would suggest you can remove the new property, remove the assignment in the constructor $this->_eav and add the tag @SuppressWarnings(PHPMD.UnusedFormalParameter) to the constructor phpdocs.

@@ -213,6 +215,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
protected $_currencyFactory;

/**
* @var \Magento\Eav\Model\Config
*/
private $_eavConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup so this looks like a left over from the M1 approach of doing things. I cannot find a usage in this class and in the history it was last changed 4 years ago. I would suggest you can remove the new property, remove the assignment in the constructor $this->_eav and add the tag @SuppressWarnings(PHPMD.UnusedFormalParameter) to the constructor phpdocs.

@JeroenVanLeusden
Copy link
Member Author

@dmanners I removed the variable and added the @SuppressWarnings(PHPMD.UnusedFormalParameter)

@JeroenVanLeusden
Copy link
Member Author

@dmanners Can you proceed merging? Would love to see this released in 2.2.2

@@ -310,7 +318,6 @@ public function __construct(
\Magento\Catalog\Model\Product\Visibility $productVisibility,
\Magento\Sales\Api\InvoiceManagementInterface $invoiceManagement,
\Magento\Directory\Model\CurrencyFactory $currencyFactory,
\Magento\Eav\Model\Config $eavConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot remove the injection via the __constuct without this breaking BC but you can remove the setting of $this->_eavConfig = $eavConfig; which you have done. If you add back this to the construct and docblock the rest seems fine to me

@dmanners
Copy link
Contributor

@JeroenVanLeusden while testing this our team found the following.

I couldn't see what was fixed here.
Here are the steps I used:
1. Install German thought console:
composer require splendidinternet/mage2-locale-de-de
php bin/magento setup:upgrade
php bin/magento cron:run && php bin/magento indexer:reindex && php bin/magento cache:clean
2. Go to Stores->Configurations->General->Locale Otions->Locale-> German (Germany)
3. Create a product, open storefront and order it as registered customer
4. Check Email of the customer
Expected result: 
Date of order will be translated in emails to locale being used in that store view
Actual result:
There is no difference in Emails

It seems that in the testing process both the branch for this PR and the 2.2-develop branch had the same date information in the resulting emails. Are there any special test cases that should be taken into account?

@JeroenVanLeusden
Copy link
Member Author

@dmanners Will find some time this week to check this. Will ping you with the results!

@dmanners
Copy link
Contributor

Thanks @JeroenVanLeusden if you get stuck and need some help feel free to drop me a message here on in the engcom slack.

@JeroenVanLeusden
Copy link
Member Author

@dmanners I've reproduced using the following steps:

  1. Install NL language pack, composer require honl/magento2-nl-nl:^1@dev.
  2. Set store language to Dutch (NL_nl).
  3. Create order and send confirmation email.
  4. Without this patch the date is printed as Geplaatst op 2017 M10 11 19:56:05 GMT+2 (http://cloud.h-o.nl/nmts).
  5. With this patch the date is printed as Geplaatst op 11 oktober 2017 19:56:05 CEST (http://cloud.h-o.nl/nn0T).

Using the DE language pack will give me the same results. http://cloud.h-o.nl/nmZE and with patch http://cloud.h-o.nl/nnBu

This is tested from commit d2cbddd

@dmanners
Copy link
Contributor

Thank you for the update @JeroenVanLeusden will keep you updated on the progress.

@JeroenVanLeusden
Copy link
Member Author

@dmanners I've been able to reproduce it using the following steps:

  1. Clean install from 2.2-develop branch, commit 2b78994.
  2. Install NL language pack, composer require honl/magento2-nl-nl:^1@dev.
  3. Set store language to Dutch (NL_nl).
  4. Create order and send confirmation email (date is translated correctly).
  5. Login the backend and open new order and press Send Email to send the email again.
  6. Date is now formatted using US locale.

@magento-team magento-team merged commit 02bc892 into magento:2.2-develop Nov 25, 2017
magento-team pushed a commit that referenced this pull request Nov 25, 2017
magento-team pushed a commit that referenced this pull request Nov 25, 2017
[EngCom] Public Pull Requests - 2.2-develop
 - MAGETWO-83552: save invoice ID on credit memo when using API method salesRefundInvoiceV1 #11670
 - MAGETWO-82577: [Backport 2.2] Translate order getCreatedAtFormatted() to store locale #11422
 - MAGETWO-84474: 10128: New Orders not being saved to order grid #12241
 - MAGETWO-83783: Shipping method fixtures not compatible with getShippingMethod(true) in OrderCreateTest #12227
 - MAGETWO-83290: Add swatch option: Prevent loosing data and default value if data is not populated via adminhtml #12036
 - MAGETWO-83741: 11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store #11992
 - MAGETWO-83399: Fix for remove 'product_list_toolbar' block from layout in XML #9413 #11473
@JeroenVanLeusden JeroenVanLeusden deleted the patch-4 branch December 4, 2017 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants