mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 06:14:51 -04:00
- 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>
34 lines
954 B
PHP
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');
|
|
}
|
|
}
|