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

Commit

Permalink
Optimize logic on InvoicePaid
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhansch committed May 6, 2019
1 parent c9d08ab commit 00518b6
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions modules/addons/order_management/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,50 @@
/*
* Accept paid orders
*/
$command = 'GetOrders';
$command = 'GetInvoice';
$values = array(
'status' => 'Pending',
'limitnum' => '100',
'invoiceid' => $paidInvoiceID
);

$results = localAPI($command, $values);
$invoiceResults = localAPI($command, $values);

if ($results['result'] == 'success') {
for ($i = 0; $i < $results['numreturned']; $i++) {
$order = $results['orders']['order'][$i];
if ($invoiceResults['result'] == 'success') {
$userID = $invoiceResults['userid'];

$invoiceID = $order['invoiceid'];
$command = 'GetOrders';
$values = array(
'status' => 'Pending',
'limitnum' => '100',
'userid' => $userID
);

if ($invoiceID == $paidInvoiceID) {
$orderID = $order['id'];
$orderResults = localAPI($command, $values);

$command = 'AcceptOrder';
$values = array(
'orderid' => $orderID,
);
if ($orderResults['result'] == 'success') {
for ($i = 0; $i < $orderResults['numreturned']; $i++) {
$order = $orderResults['orders']['order'][$i];

$acceptOrderResults = localAPI($command, $values);
$invoiceID = $order['invoiceid'];

if ($acceptOrderResults['result'] != 'success') {
logActivity('[Order Management] An error occured accepting order ' . $orderID . ': ' . $acceptOrderResults['result']);
if ($invoiceID == $paidInvoiceID) {
$orderID = $order['id'];

$command = 'AcceptOrder';
$values = array(
'orderid' => $orderID,
);

$acceptOrderResults = localAPI($command, $values);

if ($acceptOrderResults['result'] != 'success') {
logActivity('[Order Management] An error occured accepting order ' . $orderID . ': ' . $acceptOrderResults['result']);
}
}
}
} else {
logActivity('[Order Management] An error occured with getting orders: ' . $orderResults['result']);
}
} else {
logActivity('[Order Management] An error occured with getting orders: ' . $results['result']);
logActivity('[Order Management] An error occured with getting invoice: ' . $invoiceResults['result']);
}
});

0 comments on commit 00518b6

Please sign in to comment.