Refactor value handling in multiple classes to streamline data processing

This commit is contained in:
2024-11-01 00:11:11 +01:00
parent 9e3b109c39
commit 1a68e5b58a
24 changed files with 251 additions and 473 deletions

View File

@@ -17,18 +17,8 @@ class ShopAttribute
static public function values_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania wartości atrybutu wystąpił błąd. Proszę spróbować ponownie.' ];
$values_tmp = json_decode( \S::get( 'values' ), true );
$values = json_decode( \S::get( 'values' ), true );
$values = [];
foreach ( $values_tmp as $item )
{
$name = $item['name'];
$value = $item['value'];
$keys = \S::parse_name( $name );
\S::set_array_value( $values, $keys, $value );
}
;
if ( $id = \admin\factory\ShopAttribute::values_save( (int) \S::get( 'attribute_id' ), $values['name'], $values['value'], $values['ids'], $values['default_value'], $values['impact_on_the_price'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Wartości atrybutu zostały zapisane.', 'id' => $id ];
@@ -57,17 +47,7 @@ class ShopAttribute
public static function attribute_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania atrybutu wystąpił błąd. Proszę spróbować ponownie.' ];
$values_tmp = json_decode( \S::get( 'values' ), true );
$values = [];
foreach ( $values_tmp as $item )
{
$name = $item['name'];
$value = $item['value'];
$keys = \S::parse_name( $name );
\S::set_array_value( $values, $keys, $value );
}
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopAttribute::attribute_save( (int) $values['id'], $values['name'], $values['status'] == 'on' ? 1 : 0, (int) $values['type'], (int) $values['o'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Atrybut został zapisany.', 'id' => $id ];