Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 02fff93e

Von Tamino Steinert vor 6 Tagen hinzugefügt

  • ID 02fff93e602bf4e2119aa236391f7bfd408d2b86
  • Vorgänger 3e50ade5
  • Nachfolger 94dea1d5

Varianten: Partpicker nach Varianten filtern.

Unterschiede anzeigen:

SL/DB/Manager/Part.pm
20 20
    my ($key, $value, $prefix) = @_;
21 21
    return __PACKAGE__->type_filter($value, $prefix);
22 22
  },
23
  all => sub {
24
    my ($key, $value, $prefix) = @_;
25
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ]
26
  },
23
  # all => sub {
24
  #   my ($key, $value, $prefix) = @_;
25
  #   return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ]
26
  # },
27 27
  all_with_makemodel => sub {
28 28
    my ($key, $value, $prefix) = @_;
29 29
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean makemodels.model) ],
......
34 34
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean customerprices.customer_partnumber) ],
35 35
      $prefix . 'customerprices';
36 36
  },
37
  # all_with_variants => sub {
38
  all => sub {
39
    my ($key, $value, $prefix) = @_;
40
    if ($value =~ m/\[/ || $value->{ilike} =~ m/\[/) { #variant_filter
41
      my $ilike = 0;
42
      if ($value->{ilike}) {
43
        $ilike = 1;
44
        $value = $value->{ilike};
45
        $value =~ s/^%//;
46
        $value =~ s/%$//;
47
      }
48
      #clean
49
      $value =~ s/^\s+//;
50
      $value =~ s/\s+$//;
51
      $value =~ s/^.*\[//;
52
      $value =~ s/].*$//;
53
      # search for part_id with all variant_property_values
54
      my @wheres;
55
      my @values;
56
      foreach my $variant_search (split(/\|/, $value)) {
57
        next unless $variant_search;
58
        my $comp = '=';
59
        my $or_and = 'and';
60
        my ($variant_name, $variant_value) = split(/:/, $variant_search);
61
        unless ($variant_name && $variant_value) {
62
          $variant_search =~ s/://;
63
          $variant_name = $variant_value = $variant_search;
64
          $or_and = 'or';
65
        }
66
        if ($ilike) {
67
          $comp = 'ilike';
68
          $variant_name  = "%$variant_name%";
69
          $variant_value = "%$variant_value%";
70
        }
71
        push @wheres, "(prop.abbreviation $comp ? $or_and val.abbreviation $comp ?)";
72
        push @values, $variant_name, $variant_value;
73
      }
74
      return unless @wheres;
75
      my $where = join(' or ', @wheres) || '1=1';
76
      push @values, scalar @wheres; # count_hits
77
      my $query = <<SQL;
78
        SELECT part_id from (
79
          SELECT
80
            t3.part_id, COUNT(*) as count_hits
81
          FROM
82
            variant_property_values val
83
            JOIN variant_properties prop ON (val.variant_property_id = prop.id)
84
            JOIN variant_property_values_parts t3 ON (t3.variant_property_value_id = val.id)
85
          WHERE
86
           $where
87
          GROUP BY t3.part_id
88
        ) as tmp
89
        WHERE count_hits >= ?;
90
SQL
91
      my @part_ids =
92
        map {$_->{part_id}}
93
        selectall_hashref_query($::form, $::form->get_standard_dbh, $query, @values);
94

  
95
      return id => scalar @part_ids ? \@part_ids : (-1); # empty list not allowed
96
    }
97
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ]
98
  }
37 99
);
38 100

  
39 101
sub type_filter {

Auch abrufbar als: Unified diff