From a21afb110b8feeced33e534b9f023bf633eebc55 Mon Sep 17 00:00:00 2001 From: Yaroslav Garmash Date: Wed, 18 Dec 2024 10:48:44 +0300 Subject: [PATCH] Legacy: custom out of stock validation error fix --- Model/Api/CreateOrder.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Model/Api/CreateOrder.php b/Model/Api/CreateOrder.php index 1001e0dbd..097486c92 100644 --- a/Model/Api/CreateOrder.php +++ b/Model/Api/CreateOrder.php @@ -287,7 +287,7 @@ public function execute( $this->sendResponse(422, [ 'status' => 'failure', 'error' => [[ - 'code' => 6009, + 'code' => ($e->getMessage() && $this->isCustomOutOfStockMsg($e->getMessage())) ? self::E_BOLT_ITEM_OUT_OF_INVENTORY : 6009, 'data' => [[ 'reason' => 'Unprocessable Entity: ' . $e->getMessage(), ]] @@ -839,4 +839,13 @@ protected function getTotalAmountFromTransaction($transaction) { return $transaction->order->cart->total_amount->amount; } + + /** + * @param $msg + * @return bool + */ + protected function isCustomOutOfStockMsg($msg) + { + return strpos(strtolower($msg), 'out of stock') !== false; + } }