Skip to content

Commit

Permalink
check if order is backOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
vegimcarkaxhija committed Mar 15, 2024
1 parent 230e1aa commit 5f5e189
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions buckaroo3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5f5e189

Please sign in to comment.