Add is_required column to pp_shop_products_custom_fields table

This commit introduces a new column `is_required` to the `pp_shop_products_custom_fields` table. The column is of type TINYINT, cannot be null, and has a default value of 1. This change is intended to enhance the product custom fields by allowing the specification of whether a field is mandatory.
This commit is contained in:
2025-08-19 20:31:44 +02:00
parent 84333c1b59
commit ef15f16e18
16 changed files with 137 additions and 28 deletions

View File

@@ -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 ] ] );
}
}
}