Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-1020 #99

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Plugin/ProcessShipmentSave.php
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;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mondu_gmbh/magento2-payment",
"description": "Mondu payment method for magento 2",
"type": "magento2-module",
"version": "2.3.2",
"version": "2.3.3",
"license": [
"MIT"
],
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
<type name="Magento\Payment\Helper\Data">
<plugin sortOrder="10" name="monduPaymentData" type="Mondu\Mondu\Helpers\DataPlugin"/>
</type>
<type name="Magento\Sales\Model\Order\ShipmentRepository">
<plugin sortOrder="10" name="processShipmentSave" type="Mondu\Mondu\Plugin\ProcessShipmentSave" />
</type>
</config>
Loading