Skip to content

Commit

Permalink
[NN-347] Fix to prevent infinite loop with payment module which uses … (
Browse files Browse the repository at this point in the history
#18)

* [NN-347] Fix to prevent infinite loop with payment module which uses transactions

* [NN-347] PHPCS fix
  • Loading branch information
Ruslan Mavlyanov authored and gromovdmi committed Mar 29, 2018
1 parent 1690423 commit f1f1669
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
49 changes: 35 additions & 14 deletions app/code/community/Mygento/Kkm/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,29 @@ public function sendCheque($observer)
return;
}

$helper->addLog('sendCheque ' . $invoice->getData('increment_id'));
$order = $invoice->getOrder();

//Проверяем флаг, чтобы предотвратить повторную отправку
if ($invoice->getSendCheque()) {
return;
}

$order = $invoice->getOrder();
$invoiceOrigData = $invoice->getOrigData();

if ($helper->skipCheque($order)) {
$helper->addLog('Skipped send cheque. Payment method: ' . $order->getPayment()->getMethod()
. ', currency: ' . $order->getOrderCurrencyCode());
if ($invoice->getOrigData() && isset($invoiceOrigData['increment_id'])) {
return;
}

if ($invoice->getOrigData() && isset($invoiceOrigData['increment_id'])) {
if ($helper->skipCheque($order)) {
$helper->addLog('Skipped send cheque. Payment method: ' . $order->getPayment()->getMethod()
. ', currency: ' . $order->getOrderCurrencyCode());
return;
}

$helper->addLog('sendCheque ' . $invoice->getData('increment_id'));
try {
//Сетим флаг, чтобы предотвратить повторную отправку
$invoice->setSendCheque(1);
$helper->getVendorModel()->sendCheque($invoice, $order);
} catch (Mygento_Kkm_SendingException $e) {
$helper->processError($e);
Expand All @@ -53,14 +60,19 @@ public function sendCheque($observer)
public function cancelCheque($observer)
{
$helper = Mage::helper('kkm');
$helper->addLog('cancelCheque');

$creditmemo = $observer->getEvent()->getCreditmemo();
if (!$helper->getConfig('general/enabled') || !$helper->getConfig('general/auto_send_after_cancel')) {
return;
}

$order = $creditmemo->getOrder();
$order = $creditmemo->getOrder();

//Проверяем флаг, чтобы предотвратить повторную отправку
if ($creditmemo->getCancelCheque()) {
return;
}

$creditmemoOrigData = $creditmemo->getOrigData();

if ($helper->skipCheque($order)) {
Expand All @@ -73,7 +85,10 @@ public function cancelCheque($observer)
return;
}

$helper->addLog('cancelCheque');
try {
//Сетим флаг, чтобы предотвратить повторную отправку
$creditmemo->setCancelCheque(1);
$helper->getVendorModel()->cancelCheque($creditmemo, $order);
} catch (Mygento_Kkm_SendingException $e) {
$helper->processError($e);
Expand Down Expand Up @@ -144,7 +159,7 @@ public function updateTransactions()
return;
}

$waitStatuses = Mage::getModel('kkm/status')->getCollection()
$waitStatuses = Mage::getModel('kkm/status')->getCollection()
->addFieldToFilter('short_status', 'wait')
//->addFieldToFilter('resend_count', [["null" => true], ['lt' => $autoSendLimit]])
;
Expand Down Expand Up @@ -197,8 +212,14 @@ public function updateTransactions()
}
}

$helper->addLog("{$waitUpdated} records with status 'wait' were successfully updated by CRON.", Zend_Log::WARN);
$helper->addLog("{$failUpdated} records with status 'fail' were successfully resent or updated by CRON.", Zend_Log::WARN);
$helper->addLog(
"{$waitUpdated} records with status 'wait' were successfully updated by CRON.",
Zend_Log::WARN
);
$helper->addLog(
"{$failUpdated} records with status 'fail' were successfully resent or updated by CRON.",
Zend_Log::WARN
);
}

public function addExtraButtons($observer)
Expand All @@ -223,8 +244,8 @@ public function addExtraButtons($observer)
return;
}

$statusModel = Mage::getModel('kkm/status')->loadByEntity($entity);
$status = json_decode($statusModel->getStatus());
$statusModel = Mage::getModel('kkm/status')->loadByEntity($entity);
$status = json_decode($statusModel->getStatus());

$this->addPhpUnitTestButton($observer);

Expand Down Expand Up @@ -345,7 +366,7 @@ public function addPhpUnitTestButton($observer)
$block->addButton('phpunit_data', $data);
}

/**Check is current page appropriate for "resend to kkm" button
/** Check is current page appropriate for "resend to kkm" button
*
* @param type $block
* @return boolean
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Mygento/Kkm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Mygento_Kkm>
<version>1.1.6</version>
<version>1.1.6.1</version>
</Mygento_Kkm>
</modules>
<frontend>
Expand Down

0 comments on commit f1f1669

Please sign in to comment.