update
This commit is contained in:
BIN
autoload/.DS_Store
vendored
Normal file
BIN
autoload/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -186,7 +186,7 @@ class ShopProduct
|
||||
$values['id'], $values['name'], $values['short_description'], $values['description'], $values['status'], $values['meta_description'], $values['meta_keywords'], $values['seo_link'],
|
||||
$values['copy_from'], $values['categories'], $values['price_netto'], $values['price_brutto'], $values['vat'], $values['promoted'], $values['warehouse_message_zero'], $values['warehouse_message_nonzero'], $values['tab_name_1'],
|
||||
$values['tab_description_1'], $values['tab_name_2'], $values['tab_description_2'], $values['layout_id'], $values['products_related'], (int) $values['set'], $values['price_netto_promo'], $values['price_brutto_promo'],
|
||||
$values['new_to_date'], $values['stock_0_buy'], $values['wp'], $values['custom_label_0'], $values['custom_label_1'], $values['custom_label_2'], $values['custom_label_3'], $values['custom_label_4'], $values['additional_message'], (int)$values['quantity'], $values['additional_message_text'], $values['additional_message_required'] == 'on' ? 1 : 0, $values['canonical'], $values['meta_title'], $values['producer_id'], $values['sku'], $values['ean'], $values['product_unit'], $values['weight'], $values['xml_name'], $values['custom_field_name']
|
||||
$values['new_to_date'], $values['stock_0_buy'], $values['wp'], $values['custom_label_0'], $values['custom_label_1'], $values['custom_label_2'], $values['custom_label_3'], $values['custom_label_4'], $values['additional_message'], (int)$values['quantity'], $values['additional_message_text'], $values['additional_message_required'] == 'on' ? 1 : 0, $values['canonical'], $values['meta_title'], $values['producer_id'], $values['sku'], $values['ean'], $values['product_unit'], $values['weight'], $values['xml_name'], $values['custom_field_name'], $values['custom_field_required']
|
||||
) ) {
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Produkt został zapisany.', 'id' => $id ];
|
||||
}
|
||||
|
||||
@@ -761,7 +761,7 @@ class ShopProduct
|
||||
}
|
||||
|
||||
public static function save(
|
||||
$product_id, $name, $short_description, $description, $status, $meta_description, $meta_keywords, $seo_link, $copy_from, $categories, $price_netto, $price_brutto, $vat, $promoted, $warehouse_message_zero, $warehouse_message_nonzero, $tab_name_1, $tab_description_1, $tab_name_2, $tab_description_2, $layout_id, $products_related, int $set_id, $price_netto_promo, $price_brutto_promo, $new_to_date, $stock_0_buy, $wp, $custom_label_0, $custom_label_1, $custom_label_2, $custom_label_3, $custom_label_4, $additional_message, int $quantity, $additional_message_text, int $additional_message_required, $canonical, $meta_title, $producer_id, $sku, $ean, $product_unit, $weight, $xml_name, $custom_field_name
|
||||
$product_id, $name, $short_description, $description, $status, $meta_description, $meta_keywords, $seo_link, $copy_from, $categories, $price_netto, $price_brutto, $vat, $promoted, $warehouse_message_zero, $warehouse_message_nonzero, $tab_name_1, $tab_description_1, $tab_name_2, $tab_description_2, $layout_id, $products_related, int $set_id, $price_netto_promo, $price_brutto_promo, $new_to_date, $stock_0_buy, $wp, $custom_label_0, $custom_label_1, $custom_label_2, $custom_label_3, $custom_label_4, $additional_message, int $quantity, $additional_message_text, int $additional_message_required, $canonical, $meta_title, $producer_id, $sku, $ean, $product_unit, $weight, $xml_name, $custom_field_name, $custom_field_required
|
||||
)
|
||||
{
|
||||
global $mdb, $user;
|
||||
@@ -941,13 +941,17 @@ class ShopProduct
|
||||
}
|
||||
|
||||
// dodatkowe pola
|
||||
foreach ( $custom_field_name as $custom_field )
|
||||
for ( $i = 0; $i < count( $custom_field_name ); ++$i )
|
||||
{
|
||||
if ( !empty( $custom_field ) )
|
||||
if ( !empty( $custom_field_name[$i] ) )
|
||||
{
|
||||
$custom_field = $custom_field_name[$i];
|
||||
$custom_field_required = isset( $custom_field_required[$i] ) ? 1 : 0;
|
||||
|
||||
$mdb -> insert( 'pp_shop_products_custom_fields', [
|
||||
'id_product' => (int) $id,
|
||||
'name' => $custom_field,
|
||||
'is_required' => $custom_field_required,
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -1268,13 +1272,20 @@ class ShopProduct
|
||||
|
||||
$mdb -> delete( 'pp_shop_products_custom_fields', [ 'AND' => [ 'id_product' => $product_id, 'id_additional_field[!]' => $exits_custom_ids ] ] );
|
||||
|
||||
foreach ( $custom_field_name as $custom_field )
|
||||
// $custom_field_name i $custom_field_required
|
||||
foreach ( $custom_field_name as $i => $custom_field )
|
||||
{
|
||||
if ( !empty( $custom_field ) )
|
||||
{
|
||||
$is_required = !empty( $custom_field_required[$i] ) ? 1 : 0;
|
||||
|
||||
if ( !$mdb -> count( 'pp_shop_products_custom_fields', [ 'AND' => [ 'id_product' => $product_id, 'name' => $custom_field ] ] ) )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_products_custom_fields', [ 'id_product' => $product_id, 'name' => $custom_field ] );
|
||||
$mdb -> insert( 'pp_shop_products_custom_fields', [ 'id_product' => $product_id, 'name' => $custom_field, 'is_required' => $is_required ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products_custom_fields', [ 'is_required' => $is_required ], [ 'AND' => [ 'id_product' => $product_id, 'name' => $custom_field ] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,17 +322,42 @@ class S
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function normalize_decimal( $val, $precision = 2 )
|
||||
static public function normalize_decimal($val, int $precision = 2)
|
||||
{
|
||||
$input = str_replace( ' ', '', $val );
|
||||
$number = str_replace( ',', '.', $input );
|
||||
if ( strpos( $number, '.' ) )
|
||||
{
|
||||
$groups = explode( '.', str_replace( ',', '.', $number ) );
|
||||
$lastGroup = array_pop( $groups );
|
||||
$number = implode( '', $groups ) . '.' . $lastGroup;
|
||||
if ($val === null || $val === '') {
|
||||
return number_format(0, $precision, '.', '');
|
||||
}
|
||||
return bcadd( round( $number, $precision ), 0, $precision );
|
||||
|
||||
// 1) wstępne czyszczenie
|
||||
$s = (string)$val;
|
||||
$s = str_replace(["\xC2\xA0", ' ', '’', "'"], '', $s); // spacje (w tym NBSP) i apostrofy
|
||||
$s = preg_replace('/[^0-9.,\-]/', '', $s); // zostaw tylko cyfry, . , i -
|
||||
|
||||
// 2) ustalenie separatora dziesiętnego
|
||||
$lastDot = strrpos($s, '.');
|
||||
$lastComma = strrpos($s, ',');
|
||||
|
||||
if ($lastDot !== false && $lastComma !== false) {
|
||||
// oba występują – prawy znak traktujemy jako dziesiętny
|
||||
if ($lastDot > $lastComma) {
|
||||
$s = str_replace(',', '', $s); // , = tysiące
|
||||
} else {
|
||||
$s = str_replace('.', '', $s); // . = tysiące
|
||||
$s = str_replace(',', '.', $s); // , = dziesiętny
|
||||
}
|
||||
} elseif ($lastComma !== false) {
|
||||
// tylko przecinek – traktuj jako dziesiętny
|
||||
$s = str_replace(',', '.', $s);
|
||||
} elseif (substr_count($s, '.') > 1) {
|
||||
// wiele kropek – ostatnia dziesiętna, pozostałe tysiące
|
||||
$pos = strrpos($s, '.');
|
||||
$s = str_replace('.', '', substr($s, 0, $pos)) . '.' . substr($s, $pos + 1);
|
||||
}
|
||||
// na tym etapie mamy opcjonalny '-' i co najwyżej jedną kropkę dziesiętną
|
||||
|
||||
// 3) zaokrąglenie i normalizacja
|
||||
$rounded = round((float)$s, $precision);
|
||||
return number_format($rounded, $precision, '.', '');
|
||||
}
|
||||
|
||||
public static function decimal( $val, $precision = 2, $dec_point = ',', $thousands_sep = ' ' )
|
||||
|
||||
BIN
autoload/front/.DS_Store
vendored
Normal file
BIN
autoload/front/.DS_Store
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user