Skip to content

Commit

Permalink
Merge pull request #150 from mollie/5.5.2
Browse files Browse the repository at this point in the history
5.5.2
  • Loading branch information
Marvin-Magmodules authored Oct 11, 2019
2 parents 289859d + bc41c20 commit eb3a9f4
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function initTotals()
}

$total = new Varien_Object();
$total->setLabel(__('Mollie Payment Fee'))
$total->setLabel(__('Payment Fee'))
->setValue($fee + $tax)
->setBaseValue($baseFee + $baseTax)
->setCode('mollie_mpm_payment_fee');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function initTotals()
}

$total = new Varien_Object();
$total->setLabel(__('Mollie Payment Fee'));
$total->setLabel(__('Payment Fee'));
$total->setValue($fee + $tax);
$total->setBaseValue($baseFee + $baseTax);
$total->setCode('mollie_mpm_payment_fee');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function initTotals()
}

$total = new Varien_Object();
$total->setLabel(__('Mollie Payment Fee'))
$total->setLabel(__('Payment Fee'))
->setValue($fee + $tax)
->setBaseValue($baseFee + $baseTax)
->setCode('mollie_mpm_payment_fee');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getOrderLine(Mage_Sales_Model_Order $order)

return [
'type' => 'surcharge',
'name' => Mage::helper('mpm')->__('Mollie Payment Fee'),
'name' => Mage::helper('mpm')->__('Payment Fee'),
'quantity' => 1,
'unitPrice' => $mollieHelper->getAmountArray($order->getOrderCurrencyCode(), $totalPaymentFee),
'totalAmount' => $mollieHelper->getAmountArray($order->getOrderCurrencyCode(), $totalPaymentFee),
Expand Down
29 changes: 29 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public function processTransaction($orderId, $type = 'webhook', $paymentToken =
$connection->rollback();
throw $exception;
} finally {
$this->commitOrder($order);
$connection->commit();
}
}
Expand Down Expand Up @@ -324,4 +325,32 @@ public function getOrderIdByTransactionId($transactionId)
return false;
}

/**
* When wrapping a $order->save() in a transaction, the update of the grid is postponed to a later action.
* This function fixes 2 edge cases which prevents that the order grid is updated. Both are caused due to the fact
* that we update the order in a transaction.
*
* 1. Sometimes people disable the `controller_action_postdispatch` log observer, which calls all
* afterCommitCallback methods outside of the transaction.
*
* 2. When disabling logging in the backend, these afterCommitCallback methods are also not called. This is due to
* the fact that the code for triggering these goes trough the log module.
*
* In both cases we call the `commit()` method of the order ourselves, so the afterCommitCallbacks are still called.
*
* @param Mage_Sales_Model_Order $order
*/
private function commitOrder(Mage_Sales_Model_Order $order)
{
$logObserver = Mage::getConfig()->getNode('frontend/events/controller_action_postdispatch/observers/log');
$logObserverIsDisabled = $logObserver && $logObserver->type == 'disabled';
$systemLogIsDisabled = $this->mollieHelper->getStoreConfig(Mage_Log_Helper_Data::XML_PATH_LOG_ENABLED) == '0';

if (!$logObserverIsDisabled && !$systemLogIsDisabled) {
return;
}

$order->getResource()->commit();
}

}
21 changes: 20 additions & 1 deletion app/code/community/Mollie/Mpm/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,23 @@ public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer
$mollieModel->updateShipmentTrack($shipment, $track, $order);
}
}
}

public function restoreQuoteWhenReturningFromMollie(Varien_Event_Observer $observer)
{
$quoteId = Mage::getSingleton('checkout/session')->getLastQuoteId();

if (!$quoteId) {
return;
}

try {
$quote = Mage::getModel('sales/quote')->load($quoteId);

if (!$quote->getIsActive()) {
$quote->setIsActive(true)->save();
}
} catch (Exception $e) {
Mage::logException($e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function fetch(Mage_Sales_Model_Quote_Address $address)
$address->addTotal(
array(
'code' => $this->getCode(),
'title' => Mage::helper('mpm')->__('Mollie Payment Fee'),
'title' => Mage::helper('mpm')->__('Payment Fee'),
'value' => $amount + $tax,
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function fetch(Mage_Sales_Model_Quote_Address $address)
$address->addTotal(
array(
'code' => $this->getCode(),
'title' => Mage::helper('mpm')->__('Mollie Payment Fee'),
'title' => Mage::helper('mpm')->__('Payment Fee'),
'value' => $amount
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function collect(Mage_Sales_Model_Quote_Address $address)

$address->setMollieMpmPaymentFeeTax($quote->getStore()->convertPrice($paymentFeeTax));
$address->setBaseMollieMpmPaymentFeeTax($paymentFeeTax);
$address->setTaxAmount($address->getTaxAmount() + + $address->getMollieMpmPaymentFeeTax());
$address->setTaxAmount($address->getTaxAmount() + $address->getMollieMpmPaymentFeeTax());
$address->setBaseTaxAmount($address->getBaseTaxAmount() + $address->getBaseMollieMpmPaymentFeeTax());
$address->setGrandTotal($address->getGrandTotal() + $address->getMollieMpmPaymentFeeTax());
$address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseMollieMpmPaymentFeeTax());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testGetOrderLine()
$result = $instance->getOrderLine($order);

$this->assertEquals('surcharge', $result['type']);
$this->assertEquals(Mage::helper('mpm')->__('Mollie Payment Fee'), $result['name']);
$this->assertEquals(Mage::helper('mpm')->__('Payment Fee'), $result['name']);
$this->assertEquals(1, $result['quantity']);
$this->assertEquals('EUR', $result['unitPrice']['currency']);
$this->assertEquals($paymentFeeIncludingTax, $result['unitPrice']['value']);
Expand Down
26 changes: 22 additions & 4 deletions app/code/community/Mollie/Mpm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<config>
<modules>
<Mollie_Mpm>
<version>5.5.1</version>
<version>5.5.2</version>
</Mollie_Mpm>
</modules>
<global>
Expand Down Expand Up @@ -111,11 +111,11 @@
</sales_order_creditmemo_save_after>
<sales_order_shipment_save_before>
<observers>
<mollie_sales_order_shipment_save_after>
<mollie_sales_order_shipment_save_before>
<type>singleton</type>
<class>Mollie_Mpm_Model_Observer</class>
<method>salesOrderShipmentSaveBefore</method>
</mollie_sales_order_shipment_save_after>
</mollie_sales_order_shipment_save_before>
</observers>
</sales_order_shipment_save_before>
<sales_order_shipment_track_save_after>
Expand All @@ -127,6 +127,24 @@
</mollie_sales_order_shipment_track_save_after>
</observers>
</sales_order_shipment_track_save_after>
<controller_action_predispatch_onestepcheckout_index_index>
<observers>
<mollie_controller_action_predispatch_onestepcheckout_index_index>
<type>singleton</type>
<class>Mollie_Mpm_Model_Observer</class>
<method>restoreQuoteWhenReturningFromMollie</method>
</mollie_controller_action_predispatch_onestepcheckout_index_index>
</observers>
</controller_action_predispatch_onestepcheckout_index_index>
<controller_action_predispatch_checkout_onepage_index>
<observers>
<mollie_controller_action_predispatch_onestepcheckout_index_index>
<type>singleton</type>
<class>Mollie_Mpm_Model_Observer</class>
<method>restoreQuoteWhenReturningFromMollie</method>
</mollie_controller_action_predispatch_onestepcheckout_index_index>
</observers>
</controller_action_predispatch_checkout_onepage_index>
</events>
<sales>
<quote>
Expand Down Expand Up @@ -219,7 +237,7 @@
<pdf>
<totals>
<payment_fee translate="title">
<title>Mollie payment fee</title>
<title>Payment Fee</title>
<font_size>7</font_size>
<display_zero>0</display_zero>
<sort_order>100</sort_order>
Expand Down

0 comments on commit eb3a9f4

Please sign in to comment.