From 9009870c7f33dac51b38f6635c50fc93eb194c18 Mon Sep 17 00:00:00 2001 From: vigneshbalasubramani Date: Sun, 2 Feb 2020 11:19:14 +0530 Subject: [PATCH] magento/magento2#14885: Refactoring removed code duplication in EmailSender/ShipmentSender --- .../Controller/Adminhtml/Order/Invoice/Save.php | 14 +++++++------- .../Model/Order/Email/Sender/ShipmentSender.php | 2 ++ app/code/Magento/Sales/etc/di.xml | 2 +- .../Controller/Adminhtml/Order/Shipment/Save.php | 12 ++++++------ .../Magento/Shipping/Model/ShipmentNotifier.php | 8 ++++---- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php index f66ca37a47655..89ca589720bce 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php @@ -12,7 +12,7 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; -use Magento\Sales\Model\Order\Email\Sender\ShipmentSender; +use Magento\Sales\Model\Order\Shipment\Sender\EmailSender; use Magento\Sales\Model\Order\ShipmentFactory; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Service\InvoiceService; @@ -38,9 +38,9 @@ class Save extends \Magento\Backend\App\Action implements HttpPostActionInterfac protected $invoiceSender; /** - * @var ShipmentSender + * @var EmailSender */ - protected $shipmentSender; + protected $emailSender; /** * @var ShipmentFactory @@ -66,7 +66,7 @@ class Save extends \Magento\Backend\App\Action implements HttpPostActionInterfac * @param Action\Context $context * @param Registry $registry * @param InvoiceSender $invoiceSender - * @param ShipmentSender $shipmentSender + * @param EmailSender $emailSender * @param ShipmentFactory $shipmentFactory * @param InvoiceService $invoiceService * @param SalesData $salesData @@ -75,14 +75,14 @@ public function __construct( Action\Context $context, Registry $registry, InvoiceSender $invoiceSender, - ShipmentSender $shipmentSender, + EmailSender $emailSender, ShipmentFactory $shipmentFactory, InvoiceService $invoiceService, SalesData $salesData = null ) { $this->registry = $registry; $this->invoiceSender = $invoiceSender; - $this->shipmentSender = $shipmentSender; + $this->emailSender = $emailSender; $this->shipmentFactory = $shipmentFactory; $this->invoiceService = $invoiceService; parent::__construct($context); @@ -223,7 +223,7 @@ public function execute() if ($shipment) { try { if (!empty($data['send_email']) || $this->salesData->canSendNewShipmentEmail()) { - $this->shipmentSender->send($shipment); + $this->emailSender->send($shipment); } } catch (\Exception $e) { $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php index 4dbc10308f3be..fb5f56f5ebb63 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php @@ -19,6 +19,8 @@ /** * Class ShipmentSender * + * @deprecated + * @see \Magento\Sales\Model\Order\Shipment\Sender\EmailSender * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ShipmentSender extends Sender diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 9f705c1a674c1..3e8b61fe8dcb1 100644 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -338,7 +338,7 @@ - Magento\Sales\Model\Order\Email\Sender\ShipmentSender + Magento\Sales\Model\Order\Shipment\Sender\EmailSender Magento\Sales\Model\ResourceModel\Order\Shipment Magento\Sales\Model\ResourceModel\Order\Shipment\Collection Magento\Sales\Model\Order\Email\Container\ShipmentIdentity diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php index 100ba029beabd..1d54c733e5556 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php @@ -34,9 +34,9 @@ class Save extends \Magento\Backend\App\Action implements HttpPostActionInterfac protected $labelGenerator; /** - * @var \Magento\Sales\Model\Order\Email\Sender\ShipmentSender + * @var \Magento\Sales\Model\Order\Shipment\Sender\EmailSender */ - protected $shipmentSender; + protected $emailSender; /** * @var \Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface @@ -47,21 +47,21 @@ class Save extends \Magento\Backend\App\Action implements HttpPostActionInterfac * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader * @param \Magento\Shipping\Model\Shipping\LabelGenerator $labelGenerator - * @param \Magento\Sales\Model\Order\Email\Sender\ShipmentSender $shipmentSender + * @param \Magento\Sales\Model\Order\Shipment\Sender\EmailSender $emailSender * @param \Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface|null $shipmentValidator */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader, \Magento\Shipping\Model\Shipping\LabelGenerator $labelGenerator, - \Magento\Sales\Model\Order\Email\Sender\ShipmentSender $shipmentSender, + \Magento\Sales\Model\Order\Shipment\Sender\EmailSender $emailSender, \Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface $shipmentValidator = null ) { parent::__construct($context); $this->shipmentLoader = $shipmentLoader; $this->labelGenerator = $labelGenerator; - $this->shipmentSender = $shipmentSender; + $this->emailSender = $emailSender; $this->shipmentValidator = $shipmentValidator ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface::class); } @@ -157,7 +157,7 @@ public function execute() $this->_saveShipment($shipment); if (!empty($data['send_email'])) { - $this->shipmentSender->send($shipment); + $this->emailSender->send($shipment); } $shipmentCreatedMessage = __('The shipment has been created.'); diff --git a/app/code/Magento/Shipping/Model/ShipmentNotifier.php b/app/code/Magento/Shipping/Model/ShipmentNotifier.php index 6a317c068bbc4..ae766f4f09739 100644 --- a/app/code/Magento/Shipping/Model/ShipmentNotifier.php +++ b/app/code/Magento/Shipping/Model/ShipmentNotifier.php @@ -7,7 +7,7 @@ namespace Magento\Shipping\Model; use Psr\Log\LoggerInterface as Logger; -use Magento\Sales\Model\Order\Email\Sender\ShipmentSender; +use Magento\Sales\Model\Order\Shipment\Sender\EmailSender; use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory; /** @@ -27,19 +27,19 @@ class ShipmentNotifier extends \Magento\Sales\Model\AbstractNotifier protected $logger; /** - * @var ShipmentSender + * @var EmailSender */ protected $sender; /** * @param CollectionFactory $historyCollectionFactory * @param Logger $logger - * @param ShipmentSender $sender + * @param EmailSender $sender */ public function __construct( CollectionFactory $historyCollectionFactory, Logger $logger, - ShipmentSender $sender + EmailSender $sender ) { $this->historyCollectionFactory = $historyCollectionFactory; $this->logger = $logger;