From 95d52d33739b56807cdc692dbfedc57ac100ba07 Mon Sep 17 00:00:00 2001
From: Mohamed ELIDRISSI <67818913+elidrissidev@users.noreply.github.com>
Date: Tue, 13 Jul 2021 08:37:50 +0100
Subject: [PATCH] Handle empty Order increment prefix (#1718)

* Handle empty Order increment prefix

A call to `strpos` with an empty needle would throw a warning pre PHP 8.0. This change will check if the prefix is not empty first before performing the call to `strpos`.

* Use the string casted prefix in `strlen` call

Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>

* Fix syntax error

Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>
---
 app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php b/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php
index c89fd4ba312..b3e8f3df541 100644
--- a/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php
+++ b/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php
@@ -45,8 +45,8 @@ public function getNextId()
 
         if (empty($last)) {
             $last = 0;
-        } else if (strpos($last, (string)$this->getPrefix()) === 0) {
-            $last = (int)substr($last, strlen($this->getPrefix()));
+        } else if (!empty($prefix = (string)$this->getPrefix()) && strpos($last, $prefix) === 0) {
+            $last = (int)substr($last, strlen($prefix));
         } else {
             $last = (int)$last;
         }