-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
34e362e
commit 9598d2d
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
namespace Mondu\Mondu\Plugin; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Mondu\Mondu\Helpers\InvoiceOrderHelper; | ||
use Mondu\Mondu\Helpers\Log; | ||
use Mondu\Mondu\Helpers\Logger\Logger as MonduFileLogger; | ||
|
||
class ProcessShipmentSave | ||
{ | ||
/** | ||
* @var MonduFileLogger | ||
*/ | ||
private $monduFileLogger; | ||
|
||
/** | ||
* @var Log | ||
*/ | ||
protected $monduLogger; | ||
|
||
/** | ||
* @var InvoiceOrderHelper | ||
*/ | ||
private $invoiceOrderHelper; | ||
|
||
/** | ||
* @param MonduFileLogger $monduFileLogger | ||
* @param Log $logger | ||
* @param InvoiceOrderHelper $invoiceOrderHelper | ||
*/ | ||
public function __construct( | ||
MonduFileLogger $monduFileLogger, | ||
Log $logger, | ||
InvoiceOrderHelper $invoiceOrderHelper | ||
) { | ||
$this->monduFileLogger = $monduFileLogger; | ||
$this->monduLogger = $logger; | ||
$this->invoiceOrderHelper = $invoiceOrderHelper; | ||
} | ||
|
||
/** | ||
* After Save Processing | ||
* | ||
* @param \Magento\Sales\Model\Order\ShipmentRepository\Interceptor $subject | ||
* @param $shipment | ||
* | ||
* @return mixed | ||
* @throws LocalizedException | ||
*/ | ||
public function afterSave( | ||
\Magento\Sales\Model\Order\ShipmentRepository\Interceptor $subject, | ||
$shipment | ||
) { | ||
$order = $shipment->getOrder(); | ||
$monduLog = $this->monduLogger->getLogCollection($order->getData('mondu_reference_id')); | ||
|
||
if ($monduLog->getSkipShipObserver()) { | ||
$this->monduFileLogger | ||
->info( | ||
'Already invoiced using invoice orders action, skipping', | ||
['orderNumber' => $order->getIncrementId()] | ||
); | ||
|
||
return $shipment; | ||
} | ||
|
||
$monduId = $order->getData('mondu_reference_id'); | ||
$this->monduLogger->syncOrder($monduId); | ||
|
||
if (!$this->monduLogger->canShipOrder($monduId)) { | ||
throw new LocalizedException( | ||
__('Can\'t ship order: Mondu order state must be confirmed or partially_shipped') | ||
); | ||
} | ||
|
||
$this->invoiceOrderHelper->handleInvoiceOrder($order, $shipment, $monduLog); | ||
|
||
return $shipment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters