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

#14952 Confirmation emails have no FROM or FROM email address 2.2.4 #15119

Closed
wants to merge 6 commits into from

Conversation

sashas777
Copy link
Contributor

Undone commit f2bfdd9 which caused issue

Description

Removed class lib/internal/Magento/Framework/Mail/Template/TransportBuilderByStore and assosiated tests for it.
The class cause the issue #14952 and was introduced because in previous releases default class lib/internal/Magento/Framework/Mail/Template/TransportBuilder didn't have the parameter $store for function public function setFromByStore($from, $store) Line 291.

Fixed Issues (if relevant)

  1. Confirmation emails have no FROM or FROM email address 2.2.4 #14952: Confirmation emails have no FROM or FROM email address 2.2.4
  2. Remove var Translator = new Translate... from every page #24: Wrong sender name/email in invoice/shipment email in multistore

Manual testing scenarios

  1. When Magento has single store view: set values at the admin Store->Configuration->General->Store Email Addresses-> Sales Representative. Make an order from storefront then check in the order success email "name from" and "email from" fields. It supposes to be matched to the admin configuration.

  2. When Magento has single store view: set values at the admin Store->Configuration->General->Store Email Addresses-> Sales Representative. Make an order from admin panel then check in the order success email "name from" and "email from" fields. It supposes to be matched to the admin configuration.

  3. When Magento has multiple store views: set different values at the admin Store->Configuration->General->Store Email Addresses-> Sales Representative.

  4. Create a new order from the storefront for each store view and look at your email to confirm these values in order confirmation email.

  5. Create a new order from the admin for each store view and look at your email to confirm these values in 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)

@sashas777 sashas777 self-assigned this May 10, 2018
@sashas777 sashas777 requested a review from RomaKis May 10, 2018 23:31
@sashas777 sashas777 requested review from sidolov and DanielRuf and removed request for RomaKis May 11, 2018 06:26
@DanielRuf
Copy link
Contributor

Undone commit f2bfdd9 which caused issue

A revert does not seem to be the right solution. There was much code added and I guess one method or some lines are just missing.

This is not how it should be fixed imho.

@sashas777
Copy link
Contributor Author

@DanielRuf

Do you have any ideas what missing? I checked if TransportBuilder class used anywhere else and it doesn't seems to be used.
As far as I can see it was introduced because core code didn't has such method. But now this additional class (transportBuilderByStore) doesn't need anymore.

@gwharton
Copy link
Contributor

I think we need to get some input from @RomaKis on what he intended to do on the original commit. Seems like it was incomplete, but was done for a reason.

Copy link
Contributor

@DanielRuf DanielRuf left a comment

Choose a reason for hiding this comment

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

Not the right solution imho.

Copy link
Contributor

@DanielRuf DanielRuf left a comment

Choose a reason for hiding this comment

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

Reverting the changes is not the solution here.

@sashas777 sashas777 requested a review from RomaKis May 14, 2018 04:09
@sashas777
Copy link
Contributor Author

@RomaKis
Any comments what would be right solution or why is t incorrect?

@RomaKis
Copy link
Contributor

RomaKis commented May 21, 2018

@sashas777, you can check the review comments from this PR #11992.

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

@gwharton
Copy link
Contributor

@RomaKis. The addition of a new class is fine, however in your implementation the new class's $message variable is never used, hence the issue #14952.

@RomaKis
Copy link
Contributor

RomaKis commented May 21, 2018

@gwharton, I can't reproduce this issue.
image

image

Steps:

  1. Fresh Magento install.
  2. Product created.
  3. Go to frontend, create customer, add product to cart, place order.
  4. Go to admin, find created order, open it and press "Send Email".
  5. Email has "From" email.

image

Do I missed something?

@gwharton
Copy link
Contributor

@RomaKis I'm not sure how your installation is working to be honest. A quick look at the code would indicate.

  1. SenderBuilder's constructor creates a copy of transportBuilder and transportBuilderByStore. These are two completely separate objects. each has its own protected member $message.
  2. A call is made to configureEmailTemplate() which configures the email template for the transportBuilder object and then sets the from address for the transportBuilderByStore object
  3. The to address is set on the transportBuilder object
  4. The message is sent using the transportBuilder object

At no point is the transportBuilderByStore object ever used, apart from having its from address set in its own protected member $message.

@RomaKis
Copy link
Contributor

RomaKis commented May 21, 2018

@gwharton and what is $message? it is object \Magento\Framework\Mail\Message injected by ObjectManager. And ObjectManager use get method. So when we inject $message in TransportBuilderByStore we will get the same object from the transportBuilder and set to it "from" email.

@gwharton
Copy link
Contributor

I don't follow. The ObjectManager's get() call in SenderBuilders constructor ensures that multiple instances of the SenderBuilder object all have the same transportBuilderByStore object, but does nothing to link it to the transportBuilder object. Please explain further.

@RomaKis
Copy link
Contributor

RomaKis commented May 21, 2018

@gwharton, we have $message object \Magento\Framework\Mail\Message in TransportBuilder. And we have the same object in TransportBuilderByStore. When we add to constructor \Magento\Framework\Mail\Message $message object manager use get() method, so it doesn't create new object of \Magento\Framework\Mail\Message it return existing.

In TransportBuilderByStore we inject \Magento\Framework\Mail\Message $message and add to it setFrom(), so object $message from TransportBuilder will have "From" email while sending it.

@gwharton
Copy link
Contributor

Whereabouts?

public function __construct(
FactoryInterface $templateFactory,
MessageInterface $message,
SenderResolverInterface $senderResolver,
ObjectManagerInterface $objectManager,
TransportInterfaceFactory $mailTransportFactory
) {
$this->templateFactory = $templateFactory;
$this->message = $message;
$this->objectManager = $objectManager;
$this->_senderResolver = $senderResolver;
$this->mailTransportFactory = $mailTransportFactory;
}

public function __construct(
MessageInterface $message,
SenderResolverInterface $senderResolver
) {
$this->message = $message;
$this->senderResolver = $senderResolver;
}

public function __construct(
Template $templateContainer,
IdentityInterface $identityContainer,
TransportBuilder $transportBuilder,
TransportBuilderByStore $transportBuilderByStore = null
) {
$this->templateContainer = $templateContainer;
$this->identityContainer = $identityContainer;
$this->transportBuilder = $transportBuilder;
$this->transportBuilderByStore = $transportBuilderByStore ?: ObjectManager::getInstance()->get(
TransportBuilderByStore::class
);
}

@RomaKis
Copy link
Contributor

RomaKis commented May 21, 2018

If you will stop here

https://github.com/magento/magento2/blob/32892a46b2682bc7745ca26a9fe3fe8e55e915d2/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php#L70

you will see that $this->transportBuilder has object $message with all necessary information.
See the screenshots above https://github.com/magento/magento2/pull/15119#issuecomment-390631010

@sashas777 sashas777 removed the request for review from sidolov May 21, 2018 20:45
@EmilyPepperman
Copy link
Contributor

Besides the "From"... looks like "Return Path" missing from emails now?

@hostep hostep mentioned this pull request Jun 24, 2018
*
* @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.

I would suggest to avoid adding new public methods when not necessary. Every public method is a kind of contract for backward compatibility.

Changing setFrom and adding an optional parameter could be a better option.

See https://github.com/magento/magento2/pull/16356/files trying to fix the same issue.

Choose a reason for hiding this comment

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

I am facing the same issue , when a customer placed an order then customer is getting the mail but not admin.. And the second thing is that it is the taking the different host as my id is socketswitches@socket-switches.com but system is sending from socketswitches@ssdvps-80478.vps.net  . ssdvps-80478.vps.net this is the server ..Any help!!!

Choose a reason for hiding this comment

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

I had tried this code but isn't working.

Copy link

@gopal2k6 gopal2k6 Jun 10, 2019

Choose a reason for hiding this comment

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

I am also facing same issue.. can you help in this ? My issue in 2.3

@phoenix128
Copy link
Contributor

FYI: Adding a corss reference with another PR trying to fix the same issue: #16356

@gwharton
Copy link
Contributor

I am going to close this PR. There have been several PRs produced that are all trying to fix the same issue. I have collated everyones opinion and generated a new PR with full test coverage, Travis pass and Codacy pass. If you would like to collaborate further on this issue, you are encouraged to do so through PR #16461

@gwharton gwharton closed this Jun 29, 2018
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.

8 participants