Files
opensourcepos/app/Helpers/attribute_helper.php
objec 855f08c4df Logic improvements
- Add getAttributeValueByAttributeId() to assist in comparing the value
- Corrected Business logic
- Added attribute_helper.php
- Simplified logic to store attribute values
- Removed duplicate call to save attribute link

Signed-off-by: objec <objecttothis@gmail.com>
2026-03-06 17:46:48 +04:00

34 lines
954 B
PHP

<?php
/**
* Translates the attribute type to the corresponding database column name.
*
* Maps attribute type constants to their corresponding attribute_values table columns.
* Defaults to 'attribute_value' for TEXT, DROPDOWN and CHECKBOX attribute types.
*
* @param string $input The attribute type constant (DATE, DECIMAL, etc.)
* @return string The database column name for storing this attribute type
*/
function getAttributeDataType(string $input): string
{
$columnMap = [
DATE => 'attribute_date',
DECIMAL => 'attribute_decimal',
];
return $columnMap[$input] ?? 'attribute_value';
}
/**
* Validates that the provided data type is an allowed attribute value type.
*
* @param string $dataType
* @return void
*/
function validateAttributeValueType(string $dataType): void
{
if (!in_array($dataType, ATTRIBUTE_VALUE_TYPES, true)) {
throw new InvalidArgumentException('Invalid data type');
}
}