magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Resending order email from admin (Multi-store) #11695

Closed srenon closed 4 years ago

srenon commented 6 years ago

Preconditions

  1. Magento 2.0-2.2 (CE/EE)

This issue is not that obvious in core Magento but does exist and become a bigger issue when using third party SMTP extension https://github.com/magepal/magento2-gmailsmtpapp (I.e https://github.com/magepal/magento2-gmailsmtpapp/issues/75 https://github.com/magepal/magento2-gmailsmtpapp/issues/49) or any code/plugin that needs to know the correct store or ScopeConfigInterface during code execution.

Basic steps to reproduce (but this issue is much deeper and does affect other areas)

  1. Create a multi-store environment image

  2. Set different value in each store for the "port" (i.e 251 & 252)

image

  1. Place an order in each store image

  2. Set a breakpoint in /app/code/Magento/Email/Model/Plugin/WindowsSmtpConfig.php

image

  1. Click "Send Email" from each store then check the value of $this->config->getValue(self::XML_SMTP_PORT)

image

Expected result

  1. To get the correct value of the "port" number set in each store

Actual result

  1. The "port number" will be the same regardless of which store it is sent from.

In Magento1.x you use a combination of startEnvironmentEmulation() and setting the storeId to prevent this issue.

https://github.com/OpenMage/magento-mirror/blob/magento-1.7/app/code/core/Mage/Sales/Model/Order.php

/**
 * Send email with order data
 *
 * @return Mage_Sales_Model_Order
 */
public function sendNewOrderEmail()
{
    $storeId = $this->getStore()->getId();
    if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
        return $this;
    }
    // Get the destination email addresses to send copies to
    $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
    $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
    // Start store emulation process
    $appEmulation = Mage::getSingleton('core/app_emulation');
    $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php#L135

orlangur commented 6 years ago

Code snippet provided seems to be Windows-specific, do you face with any problems on a supported operating system?

UPD: oh, sorry, breakpoint is outside of condition. Disregard my question.

srenon commented 6 years ago

Just to clarify, the bigger issue is that you can not get the store scope (store id, etc), because it will always be the default regardless of what store you are resending the email from.

magento-engcom-team commented 6 years ago

@srenon, thank you for your report. We've created internal ticket(s) MAGETWO-83361 to track progress on the issue.

magefan commented 6 years ago

mageconf

magento-engcom-team commented 6 years ago

@magefan thank you for joining. Please accept team invitation here and self-assign the issue.

magento-engcom-team commented 4 years ago

Unfortunately, we are archiving this ticket now as it did not get much attention from both Magento Community and Core developers for an extended period. This is done in an effort to create a quality, community-driven backlog which will allow us to allocate the required attention more easily.

Please feel free to comment or reopen according to the Issue reporting guidelines the ticket if you are still facing this issue on the latest 2.x-develop branch. Thank you for collaboration.