Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
PLGMAGTWOS-219. Keep cart alive function is now configurable. Merchan…
Browse files Browse the repository at this point in the history
…ts can now choose to not restore the cart, avoiding any stock issues because magento processes stock not correctly (magento/magento2#9969)
  • Loading branch information
JonkRuud committed Dec 20, 2017
1 parent 47a5f6f commit 53464be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Model/Observers/RestoreQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan

public function execute(\Magento\Framework\Event\Observer $observer)
{

$paymentModel= $this->_objectManager->create('MultiSafepay\Connect\Model\Connect');
$session = $this->_objectManager->get('Magento\Checkout\Model\Session');
$lastRealOrder = $session->getLastRealOrder();
if ($lastRealOrder != null && $lastRealOrder->getState() == \Magento\Sales\Model\Order::STATE_NEW) {
$payment = $lastRealOrder->getPayment()->getMethodInstance();

if (is_object($payment) && in_array($payment->getCode(), $this->_objectManager->create('MultiSafepay\Connect\Helper\Data')->gateways) && $payment->getCode() != "mspbanktransfer") {

$keepCartAlive = $paymentModel->getMainConfigData('keep_cart_alive', $lastRealOrder->getStoreId());

if (is_object($payment) && in_array($payment->getCode(), $this->_objectManager->create('MultiSafepay\Connect\Helper\Data')->gateways) && $payment->getCode() != "mspbanktransfer" && $keepCartAlive) {
$session->restoreQuote();
}
}
Expand Down
7 changes: 6 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Create a payment link for manually created orders</comment>
</field>
<field id="keep_cart_alive" translate="label" type="select" sortOrder="17" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Keep cart alive</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>This will restore the cart when processing the transaction. When a consumer uses the back button, the cart won't be empty.</comment>
</field>
<!--<field id="order_status_initialized" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
<label>MultiSafepay Status: Initialized</label>
<source_model>MultiSafepay\Connect\Model\Config\Source\Order\Status\Status</source_model>
Expand Down Expand Up @@ -123,7 +128,7 @@
<label>MultiSafepay Status: Cancelled</label>
<source_model>MultiSafepay\Connect\Model\Config\Source\Order\Status\Status</source_model>
</field>-->
<field id="msp_debug" translate="label" type="select" sortOrder="16" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="msp_debug" translate="label" type="select" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable debug mode</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>All API request will be stored within var/log/multisafepay.log</comment>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<payment_action>true</payment_action>
<model>MultiSafepay\Connect\Model\Connect</model>
<transaction_currency>1</transaction_currency>
<keep_cart_alive>1</keep_cart_alive>
<group>multisafepay_connect</group>
</connect>
</multisafepay>
Expand Down

0 comments on commit 53464be

Please sign in to comment.