Skip to content

Commit

Permalink
Merge pull request #147 from buckaroo-it/BP-3473-Status-changed-from-…
Browse files Browse the repository at this point in the history
…in-backorder-not-payed-to-payed

Bp 3473 status changed from in backorder not payed to payed
  • Loading branch information
vegimcarkaxhija authored Mar 18, 2024
2 parents e9a2236 + 5f5e189 commit 6f98cba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 22 additions & 3 deletions buckaroo3.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,13 @@ public function hookDisplayHeader()
$this->context->controller->addJS($this->_path . 'views/js/buckaroo.js', 'all');
}

public static function resolveStatusCode($status_code)
public static function resolveStatusCode($status_code, $id_order = null)
{
switch ($status_code) {
case BuckarooAbstract::BUCKAROO_SUCCESS:
return Configuration::get('BUCKAROO_ORDER_STATE_SUCCESS') ?
Configuration::get('BUCKAROO_ORDER_STATE_SUCCESS') : Configuration::get('PS_OS_PAYMENT');
return self::isOrderBackOrder($id_order) ?
Configuration::get('PS_OS_OUTOFSTOCK_PAID') :
(Configuration::get('BUCKAROO_ORDER_STATE_SUCCESS') ?: Configuration::get('PS_OS_PAYMENT'));
case BuckarooAbstract::BUCKAROO_PENDING_PAYMENT:
return Configuration::get('BUCKAROO_ORDER_STATE_DEFAULT');
case BuckarooAbstract::BUCKAROO_CANCELED:
Expand All @@ -479,6 +480,24 @@ public static function resolveStatusCode($status_code)
}
}

private static function isOrderBackOrder($orderId)
{
$order = new Order($orderId);
$orderDetails = $order->getOrderDetailList();
/** @var OrderDetail $detail */
foreach ($orderDetails as $detail) {
$orderDetail = new OrderDetail($detail['id_order_detail']);
if (
Configuration::get('PS_STOCK_MANAGEMENT') &&
($orderDetail->getStockState() || $orderDetail->product_quantity_in_stock < 0)
) {
return true;
}
}

return false;
}

public function getBuckarooFeeByCartId($id_cart)
{
$id_cart = (int) $id_cart;
Expand Down
3 changes: 2 additions & 1 deletion controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public function initContent()
} else {
$logger->logInfo('Update the order', 'Order ID: ' . $id_order);

$new_status_code = Buckaroo3::resolveStatusCode($response->status);
$new_status_code = Buckaroo3::resolveStatusCode($response->status, $id_order);

$order = new Order($id_order);

if (!in_array($order->reference, $references)) {
Expand Down

0 comments on commit 6f98cba

Please sign in to comment.