Skip to content

Commit 9c0da70

Browse files
committed
Merge remote-tracking branch 'origin/MC-31544' into 2.4-develop-pr21
2 parents b891e81 + 1f4166b commit 9c0da70

32 files changed

+496
-67
lines changed

app/code/Magento/Sales/Block/Order/Email/Creditmemo/Items.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*/
66
namespace Magento\Sales\Block\Order\Email\Creditmemo;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Sales\Api\CreditmemoRepositoryInterface;
11+
use Magento\Sales\Api\Data\OrderInterface;
12+
use Magento\Sales\Api\Data\CreditmemoInterface;
13+
use Magento\Sales\Api\OrderRepositoryInterface;
14+
815
/**
916
* Sales Order Email creditmemo items
1017
*
@@ -14,6 +21,36 @@
1421
*/
1522
class Items extends \Magento\Sales\Block\Items\AbstractItems
1623
{
24+
/**
25+
* @var OrderRepositoryInterface
26+
*/
27+
private $orderRepository;
28+
29+
/**
30+
* @var CreditmemoRepositoryInterface
31+
*/
32+
private $creditmemoRepository;
33+
34+
/**
35+
* @param Context $context
36+
* @param array $data
37+
* @param OrderRepositoryInterface|null $orderRepository
38+
* @param CreditmemoRepositoryInterface|null $creditmemoRepository
39+
*/
40+
public function __construct(
41+
Context $context,
42+
array $data = [],
43+
?OrderRepositoryInterface $orderRepository = null,
44+
?CreditmemoRepositoryInterface $creditmemoRepository = null
45+
) {
46+
$this->orderRepository =
47+
$orderRepository ?: ObjectManager::getInstance()->get(OrderRepositoryInterface::class);
48+
$this->creditmemoRepository =
49+
$creditmemoRepository ?: ObjectManager::getInstance()->get(CreditmemoRepositoryInterface::class);
50+
51+
parent::__construct($context, $data);
52+
}
53+
1754
/**
1855
* Prepare item before output
1956
*
@@ -25,4 +62,54 @@ protected function _prepareItem(\Magento\Framework\View\Element\AbstractBlock $r
2562
$renderer->getItem()->setOrder($this->getOrder());
2663
$renderer->getItem()->setSource($this->getCreditmemo());
2764
}
65+
66+
/**
67+
* Returns order.
68+
*
69+
* Custom email templates are only allowed to use scalar values for variable data.
70+
* So order is loaded by order_id, that is passed to block from email template.
71+
* For legacy custom email templates it can pass as an object.
72+
*
73+
* @return OrderInterface|null
74+
*/
75+
public function getOrder()
76+
{
77+
$order = $this->getData('order');
78+
if ($order !== null) {
79+
return $order;
80+
}
81+
82+
$orderId = (int)$this->getData('order_id');
83+
if ($orderId) {
84+
$order = $this->orderRepository->get($orderId);
85+
$this->setData('order', $order);
86+
}
87+
88+
return $this->getData('order');
89+
}
90+
91+
/**
92+
* Returns creditmemo.
93+
*
94+
* Custom email templates are only allowed to use scalar values for variable data.
95+
* So creditmemo is loaded by creditmemo_id, that is passed to block from email template.
96+
* For legacy custom email templates it can pass as an object.
97+
*
98+
* @return CreditmemoInterface|null
99+
*/
100+
public function getCreditmemo()
101+
{
102+
$creditmemo = $this->getData('creditmemo');
103+
if ($creditmemo !== null) {
104+
return $creditmemo;
105+
}
106+
107+
$creditmemoId = (int)$this->getData('creditmemo_id');
108+
if ($creditmemoId) {
109+
$creditmemo = $this->creditmemoRepository->get($creditmemoId);
110+
$this->setData('creditmemo', $creditmemo);
111+
}
112+
113+
return $this->getData('creditmemo');
114+
}
28115
}

app/code/Magento/Sales/Block/Order/Email/Invoice/Items.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
namespace Magento\Sales\Block\Order\Email\Invoice;
88

9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\View\Element\Template\Context;
11+
use Magento\Sales\Api\Data\InvoiceInterface;
12+
use Magento\Sales\Api\Data\OrderInterface;
13+
use Magento\Sales\Api\InvoiceRepositoryInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
916
/**
1017
* Sales Order Email Invoice items
1118
*
@@ -14,6 +21,36 @@
1421
*/
1522
class Items extends \Magento\Sales\Block\Items\AbstractItems
1623
{
24+
/**
25+
* @var OrderRepositoryInterface
26+
*/
27+
private $orderRepository;
28+
29+
/**
30+
* @var InvoiceRepositoryInterface
31+
*/
32+
private $invoiceRepository;
33+
34+
/**
35+
* @param Context $context
36+
* @param array $data
37+
* @param OrderRepositoryInterface|null $orderRepository
38+
* @param InvoiceRepositoryInterface|null $invoiceRepository
39+
*/
40+
public function __construct(
41+
Context $context,
42+
array $data = [],
43+
?OrderRepositoryInterface $orderRepository = null,
44+
?InvoiceRepositoryInterface $invoiceRepository = null
45+
) {
46+
$this->orderRepository =
47+
$orderRepository ?: ObjectManager::getInstance()->get(OrderRepositoryInterface::class);
48+
$this->invoiceRepository =
49+
$invoiceRepository ?: ObjectManager::getInstance()->get(InvoiceRepositoryInterface::class);
50+
51+
parent::__construct($context, $data);
52+
}
53+
1754
/**
1855
* Prepare item before output
1956
*
@@ -25,4 +62,54 @@ protected function _prepareItem(\Magento\Framework\View\Element\AbstractBlock $r
2562
$renderer->getItem()->setOrder($this->getOrder());
2663
$renderer->getItem()->setSource($this->getInvoice());
2764
}
65+
66+
/**
67+
* Returns order.
68+
*
69+
* Custom email templates are only allowed to use scalar values for variable data.
70+
* So order is loaded by order_id, that is passed to block from email template.
71+
* For legacy custom email templates it can pass as an object.
72+
*
73+
* @return OrderInterface|null
74+
*/
75+
public function getOrder()
76+
{
77+
$order = $this->getData('order');
78+
if ($order !== null) {
79+
return $order;
80+
}
81+
82+
$orderId = (int)$this->getData('order_id');
83+
if ($orderId) {
84+
$order = $this->orderRepository->get($orderId);
85+
$this->setData('order', $order);
86+
}
87+
88+
return $this->getData('order');
89+
}
90+
91+
/**
92+
* Returns invoice.
93+
*
94+
* Custom email templates are only allowed to use scalar values for variable data.
95+
* So invoice is loaded by invoice_id, that is passed to block from email template.
96+
* For legacy custom email templates it can pass as an object.
97+
*
98+
* @return InvoiceInterface|null
99+
*/
100+
public function getInvoice()
101+
{
102+
$invoice = $this->getData('invoice');
103+
if ($invoice !== null) {
104+
return $invoice;
105+
}
106+
107+
$invoiceId = (int)$this->getData('invoice_id');
108+
if ($invoiceId) {
109+
$invoice = $this->invoiceRepository->get($invoiceId);
110+
$this->setData('invoice', $invoice);
111+
}
112+
113+
return $this->getData('invoice');
114+
}
28115
}

app/code/Magento/Sales/Block/Order/Email/Items.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,61 @@
1111
*/
1212
namespace Magento\Sales\Block\Order\Email;
1313

14+
use Magento\Framework\App\ObjectManager;
15+
use Magento\Framework\View\Element\Template\Context;
16+
use Magento\Sales\Api\Data\OrderInterface;
17+
use Magento\Sales\Api\OrderRepositoryInterface;
18+
1419
/**
20+
* Sales Order Email items.
21+
*
1522
* @api
1623
* @since 100.0.2
1724
*/
1825
class Items extends \Magento\Sales\Block\Items\AbstractItems
1926
{
27+
/**
28+
* @var OrderRepositoryInterface
29+
*/
30+
private $orderRepository;
31+
32+
/**
33+
* @param Context $context
34+
* @param array $data
35+
* @param OrderRepositoryInterface|null $orderRepository
36+
*/
37+
public function __construct(
38+
Context $context,
39+
array $data = [],
40+
?OrderRepositoryInterface $orderRepository = null
41+
) {
42+
$this->orderRepository = $orderRepository ?: ObjectManager::getInstance()->get(OrderRepositoryInterface::class);
43+
44+
parent::__construct($context, $data);
45+
}
46+
47+
/**
48+
* Returns order.
49+
*
50+
* Custom email templates are only allowed to use scalar values for variable data.
51+
* So order is loaded by order_id, that is passed to block from email template.
52+
* For legacy custom email templates it can pass as an object.
53+
*
54+
* @return OrderInterface|null
55+
*/
56+
public function getOrder()
57+
{
58+
$order = $this->getData('order');
59+
60+
if ($order !== null) {
61+
return $order;
62+
}
63+
$orderId = (int)$this->getData('order_id');
64+
if ($orderId) {
65+
$order = $this->orderRepository->get($orderId);
66+
$this->setData('order', $order);
67+
}
68+
69+
return $this->getData('order');
70+
}
2071
}

app/code/Magento/Sales/Block/Order/Email/Shipment/Items.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
namespace Magento\Sales\Block\Order\Email\Shipment;
88

9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\View\Element\Template\Context;
11+
use Magento\Sales\Api\Data\ShipmentInterface;
12+
use Magento\Sales\Api\Data\OrderInterface;
13+
use Magento\Sales\Api\OrderRepositoryInterface;
14+
use Magento\Sales\Api\ShipmentRepositoryInterface;
15+
916
/**
1017
* Sales Order Email Shipment items
1118
*
@@ -14,6 +21,36 @@
1421
*/
1522
class Items extends \Magento\Sales\Block\Items\AbstractItems
1623
{
24+
/**
25+
* @var OrderRepositoryInterface
26+
*/
27+
private $orderRepository;
28+
29+
/**
30+
* @var ShipmentRepositoryInterface
31+
*/
32+
private $shipmentRepository;
33+
34+
/**
35+
* @param Context $context
36+
* @param array $data
37+
* @param OrderRepositoryInterface|null $orderRepository
38+
* @param ShipmentRepositoryInterface|null $creditmemoRepository
39+
*/
40+
public function __construct(
41+
Context $context,
42+
array $data = [],
43+
?OrderRepositoryInterface $orderRepository = null,
44+
?ShipmentRepositoryInterface $creditmemoRepository = null
45+
) {
46+
$this->orderRepository =
47+
$orderRepository ?: ObjectManager::getInstance()->get(OrderRepositoryInterface::class);
48+
$this->shipmentRepository =
49+
$creditmemoRepository ?: ObjectManager::getInstance()->get(ShipmentRepositoryInterface::class);
50+
51+
parent::__construct($context, $data);
52+
}
53+
1754
/**
1855
* Prepare item before output
1956
*
@@ -25,4 +62,54 @@ protected function _prepareItem(\Magento\Framework\View\Element\AbstractBlock $r
2562
$renderer->getItem()->setOrder($this->getOrder());
2663
$renderer->getItem()->setSource($this->getShipment());
2764
}
65+
66+
/**
67+
* Returns order.
68+
*
69+
* Custom email templates are only allowed to use scalar values for variable data.
70+
* So order is loaded by order_id, that is passed to block from email template.
71+
* For legacy custom email templates it can pass as an object.
72+
*
73+
* @return OrderInterface|null
74+
*/
75+
public function getOrder()
76+
{
77+
$order = $this->getData('order');
78+
if ($order !== null) {
79+
return $order;
80+
}
81+
82+
$orderId = (int)$this->getData('order_id');
83+
if ($orderId) {
84+
$order = $this->orderRepository->get($orderId);
85+
$this->setData('order', $order);
86+
}
87+
88+
return $this->getData('order');
89+
}
90+
91+
/**
92+
* Returns shipment.
93+
*
94+
* Custom email templates are only allowed to use scalar values for variable data.
95+
* So shipment is loaded by shipment_id, that is passed to block from email template.
96+
* For legacy custom email templates it can pass as an object.
97+
*
98+
* @return ShipmentInterface|null
99+
*/
100+
public function getShipment()
101+
{
102+
$shipment = $this->getData('shipment');
103+
if ($shipment !== null) {
104+
return $shipment;
105+
}
106+
107+
$shipmentId = (int)$this->getData('shipment_id');
108+
if ($shipmentId) {
109+
$shipment = $this->shipmentRepository->get($shipmentId);
110+
$this->setData('shipment', $shipment);
111+
}
112+
113+
return $this->getData('shipment');
114+
}
28115
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\DataObject;
1818

1919
/**
20-
* Class CreditmemoSender
20+
* Sends order creditmemo email to the customer.
2121
*
2222
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2323
*/
@@ -108,7 +108,9 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
108108

109109
$transport = [
110110
'order' => $order,
111+
'order_id' => $order->getId(),
111112
'creditmemo' => $creditmemo,
113+
'creditmemo_id' => $creditmemo->getId(),
112114
'comment' => $creditmemo->getCustomerNoteNotify() ? $creditmemo->getCustomerNote() : '',
113115
'billing' => $order->getBillingAddress(),
114116
'payment_html' => $this->getPaymentHtml($order),

0 commit comments

Comments
 (0)