From 55856f10e549d6c20768b5416a49b348646f1231 Mon Sep 17 00:00:00 2001 From: vegim carkaxhija Date: Fri, 15 Mar 2024 13:08:01 +0100 Subject: [PATCH 1/6] fix status code --- controllers/front/return.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/front/return.php b/controllers/front/return.php index 6fbbfc82..18364221 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -132,6 +132,9 @@ public function initContent() $logger->logInfo('Update the order', 'Order ID: ' . $id_order); $new_status_code = Buckaroo3::resolveStatusCode($response->status); + if($order->getCurrentState() == 12 && $new_status_code == 2){ + $new_status_code = 9; + } $order = new Order($id_order); if (!in_array($order->reference, $references)) { From 628bb8b8c734969d9ebb319e1a727b2c8ca5708a Mon Sep 17 00:00:00 2001 From: vegim carkaxhija Date: Fri, 15 Mar 2024 13:52:24 +0100 Subject: [PATCH 2/6] fix status code --- buckaroo3.php | 7 ++++--- controllers/front/return.php | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/buckaroo3.php b/buckaroo3.php index 54d7afdc..c981bca0 100644 --- a/buckaroo3.php +++ b/buckaroo3.php @@ -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, $orderStatus = 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 ($orderStatus == Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')) ? + 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: diff --git a/controllers/front/return.php b/controllers/front/return.php index 18364221..2bc43b2c 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -131,10 +131,8 @@ public function initContent() } else { $logger->logInfo('Update the order', 'Order ID: ' . $id_order); - $new_status_code = Buckaroo3::resolveStatusCode($response->status); - if($order->getCurrentState() == 12 && $new_status_code == 2){ - $new_status_code = 9; - } + $new_status_code = Buckaroo3::resolveStatusCode($response->status,$order->getCurrentState()); + $order = new Order($id_order); if (!in_array($order->reference, $references)) { From 193ea0837de29441d599f504552a4d5bfbca69f0 Mon Sep 17 00:00:00 2001 From: vegim carkaxhija Date: Fri, 15 Mar 2024 13:55:06 +0100 Subject: [PATCH 3/6] fix status code --- buckaroo3.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buckaroo3.php b/buckaroo3.php index c981bca0..778b41b4 100644 --- a/buckaroo3.php +++ b/buckaroo3.php @@ -460,11 +460,11 @@ public function hookDisplayHeader() $this->context->controller->addJS($this->_path . 'views/js/buckaroo.js', 'all'); } - public static function resolveStatusCode($status_code, $orderStatus = null) + public static function resolveStatusCode($status_code, $orderCurrentState = null) { switch ($status_code) { case BuckarooAbstract::BUCKAROO_SUCCESS: - return ($orderStatus == Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')) ? + return ($orderCurrentState == Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')) ? Configuration::get('PS_OS_OUTOFSTOCK_PAID') : (Configuration::get('BUCKAROO_ORDER_STATE_SUCCESS') ?: Configuration::get('PS_OS_PAYMENT')); case BuckarooAbstract::BUCKAROO_PENDING_PAYMENT: From 4f972cb8405c146f7b4691cc9e663cb8cd550474 Mon Sep 17 00:00:00 2001 From: vegim carkaxhija Date: Fri, 15 Mar 2024 14:23:50 +0100 Subject: [PATCH 4/6] log order --- controllers/front/return.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/front/return.php b/controllers/front/return.php index 2bc43b2c..bac0a681 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -134,6 +134,8 @@ public function initContent() $new_status_code = Buckaroo3::resolveStatusCode($response->status,$order->getCurrentState()); $order = new Order($id_order); + $logger->logInfo('Order ' . $order); + if (!in_array($order->reference, $references)) { header('HTTP/1.1 503 Service Unavailable'); From 230e1aa0be828cedf30656fc661b46c620996216 Mon Sep 17 00:00:00 2001 From: vegim carkaxhija Date: Fri, 15 Mar 2024 14:35:31 +0100 Subject: [PATCH 5/6] remove log --- controllers/front/return.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index bac0a681..2bc43b2c 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -134,8 +134,6 @@ public function initContent() $new_status_code = Buckaroo3::resolveStatusCode($response->status,$order->getCurrentState()); $order = new Order($id_order); - $logger->logInfo('Order ' . $order); - if (!in_array($order->reference, $references)) { header('HTTP/1.1 503 Service Unavailable'); From 5f5e189e585a2feec9fbca1905c27341d0a854ea Mon Sep 17 00:00:00 2001 From: vegim carkaxhija Date: Fri, 15 Mar 2024 14:41:14 +0100 Subject: [PATCH 6/6] check if order is backOrder --- buckaroo3.php | 22 ++++++++++++++++++++-- controllers/front/return.php | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/buckaroo3.php b/buckaroo3.php index 778b41b4..8c3ad9d0 100644 --- a/buckaroo3.php +++ b/buckaroo3.php @@ -460,11 +460,11 @@ public function hookDisplayHeader() $this->context->controller->addJS($this->_path . 'views/js/buckaroo.js', 'all'); } - public static function resolveStatusCode($status_code, $orderCurrentState = null) + public static function resolveStatusCode($status_code, $id_order = null) { switch ($status_code) { case BuckarooAbstract::BUCKAROO_SUCCESS: - return ($orderCurrentState == Configuration::get('PS_OS_OUTOFSTOCK_UNPAID')) ? + 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: @@ -480,6 +480,24 @@ public static function resolveStatusCode($status_code, $orderCurrentState = null } } + 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; diff --git a/controllers/front/return.php b/controllers/front/return.php index 2bc43b2c..60a47662 100644 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -131,7 +131,7 @@ public function initContent() } else { $logger->logInfo('Update the order', 'Order ID: ' . $id_order); - $new_status_code = Buckaroo3::resolveStatusCode($response->status,$order->getCurrentState()); + $new_status_code = Buckaroo3::resolveStatusCode($response->status, $id_order); $order = new Order($id_order);