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

11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store #11992

Merged
merged 5 commits into from
Nov 25, 2017

Conversation

RomaKis
Copy link
Contributor

@RomaKis RomaKis commented Nov 3, 2017

Description

Sending emails from Admin in Multi-Store Environment defaults to Primary Store

Fixed Issues (if relevant)

  1. Sending emails from Admin in Multi-Store Environment defaults to Primary Store #11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store

Manual testing scenarios

  1. Create two websites: ABC.com (primary) and XYZ.com each with its store/storeview accordingly.
  2. Make sure You have a different Sender Name and Sender Email for XYZ.com from ABC.com (Configuration -> General -> Store Email Address -> Sales Representative).
  3. Have customer place order on XYZ.com.
  4. Go into admin, click on order from XYZ.com, and resend order 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)

@magento-engcom-team magento-engcom-team added 2.2.x Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 7, 2017
@ishakhsuvarov ishakhsuvarov self-assigned this Nov 13, 2017
@ishakhsuvarov ishakhsuvarov added this to the November 2017 milestone Nov 13, 2017
* @param string|int $store
* @return $this
*/
public function setFromByStore($from, $store)
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not encouraged to add new public methods in classes marked as api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ishakhsuvarov, fixed. I created separate class. Notify me if you accept these changes, i'll squash commits.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a hack. Surely the correct decision should have been to mark the old setFrom function as deprecated and introduce a new working function, setFromByStore in the API.

The resulting fix that was implemented was not good, involving making objects static that shouldnt have been static, to allow other classes access its protected members. This is far worse in my opinion and has already lead to two further issues being raised caused by this commit. Can this not be looked at again and fixed properly instead of the hack that is currently in place to avoid changing the transportBuilder class.

Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a comment

Choose a reason for hiding this comment

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

Looks like solution may be simplified

*
* @return $this
*/
public function setFromByStore($from, $store)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason to introduce another class and method instead of just adding an optional parameter scopeId to \Magento\Framework\Mail\Template\TransportBuilder::setFrom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ishakhsuvarov, is it allowed? According to the backward compatibility(http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html) seems it is prohibited.
May I add optional parameter scopeId?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. I overlooked that for this case

@magento-team magento-team merged commit b322718 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
@gwharton
Copy link
Contributor

@RomaKis This commit breaks situations where Magento sends multiple emails at the same time.

Just before senderBuilder sends the email it calls transportBuilder->getTransport() which resets the email ready for the next one. This includes instantiating a new $message object. From this point onwards the $message object is no longer statically shared with transportBuilderByStore.

On sending the second, and subsequent emails, the function fails becasuse although transportBuilder has a nice new fresh $message object to work on, transportBuilderByStore does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants