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

Transport Variables can not be modified for invoice and shipment mail #15152

Closed
staywithabhi opened this issue May 11, 2018 · 2 comments
Closed
Labels
Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@staywithabhi
Copy link

I am using magento 2.2.3 and have custom shipping method to magento store,every thing is working like a charm except custom details in invoice and shipment mail.Transport variables are modified for order email but not working for invoice and shipment.I have crosschecked and observer is working fine for invoice mail and shipment mail.

Preconditions

Steps to reproduce

Expected result

  1. Transport variables must be modified for invoice and shipment mail and custom details must be sent in invoice and shipment mail.

Actual result

  1. [Screenshot, logs]
    Transport variables not modified and custom data not sent in mail
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label May 11, 2018
@sashas777 sashas777 added Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed and removed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels May 11, 2018
@magento-engcom-team magento-engcom-team added Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels May 11, 2018
@gwharton
Copy link
Contributor

Setting of the transport variables was broken for ages.

An attempt to fix it was made however the fix did not cover all aspects properly. The failed fix was released in 2.2.4.

Here's the original bug report. #10210
Here is a link to the PR that partially fixed the problem #12132
Here is a link to the pull request that fixes the rest of the problem #15040

That last PR is waiting to be merged, but hopefully as of 2.2.5 all email senders will properly work with the new transportObject data parameter.

Note that following this change, the use of $transport is deprecated. You should use $transportObject instead in your observer.

Here is an example of a working observer that adds plain text billing and shipping address to the transport object.

    public function __construct(
      \Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
      \Magento\Payment\Helper\Data $paymentHelper,
      \Magento\Sales\Model\Order\Email\Container\OrderIdentity $identityContainer
    ) {
            $this->addressRenderer = $addressRenderer;
            $this->paymentHelper = $paymentHelper;
            $this->identityContainer = $identityContainer;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $transportObject = $observer->getEvent()->getData('transportObject');
        $order = $transportObject->getData('order');
        $shippingaddress = $order->getIsVirtual() ? null : $this->addressRenderer->format($order->getShippingAddress(), 'text');
        $billingaddress = $this->addressRenderer->format($order->getBillingAddress(), 'text');        
        $shippingaddress = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $shippingaddress);
        $billingaddress = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $billingaddress);
        $transportObject->setData('textShippingAddress', $shippingaddress);
        $transportObject->setData('textBillingAddress', $billingaddress);        
    }

@staywithabhi
Copy link
Author

Hi gwharton ,
Thanks for the help and references provided.Issue has been fixed by using transportObject.
Hope to see changes in latest magento release
Thank You.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests

4 participants