Skip to content

Commit

Permalink
Combined 5.0.2 fixes (offline refund, Klarna workflow and selected is…
Browse files Browse the repository at this point in the history
…suer)
  • Loading branch information
Marvin-Magmodules committed Dec 20, 2018
1 parent 126822d commit 0cf3a43
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 32 deletions.
48 changes: 29 additions & 19 deletions app/code/community/Mollie/Mpm/Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,6 @@ public function processTransaction(Mage_Sales_Model_Order $order, $type = 'webho
->addObject($invoice)
->addObject($invoice->getOrder())
->save();


/**
* $transaction = Mage::getModel('core/resource_transaction')
* ->addObject($invoice)
* ->addObject($invoice->getOrder());
*
* $transaction->save();
* **/
}

$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING)->save();
Expand Down Expand Up @@ -309,9 +300,12 @@ public function processTransaction(Mage_Sales_Model_Order $order, $type = 'webho
if ($mollieOrder->method == 'banktransfer' && !$order->getEmailSent()) {
$order->sendNewOrderEmail()->setEmailSent(true)->save();
$message = $this->mollieHelper->__('New order email sent');
$defaultStatusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId);
if (!$statusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId)) {
$statusPending = $order->getStatus();
}

$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
$order->addStatusToHistory($defaultStatusPending, $message, true);
$order->addStatusToHistory($statusPending, $message, true);
$order->save();
}

Expand Down Expand Up @@ -472,12 +466,11 @@ public function createShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_S
* Check if Transactions needs to be captures (eg. Klarna methods)
*/
$payment = $order->getPayment();
if (!$payment->getIsTransactionClosed()) {
/** @var Mage_Sales_Model_Order_Invoice $invoice */
$invoice = $order->getInvoiceCollection()->getLastItem();
if ($invoice && $invoice->getState() == 1) {
$payment->registerCaptureNotification($order->getBaseGrandTotal(), true);
$order->save();

/** @var Mage_Sales_Model_Order_Invoice $invoice */
$invoice = $payment->getCreatedInvoice();
$sendInvoice = $this->mollieHelper->sendInvoice($order->getStoreId());
if ($invoice && !$invoice->getEmailSent() && $sendInvoice) {
$invoice->setEmailSent(true)->sendEmail()->save();
Expand All @@ -497,7 +490,6 @@ public function createShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_S
* @param Mage_Sales_Model_Order $order
*
* @return $this
* @throws Mage_Core_Exception
*/
public function updateShipmentTrack(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order_Shipment_Track $track, Mage_Sales_Model_Order $order)
{
Expand Down Expand Up @@ -538,7 +530,6 @@ public function updateShipmentTrack(Mage_Sales_Model_Order_Shipment $shipment, M
}
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
Mage::throwException($this->mollieHelper->__('Mollie API: %s', $e->getMessage()));
}

return $this;
Expand All @@ -557,9 +548,26 @@ public function createOrderRefund(Mage_Sales_Model_Order_Creditmemo $creditmemo,
$storeId = $order->getStoreId();
$orderId = $order->getId();

/**
* Skip the creation of an online refund if an offline refund is used
* and add a message to the core/sessions about this workflow.
* Registry set at the Mollie_Mpm_Model_Mollie::refund and is set once an online refund is used.
*/
if (!Mage::registry('online_refund')) {
Mage::getSingleton('core/session')->addNotice(
$this->mollieHelper->__(
'An offline refund has been created, please make sure to also create this
refund on mollie.com/dashboard or use the online refund option.'
)
);
return $this;
}

$methodCode = $this->mollieHelper->getMethodCode($order);
if (!$order->hasShipments() && ($methodCode == 'klarnapaylater' || $methodCode == 'klarnasliceit')) {
$msg = $this->mollieHelper->__('Order can only be refunded after Klara has been captured (after shipment)');
$msg = $this->mollieHelper->__(
'Order can only be refunded after Klara has been captured (after shipment)'
);
Mage::throwException($msg);
}

Expand All @@ -582,7 +590,9 @@ public function createOrderRefund(Mage_Sales_Model_Order_Creditmemo $creditmemo,
* Throw exception if these are set, as this is not supportef by the orders api.
*/
if ($creditmemo->getAdjustmentPositive() > 0 || $creditmemo->getAdjustmentNegative() > 0) {
$msg = $this->mollieHelper->__('Creating an online refund with adjustment fee\'s is not supported by Mollie');
$msg = $this->mollieHelper->__(
'Creating an online refund with adjustment fee\'s is not supported by Mollie'
);
$this->mollieHelper->addTolog('error', $msg);
Mage::throwException($msg);
}
Expand Down
10 changes: 7 additions & 3 deletions app/code/community/Mollie/Mpm/Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,14 @@ public function processTransaction(Mage_Sales_Model_Order $order, $type = 'webho
if ($status == 'open') {
if ($paymentData->method == 'banktransfer' && !$order->getEmailSent()) {
$order->sendNewOrderEmail()->setEmailSent(true)->save();
$defaultStatusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId);
$state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
$message = $this->mollieHelper->__('New order email sent');
$order->setState($defaultStatusPending, $status, $message, false)->save();
if (!$statusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId)) {
$statusPending = $order->getStatus();
}

$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
$order->addStatusToHistory($statusPending, $message, true);
$order->save();
}

$msg = array('success' => true, 'status' => 'open', 'order_id' => $orderId, 'type' => $type);
Expand Down
12 changes: 12 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ class Mollie_Mpm_Model_Method_Abstract extends Mollie_Mpm_Model_Mollie
protected $_canRefundInvoicePartial = true;
protected $_canCapture = true;

/**
* @param mixed $data
*
* @return $this|Mage_Payment_Model_Info
* @throws Mage_Core_Exception
*/
public function assignData($data)
{
parent::assignData($data);
$this->getInfoInstance()->setAdditionalInformation('selected_issuer', null);
return $this;
}
}
15 changes: 15 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Kbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ class Mollie_Mpm_Model_Method_Kbc extends Mollie_Mpm_Model_Method_Abstract
*/
protected $_paymentMethod = self::PAYMENT_METHOD;

/**
* @param mixed $data
*
* @return $this|Mage_Payment_Model_Info
* @throws Mage_Core_Exception
*/
public function assignData($data)
{
parent::assignData($data);

$selectedIssuer = Mage::app()->getRequest()->getParam('mollie_kbc_issuer');
$this->getInfoInstance()->setAdditionalInformation('selected_issuer', $selectedIssuer);

return $this;
}
}
15 changes: 15 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Paymentlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ public function initialize($paymentAction, $stateObject)
$this->startTransaction($order);
}

/**
* @param mixed $data
*
* @return $this|Mage_Payment_Model_Info
* @throws Mage_Core_Exception
*/
public function assignData($data)
{
parent::assignData($data);

$limitedMethods = Mage::app()->getRequest()->getParam('limited_methods', null);
$this->getInfoInstance()->setAdditionalInformation('limited_methods', $limitedMethods);
return $this;
}

}
1 change: 1 addition & 0 deletions app/code/community/Mollie/Mpm/Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public function refund(Varien_Object $payment, $amount)
*/
$checkoutType = $this->mollieHelper->getCheckoutType($order);
if ($checkoutType == 'order') {
Mage::register('online_refund', true);
return $this;
}

Expand Down
20 changes: 12 additions & 8 deletions app/code/community/Mollie/Mpm/Model/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,18 @@ public function getShipmentOrderLines(Mage_Sales_Model_Order_Shipment $shipment)
}

/**
* @param $lineId
* @param $itemId
*
* @return Mollie_Mpm_Model_Resource_OrderLines
*/
public function getOrderLineByItemId($itemId)
{
return $this->load($itemId, 'item_id');
$orderLine = $this->getCollection()
->addFieldToFilter('item_id', array('eq' => $itemId))
->addFieldToFilter('line_id', array('notnull' => true))
->getLastItem();

return $orderLine;
}

/**
Expand Down Expand Up @@ -353,8 +358,8 @@ public function getOpenForShipmentQty($orderId)
->addFieldToFilter('type', array('eq' => 'physical'))
->addExpressionFieldToSelect(
'open',
'SUM(qty_paid - qty_shipped - qty_refunded)',
array('qty_paid', 'qty_shipped', 'qty_refunded')
'SUM(qty_ordered - qty_shipped - qty_refunded)',
array('qty_ordered', 'qty_shipped', 'qty_refunded')
);
$orderLinesCollection->getSelect()->group('order_id');

Expand All @@ -380,8 +385,8 @@ public function getOpenForRefundQty($orderId)
->addFieldToFilter('type', array('in' => array('physical', 'digital')))
->addExpressionFieldToSelect(
'open',
'SUM(qty_paid - qty_refunded)',
array('qty_paid', 'qty_refunded')
'SUM(qty_ordered - qty_refunded)',
array('qty_ordered', 'qty_refunded')
);
$orderLinesCollection->getSelect()->group('order_id');

Expand All @@ -393,5 +398,4 @@ public function getOpenForRefundQty($orderId)

return $qty;
}
}

}
6 changes: 6 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Resource/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object)
$object->setData('vat_amount', $vatAmountValue);
}

$gmtDate = Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s');
$object->setData('updated_at', $gmtDate);
if (!$object->getId()) {
$object->setData('created_at', $gmtDate);
}

return parent::_beforeSave($object);
}

Expand Down
4 changes: 2 additions & 2 deletions app/code/community/Mollie/Mpm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@
</mollie_sales_order_creditmemo_save_after>
</observers>
</sales_order_creditmemo_save_after>
<sales_order_shipment_save_after>
<sales_order_shipment_save_before>
<observers>
<mollie_sales_order_shipment_save_after>
<type>singleton</type>
<class>Mollie_Mpm_Model_Observer</class>
<method>salesOrderShipmentSaveBefore</method>
</mollie_sales_order_shipment_save_after>
</observers>
</sales_order_shipment_save_after>
</sales_order_shipment_save_before>
<sales_order_shipment_track_save_after>
<observers>
<mollie_sales_order_shipment_track_save_after>
Expand Down

0 comments on commit 0cf3a43

Please sign in to comment.