From a7156820555a962a75667819ac1650a853ca2013 Mon Sep 17 00:00:00 2001 From: BadPixxel Date: Fri, 29 Mar 2024 11:51:25 +0100 Subject: [PATCH] FIX: Product Variants Codes Sanitizer --- grumphp.yml | 2 +- splash/_conf/defines.inc.php | 2 +- splash/src/Services/AttributesManager.php | 33 ++++++++++++++++------- splash/src/Services/PaymentMethods.php | 1 - 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/grumphp.yml b/grumphp.yml index 3d8e6c8..a50c929 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -38,7 +38,7 @@ parameters: # For Building Splash Module mod-src: '/splash' mod-target: '/splash/' - mod-file: "module_splash-2.19.0" + mod-file: "module_splash-2.19.1" # For Building Splash Manifest yml-enable: false diff --git a/splash/_conf/defines.inc.php b/splash/_conf/defines.inc.php index 5bd5771..90f5067 100644 --- a/splash/_conf/defines.inc.php +++ b/splash/_conf/defines.inc.php @@ -32,7 +32,7 @@ //====================================================================// // Module Version -define("SPL_MOD_VERSION", '2.19.0'); +define("SPL_MOD_VERSION", '2.19.1'); define("SPL_MOD_ID", 9200); define("SPL_MOD_NAME", 'splash'); define("SPL_MOD_CATEGORIE", 'technic'); diff --git a/splash/src/Services/AttributesManager.php b/splash/src/Services/AttributesManager.php index 8840a00..8e94054 100644 --- a/splash/src/Services/AttributesManager.php +++ b/splash/src/Services/AttributesManager.php @@ -64,11 +64,10 @@ public static function init(): array /** * Load All Attribute Values from Database * - * @param int $attributeId Product Attribute Id - * - * @return void + * @param int $attributeId Product Attribute ID + * @param bool $reload Force Reload of Values in Cache */ - public static function loadAttributeValues(int $attributeId) + public static function loadAttributeValues(int $attributeId, bool $reload = false): void { global $db; //====================================================================// @@ -78,7 +77,15 @@ public static function loadAttributeValues(int $attributeId) // Load Attributes Values Cache $attributeValue = new ProductAttributeValue($db); foreach ($attributes as $attribute) { - self::$attributesValuesCache[$attribute->id] = $attributeValue->fetchAllByProductAttribute($attributeId); + if ($reload) { + self::$attributesValuesCache[$attribute->id] = $attributeValue + ->fetchAllByProductAttribute($attributeId) + ; + } else { + self::$attributesValuesCache[$attribute->id] ??= $attributeValue + ->fetchAllByProductAttribute($attributeId) + ; + } } } @@ -120,7 +127,8 @@ public static function getAttributeByCode(string $attributeCode): ?ProductAttrib //====================================================================// // Walk on Attributes Cache foreach ($attributes as $attribute) { - if (strtolower($attributeCode) == strtolower($attribute->ref)) { + if (self::sanitizeName($attributeCode) == self::sanitizeName($attribute->ref)) { + // if (strtolower($attributeCode) == strtolower($attribute->ref)) { return $attribute; } } @@ -150,7 +158,7 @@ public static function addAttribute(string $attributeCode, string $attributeName //====================================================================// // Create New Attribute $attribute = new ProductAttribute($db); - $attribute->ref = strtoupper($attributeCode); + $attribute->ref = self::sanitizeName($attributeCode); $attribute->label = is_string($attributeName) ? $attributeName : $attributeCode; if ($attribute->create($user) < 0) { @@ -306,7 +314,7 @@ public static function getAttributeValueByName(ProductAttribute $attribute, stri //====================================================================// // Walk on Attributes Cache foreach (self::$attributesValuesCache[$attribute->id] as $value) { - if (strtolower($valueName) == strtolower($value->value)) { + if (self::sanitizeName($valueName) == self::sanitizeName($value->value)) { return $value; } } @@ -346,7 +354,7 @@ public static function addAttributeValue(ProductAttribute $attribute, string $va //====================================================================// // Reload Load Attributes Values Cache - self::loadAttributeValues($attribute->id); + self::loadAttributeValues($attribute->id, true); return $value; } @@ -395,8 +403,13 @@ public static function removeAttributeValue(ProductAttributeValue $value): bool } //====================================================================// // Reload Load Attributes Values Cache - self::loadAttributeValues($value->fk_product_attribute); + self::loadAttributeValues($value->fk_product_attribute, true); return true; } + + private static function sanitizeName(string $name): string + { + return strtoupper(dol_sanitizeFileName(dol_string_nospecial(trim($name)))); + } } diff --git a/splash/src/Services/PaymentMethods.php b/splash/src/Services/PaymentMethods.php index c43835b..eed1231 100644 --- a/splash/src/Services/PaymentMethods.php +++ b/splash/src/Services/PaymentMethods.php @@ -15,7 +15,6 @@ namespace Splash\Local\Services; -use _PHPStan_a2a733b6a\Nette\PhpGenerator\Method; use Splash\Local\Local; /**