Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
(MAGE2-316)[refactor]
Browse files Browse the repository at this point in the history
- Use trait for state handling of shipments.
- update changelog.
  • Loading branch information
Ryouzanpaku committed May 7, 2020
1 parent 889e448 commit 578479e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ This project does not follow a versioning standard. Versions are crafted after t
### Fixed
- An issue during checkout if phone number is optional and not set by customer. That leads to a failing address comparison
for secured payment methods and PayPal.

- An issue creating orders from Reservations.
- Invoice Payment methods : An issue not always setting the expected state after shipment.

## 20.2.24
### Added
Expand Down
4 changes: 3 additions & 1 deletion Controller/Adminhtml/Order/Shipment/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ public function beforeExecute()
);

$this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]);
} else {
$order->addStatusHistoryComment('heidelpay - Finalizing Order');
$this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.'));
}

$this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.'));
}
$method->setShippedOrderState($order);
$this->orderResository->save($order);
Expand Down
14 changes: 3 additions & 11 deletions PaymentMethods/HeidelpayInvoicePaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Exception;
use Heidelpay\Gateway\Block\Info\Invoice as InvoiceBlock;
use Heidelpay\Gateway\Traits\CanShipBeforePayment;
use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException;
use Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod;
use Magento\Sales\Model\Order;
Expand All @@ -27,6 +28,8 @@
*/
class HeidelpayInvoicePaymentMethod extends HeidelpayAbstractPaymentMethod
{
use CanShipBeforePayment;

/** @var string Payment Code */
const CODE = 'hgwiv';

Expand Down Expand Up @@ -108,15 +111,4 @@ public function pendingTransactionProcessing($data, &$order, $message = null)
$this->_paymentHelper->saveTransaction($invoice);
}
}

/**
* @param Order $order
*/
public function setShippedOrderState(&$order)
{
if ($order->getTotalPaid() < $order->getGrandTotal()) {
$state = Order::STATE_PENDING_PAYMENT;
$order->setState($state)->addStatusHistoryComment('heidelpay - Order shipped, awaiting payment', true);
}
}
}
13 changes: 2 additions & 11 deletions PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Heidelpay\Gateway\Block\Info\InvoiceSecured as InvoiceSecuredBlock;
use Heidelpay\Gateway\Model\PaymentInformation;
use Heidelpay\Gateway\Traits\CanShipBeforePayment;
use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException;
use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod;
use Magento\Quote\Api\Data\CartInterface;
Expand All @@ -28,6 +29,7 @@
*/
class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMethod
{
use CanShipBeforePayment;
/** @var string Payment Code */
const CODE = 'hgwivs';

Expand Down Expand Up @@ -143,15 +145,4 @@ public function pendingTransactionProcessing($data, &$order, $message = null)
$this->_paymentHelper->saveTransaction($invoice);
}
}

/**
* @param Order $order
*/
public function setShippedOrderState(&$order)
{
if ($order->getTotalPaid() < $order->getGrandTotal()) {
$state = Order::STATE_PENDING_PAYMENT;
$order->setState($state)->addStatusHistoryComment('heidelpay - Finalizing Order', true);
}
}
}
22 changes: 22 additions & 0 deletions PaymentMethods/Traits/CanShipBeforePayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Heidelpay\Gateway\Traits;


use Magento\Sales\Model\Order;

trait CanShipBeforePayment
{
/**
* @param Order $order
*/
public function setShippedOrderState(&$order)
{
if ($order->getTotalPaid() < $order->getGrandTotal()) {
$state = Order::STATE_PENDING_PAYMENT;
$status = $order->getConfig()->getStateDefaultStatus($state);
$order->setState($state)->setStatus($status);
}
}
}

0 comments on commit 578479e

Please sign in to comment.