allow more values when creating a product option
authorTony Cook <tony@develop-help.com>
Sat, 18 Apr 2020 03:06:41 +0000 (13:06 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 18 Apr 2020 03:06:41 +0000 (13:06 +1000)
site/cgi-bin/modules/BSE/Edit/Product.pm

index e947ddf47617b628db6a128052511cc07de0f924..e668ffb4aef35f76a6a027ddc76e78e4432f8463 100644 (file)
@@ -670,30 +670,6 @@ my %option_fields =
     rules => "dh_one_line",
     maxlength => 255,
    },
-   value2 =>
-   {
-    description => "Value 2",
-    rules => "dh_one_line",
-    maxlength => 255,
-   },
-   value3 =>
-   {
-    description => "Value 3",
-    rules => "dh_one_line",
-    maxlength => 255,
-   },
-   value4 =>
-   {
-    description => "Value 4",
-    rules => "dh_one_line",
-    maxlength => 255,
-   },
-   value5 =>
-   {
-    description => "Value 5",
-    rules => "dh_one_line",
-    maxlength => 255,
-   },
   );
 
 =head1 Targets
@@ -751,7 +727,17 @@ sub req_add_option {
     or return $self->_service_error($req, $article, $articles, "Insufficient product access to add options");
 
   my %errors;
-  $req->validate(fields => \%option_fields,
+  my %work_option_fields = \%option_fields;
+  for my $field (grep /^value[1-9][0-9]*$/, $req->cgi->param) {
+    my ($index) = ( $field =~ /([1-9][0-9]*)$/);
+    $work_option_fields{$field} =
+      {
+       description => "Value $index",
+       rules => "dh_one_line",
+       maxlength => 255,
+      };
+  }
+  $req->validate(fields => \%work_option_fields,
                 errors => \%errors);
   keys %errors
     and return $self->_service_error($req, $article, $articles, undef, 
@@ -770,7 +756,7 @@ sub req_add_option {
   my $order = time;
   my @values;
   my %value_keys;
-  for my $value_key (sort grep /^value/, keys %option_fields) {
+  for my $value_key (sort grep /^value/, keys %work_option_fields) {
     my ($value) = $cgi->param($value_key);
     if (defined $value && $value =~ /\S/) {
       my $entry = BSE::TB::ProductOptionValues->make