Skip to content

Commit

Permalink
magento#14885: Refactoring removed code duplication in EmailSender/Sh…
Browse files Browse the repository at this point in the history
…ipmentSender
  • Loading branch information
vigneshbalasubramani committed Feb 2, 2020
1 parent 90a479f commit 9009870
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
/**
* Class ShipmentSender
*
* @deprecated
* @see \Magento\Sales\Model\Order\Shipment\Sender\EmailSender
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ShipmentSender extends Sender
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
</virtualType>
<virtualType name="SalesOrderShipmentSendEmails" type="Magento\Sales\Model\EmailSenderHandler">
<arguments>
<argument name="emailSender" xsi:type="object">Magento\Sales\Model\Order\Email\Sender\ShipmentSender</argument>
<argument name="emailSender" xsi:type="object">Magento\Sales\Model\Order\Shipment\Sender\EmailSender</argument>
<argument name="entityResource" xsi:type="object">Magento\Sales\Model\ResourceModel\Order\Shipment</argument>
<argument name="entityCollection" xsi:type="object" shared="false">Magento\Sales\Model\ResourceModel\Order\Shipment\Collection</argument>
<argument name="identityContainer" xsi:type="object" shared="false">Magento\Sales\Model\Order\Email\Container\ShipmentIdentity</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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.');
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Shipping/Model/ShipmentNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down

0 comments on commit 9009870

Please sign in to comment.