From 85e35df2f634f07c8d0c01342c0b468e2933f2c6 Mon Sep 17 00:00:00 2001 From: Thales Mendes Date: Tue, 25 Jan 2022 01:37:06 -0300 Subject: [PATCH] :bug: added string verification at product helper --- Helper/ProductHelper.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Helper/ProductHelper.php b/Helper/ProductHelper.php index e53df27e..6cac9043 100644 --- a/Helper/ProductHelper.php +++ b/Helper/ProductHelper.php @@ -80,7 +80,7 @@ public static function getDiscountAmount($product) */ public static function extractValueFromTitle($title) { - return (float)preg_replace('/[^0-9,]/', '', $title); + return (float)preg_replace('/[^0-9,]/', '', ProductHelper::getStringBetween($title, '(', ')')); } /** @@ -104,6 +104,22 @@ public static function convertDecimalMoney($amount) return $amount; } + /** + * @param string $str + * @param string $starting_word + * @param string $ending_word + * @return string + */ + public static function getStringBetween($str, $first_string, $second_string) + { + $arr = explode($first_string, $str); + if (isset($arr[1])) { + $arr = explode($second_string, $arr[1]); + return $arr[0]; + } + return ''; + } + /** * @param int $number * @return float