Skip to content

Commit

Permalink
FIX: Product Variants Codes Sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
BadPixxel committed Mar 29, 2024
1 parent ac2d1bd commit a715682
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion splash/_conf/defines.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
33 changes: 23 additions & 10 deletions splash/src/Services/AttributesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//====================================================================//
Expand All @@ -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)
;
}
}
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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))));
}
}
1 change: 0 additions & 1 deletion splash/src/Services/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace Splash\Local\Services;

use _PHPStan_a2a733b6a\Nette\PhpGenerator\Method;
use Splash\Local\Local;

/**
Expand Down

0 comments on commit a715682

Please sign in to comment.