Skip to content

Commit 4cab163

Browse files
committed
Merge branch 'ACP2E-47' of https://github.com/magento-l3/magento2ce into PR-2-2021-25-11
2 parents 21fcd2d + a4c82d4 commit 4cab163

15 files changed

+171
-38
lines changed

app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoCommentSender.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Sales\Model\Order\Email\Sender;
77

8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\ObjectManager;
810
use Magento\Sales\Model\Order;
911
use Magento\Sales\Model\Order\Creditmemo;
1012
use Magento\Sales\Model\Order\Email\Container\CreditmemoCommentIdentity;
@@ -13,10 +15,8 @@
1315
use Magento\Sales\Model\Order\Address\Renderer;
1416
use Magento\Framework\Event\ManagerInterface;
1517
use Magento\Framework\DataObject;
18+
use Magento\Store\Model\App\Emulation;
1619

17-
/**
18-
* Class CreditmemoCommentSender
19-
*/
2020
class CreditmemoCommentSender extends NotifySender
2121
{
2222
/**
@@ -31,25 +31,33 @@ class CreditmemoCommentSender extends NotifySender
3131
*/
3232
protected $eventManager;
3333

34+
/**
35+
* @var Emulation
36+
*/
37+
private $appEmulation;
38+
3439
/**
3540
* @param Template $templateContainer
3641
* @param CreditmemoCommentIdentity $identityContainer
3742
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
3843
* @param \Psr\Log\LoggerInterface $logger
3944
* @param Renderer $addressRenderer
4045
* @param ManagerInterface $eventManager
46+
* @param Emulation|null $appEmulation
4147
*/
4248
public function __construct(
4349
Template $templateContainer,
4450
CreditmemoCommentIdentity $identityContainer,
4551
\Magento\Sales\Model\Order\Email\SenderBuilderFactory $senderBuilderFactory,
4652
\Psr\Log\LoggerInterface $logger,
4753
Renderer $addressRenderer,
48-
ManagerInterface $eventManager
54+
ManagerInterface $eventManager,
55+
Emulation $appEmulation = null
4956
) {
5057
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
5158
$this->addressRenderer = $addressRenderer;
5259
$this->eventManager = $eventManager;
60+
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()->get(Emulation::class);
5361
}
5462

5563
/**
@@ -64,7 +72,7 @@ public function send(Creditmemo $creditmemo, $notify = true, $comment = '')
6472
{
6573
$order = $creditmemo->getOrder();
6674
$this->identityContainer->setStore($order->getStore());
67-
75+
$this->appEmulation->startEnvironmentEmulation($order->getStoreId(), Area::AREA_FRONTEND, true);
6876
$transport = [
6977
'order' => $order,
7078
'creditmemo' => $creditmemo,
@@ -79,6 +87,7 @@ public function send(Creditmemo $creditmemo, $notify = true, $comment = '')
7987
]
8088
];
8189
$transportObject = new DataObject($transport);
90+
$this->appEmulation->stopEnvironmentEmulation();
8291

8392
/**
8493
* Event argument `transport` is @deprecated. Use `transportObject` instead.

app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoSender.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Sales\Model\Order\Email\Sender;
77

8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\ObjectManager;
810
use Magento\Payment\Helper\Data as PaymentHelper;
911
use Magento\Sales\Model\Order;
1012
use Magento\Sales\Model\Order\Creditmemo;
@@ -15,6 +17,7 @@
1517
use Magento\Sales\Model\Order\Address\Renderer;
1618
use Magento\Framework\Event\ManagerInterface;
1719
use Magento\Framework\DataObject;
20+
use Magento\Store\Model\App\Emulation;
1821

1922
/**
2023
* Sends order creditmemo email to the customer.
@@ -52,6 +55,11 @@ class CreditmemoSender extends Sender
5255
*/
5356
protected $eventManager;
5457

58+
/**
59+
* @var Emulation
60+
*/
61+
private $appEmulation;
62+
5563
/**
5664
* @param Template $templateContainer
5765
* @param CreditmemoIdentity $identityContainer
@@ -62,6 +70,9 @@ class CreditmemoSender extends Sender
6270
* @param CreditmemoResource $creditmemoResource
6371
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
6472
* @param ManagerInterface $eventManager
73+
* @param Emulation|null $appEmulation
74+
*
75+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6576
*/
6677
public function __construct(
6778
Template $templateContainer,
@@ -72,14 +83,16 @@ public function __construct(
7283
PaymentHelper $paymentHelper,
7384
CreditmemoResource $creditmemoResource,
7485
\Magento\Framework\App\Config\ScopeConfigInterface $globalConfig,
75-
ManagerInterface $eventManager
86+
ManagerInterface $eventManager,
87+
Emulation $appEmulation = null
7688
) {
7789
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
7890
$this->paymentHelper = $paymentHelper;
7991
$this->creditmemoResource = $creditmemoResource;
8092
$this->globalConfig = $globalConfig;
8193
$this->addressRenderer = $addressRenderer;
8294
$this->eventManager = $eventManager;
95+
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()->get(Emulation::class);
8396
}
8497

8598
/**
@@ -105,6 +118,7 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
105118

106119
if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
107120
$order = $creditmemo->getOrder();
121+
$this->appEmulation->startEnvironmentEmulation($order->getStoreId(), Area::AREA_FRONTEND, true);
108122
$transport = [
109123
'order' => $order,
110124
'order_id' => $order->getId(),
@@ -124,6 +138,7 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
124138
]
125139
];
126140
$transportObject = new DataObject($transport);
141+
$this->appEmulation->stopEnvironmentEmulation();
127142

128143
/**
129144
* Event argument `transport` is @deprecated. Use `transportObject` instead.

app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceCommentSender.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Sales\Model\Order\Email\Sender;
77

8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\ObjectManager;
810
use Magento\Sales\Model\Order;
911
use Magento\Sales\Model\Order\Email\Container\InvoiceCommentIdentity;
1012
use Magento\Sales\Model\Order\Email\Container\Template;
@@ -13,10 +15,8 @@
1315
use Magento\Sales\Model\Order\Address\Renderer;
1416
use Magento\Framework\Event\ManagerInterface;
1517
use Magento\Framework\DataObject;
18+
use Magento\Store\Model\App\Emulation;
1619

17-
/**
18-
* Class InvoiceCommentSender
19-
*/
2020
class InvoiceCommentSender extends NotifySender
2121
{
2222
/**
@@ -31,25 +31,33 @@ class InvoiceCommentSender extends NotifySender
3131
*/
3232
protected $eventManager;
3333

34+
/**
35+
* @var Emulation
36+
*/
37+
private $appEmulation;
38+
3439
/**
3540
* @param Template $templateContainer
3641
* @param InvoiceCommentIdentity $identityContainer
3742
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
3843
* @param \Psr\Log\LoggerInterface $logger
3944
* @param Renderer $addressRenderer
4045
* @param ManagerInterface $eventManager
46+
* @param Emulation|null $appEmulation
4147
*/
4248
public function __construct(
4349
Template $templateContainer,
4450
InvoiceCommentIdentity $identityContainer,
4551
\Magento\Sales\Model\Order\Email\SenderBuilderFactory $senderBuilderFactory,
4652
\Psr\Log\LoggerInterface $logger,
4753
Renderer $addressRenderer,
48-
ManagerInterface $eventManager
54+
ManagerInterface $eventManager,
55+
Emulation $appEmulation = null
4956
) {
5057
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
5158
$this->addressRenderer = $addressRenderer;
5259
$this->eventManager = $eventManager;
60+
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()->get(Emulation::class);
5361
}
5462

5563
/**
@@ -65,6 +73,7 @@ public function send(Invoice $invoice, $notify = true, $comment = '')
6573
$order = $invoice->getOrder();
6674
$this->identityContainer->setStore($order->getStore());
6775

76+
$this->appEmulation->startEnvironmentEmulation($order->getStoreId(), Area::AREA_FRONTEND, true);
6877
$transport = [
6978
'order' => $order,
7079
'invoice' => $invoice,
@@ -79,6 +88,7 @@ public function send(Invoice $invoice, $notify = true, $comment = '')
7988
]
8089
];
8190
$transportObject = new DataObject($transport);
91+
$this->appEmulation->stopEnvironmentEmulation();
8292

8393
/**
8494
* Event argument `transport` is @deprecated. Use `transportObject` instead.

app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceSender.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Sales\Model\Order\Email\Sender;
99

10+
use Magento\Framework\App\Area;
11+
use Magento\Framework\App\ObjectManager;
1012
use Magento\Framework\DataObject;
1113
use Magento\Framework\Event\ManagerInterface;
1214
use Magento\Payment\Helper\Data as PaymentHelper;
@@ -17,6 +19,7 @@
1719
use Magento\Sales\Model\Order\Email\Sender;
1820
use Magento\Sales\Model\Order\Invoice;
1921
use Magento\Sales\Model\ResourceModel\Order\Invoice as InvoiceResource;
22+
use Magento\Store\Model\App\Emulation;
2023

2124
/**
2225
* Sends order invoice email to the customer.
@@ -54,6 +57,11 @@ class InvoiceSender extends Sender
5457
*/
5558
protected $eventManager;
5659

60+
/**
61+
* @var Emulation
62+
*/
63+
private $appEmulation;
64+
5765
/**
5866
* @param Template $templateContainer
5967
* @param InvoiceIdentity $identityContainer
@@ -64,6 +72,9 @@ class InvoiceSender extends Sender
6472
* @param InvoiceResource $invoiceResource
6573
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
6674
* @param ManagerInterface $eventManager
75+
* @param Emulation|null $appEmulation
76+
*
77+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6778
*/
6879
public function __construct(
6980
Template $templateContainer,
@@ -74,14 +85,16 @@ public function __construct(
7485
PaymentHelper $paymentHelper,
7586
InvoiceResource $invoiceResource,
7687
\Magento\Framework\App\Config\ScopeConfigInterface $globalConfig,
77-
ManagerInterface $eventManager
88+
ManagerInterface $eventManager,
89+
Emulation $appEmulation = null
7890
) {
7991
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
8092
$this->paymentHelper = $paymentHelper;
8193
$this->invoiceResource = $invoiceResource;
8294
$this->globalConfig = $globalConfig;
8395
$this->addressRenderer = $addressRenderer;
8496
$this->eventManager = $eventManager;
97+
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()->get(Emulation::class);
8598
}
8699

87100
/**
@@ -112,7 +125,7 @@ public function send(Invoice $invoice, $forceSyncMode = false)
112125
$order->setBaseTaxAmount((float) $invoice->getBaseTaxAmount());
113126
$order->setBaseShippingAmount((float) $invoice->getBaseShippingAmount());
114127
}
115-
128+
$this->appEmulation->startEnvironmentEmulation($order->getStoreId(), Area::AREA_FRONTEND, true);
116129
$transport = [
117130
'order' => $order,
118131
'order_id' => $order->getId(),
@@ -132,6 +145,7 @@ public function send(Invoice $invoice, $forceSyncMode = false)
132145
]
133146
];
134147
$transportObject = new DataObject($transport);
148+
$this->appEmulation->stopEnvironmentEmulation();
135149

136150
/**
137151
* Event argument `transport` is @deprecated. Use `transportObject` instead.

app/code/Magento/Sales/Model/Order/Email/Sender/OrderCommentSender.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
*/
66
namespace Magento\Sales\Model\Order\Email\Sender;
77

8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\ObjectManager;
810
use Magento\Sales\Model\Order;
911
use Magento\Sales\Model\Order\Email\Container\OrderCommentIdentity;
1012
use Magento\Sales\Model\Order\Email\Container\Template;
1113
use Magento\Sales\Model\Order\Email\NotifySender;
1214
use Magento\Sales\Model\Order\Address\Renderer;
1315
use Magento\Framework\Event\ManagerInterface;
1416
use Magento\Framework\DataObject;
17+
use Magento\Store\Model\App\Emulation;
1518

16-
/**
17-
* Class OrderCommentSender
18-
*/
1919
class OrderCommentSender extends NotifySender
2020
{
2121
/**
@@ -30,25 +30,33 @@ class OrderCommentSender extends NotifySender
3030
*/
3131
protected $eventManager;
3232

33+
/**
34+
* @var Emulation
35+
*/
36+
private $appEmulation;
37+
3338
/**
3439
* @param Template $templateContainer
3540
* @param OrderCommentIdentity $identityContainer
3641
* @param Order\Email\SenderBuilderFactory $senderBuilderFactory
3742
* @param \Psr\Log\LoggerInterface $logger
3843
* @param Renderer $addressRenderer
3944
* @param ManagerInterface $eventManager
45+
* @param Emulation|null $appEmulation
4046
*/
4147
public function __construct(
4248
Template $templateContainer,
4349
OrderCommentIdentity $identityContainer,
4450
\Magento\Sales\Model\Order\Email\SenderBuilderFactory $senderBuilderFactory,
4551
\Psr\Log\LoggerInterface $logger,
4652
Renderer $addressRenderer,
47-
ManagerInterface $eventManager
53+
ManagerInterface $eventManager,
54+
Emulation $appEmulation = null
4855
) {
4956
parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
5057
$this->addressRenderer = $addressRenderer;
5158
$this->eventManager = $eventManager;
59+
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()->get(Emulation::class);
5260
}
5361

5462
/**
@@ -63,6 +71,7 @@ public function send(Order $order, $notify = true, $comment = '')
6371
{
6472
$this->identityContainer->setStore($order->getStore());
6573

74+
$this->appEmulation->startEnvironmentEmulation($order->getStoreId(), Area::AREA_FRONTEND, true);
6675
$transport = [
6776
'order' => $order,
6877
'comment' => $comment,
@@ -76,6 +85,7 @@ public function send(Order $order, $notify = true, $comment = '')
7685
]
7786
];
7887
$transportObject = new DataObject($transport);
88+
$this->appEmulation->stopEnvironmentEmulation();
7989

8090
/**
8191
* Event argument `transport` is @deprecated. Use `transportObject` instead.

0 commit comments

Comments
 (0)