[interchange-cvs] interchange - heins modified lib/Vend/Interpolate.pm
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Wed Jul 3 11:02:01 2002
User: heins
Date: 2002-07-03 15:01:59 GMT
Modified: lib/Vend Interpolate.pm
Log:
* Add sorting to simple options in [item-options ...], and enhance code to
allow configurable sorting.
-- In simplest case, acts as does currently. Matrix options are sorted
by o_sort (or the mapped value of that) automatically, simple are
not sorted.
-- By passing sort=3D1 as an option, i.e. [item-options sort=3D1], simple
options are sorted by o_sort (or the mapped value)
-- Enhance code to allow sorting by an arbitrary field with
[item-options sort=3D1 sort-field=3D"arbitrary_field"]. Adding
sort-option=3Dr reverses the sort.
-- Combine option code together for all three
Revision Changes Path
2.74 +33 -8 interchange/lib/Vend/Interpolate.pm
rev 2.74, prev_rev 2.73
Index: Interpolate.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.73
retrieving revision 2.74
diff -u -r2.73 -r2.74
--- Interpolate.pm 27 Jun 2002 22:24:10 -0000 2.73
+++ Interpolate.pm 3 Jul 2002 15:01:59 -0000 2.74
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#=20
-# $Id: Interpolate.pm,v 2.73 2002/06/27 22:24:10 jon Exp $
+# $Id: Interpolate.pm,v 2.74 2002/07/03 15:01:59 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA =3D qw(Exporter);
=20
-$VERSION =3D substr(q$Revision: 2.73 $, 10);
+$VERSION =3D substr(q$Revision: 2.74 $, 10);
=20
@EXPORT =3D qw (
=20
@@ -1621,6 +1621,7 @@
#::logDebug("entering tag_options for $sku");
=20
$opt =3D get_option_hash($opt);
+
my $table =3D $opt->{table} || $::Variable->{MV_OPTION_TABLE} || 'options=
';
=20
if($opt->{report}) {
@@ -1645,8 +1646,9 @@
my $inv_func;
if($opt->{inventory}) {
my ($t, $c) =3D split /[.:]+/, $opt->{inventory};
- if($db =3D database_exists_ref($t)) {
- $inv_func =3D $db->field_accessor($c);
+ my $idb;
+ if($idb =3D database_exists_ref($t)) {
+ $inv_func =3D $idb->field_accessor($c);
}
}
=20
@@ -1667,6 +1669,24 @@
@{$record}{keys %rec} =3D (values %rec);
}
=20
+ my $rsort =3D '';
+ $map{o_sort} ||=3D 'o_sort';
+ if($opt->{sort}) {
+ $map{o_sort} =3D $opt->{sort_field} if $opt->{sort_field};
+
+ if(! defined $db->test_column($map{o_sort}) ) {
+ logError(
+ "item-options sort column '%s' non-existent, unsorted",
+ $map{o_sort},
+ );
+ }
+ else {
+ $rsort =3D " ORDER BY $map{o_sort}";
+ my $sopt =3D $opt->{sort_option} || '';
+ $rsort .=3D " DESC" if $sopt =3D~ /^(r(?:ev(?:erse)?)?|desc(?:ending)?)=
/i;
+ }
+ }
+
return if ! $record->{o_enable};
#::logDebug("record for $sku says options enabled");
=20
@@ -1698,11 +1718,12 @@
}
my $fsel =3D $map{sku} || 'sku';
my $rsel =3D $db->quote($sku, $fsel);
- my $rsort =3D $map{o_sort} || 'o_sort';
+ $rsort ||=3D " ORDER BY $map{o_sort}";
=20=09=09
my $q =3D "SELECT " .
join (",", @rf) .
- " FROM $table where $fsel =3D $rsel ORDER BY $rsort";
+ " FROM $table where $fsel =3D $rsel $rsort";
+#::logDebug("tag_options separate query: $q");
my $ary =3D $db->query($q);=20
my $ref;
my $i =3D 0;
@@ -1774,10 +1795,11 @@
my $lcol =3D $map{sku} || 'sku';
my $lval =3D $db->quote($sku, $lcol);
=20
- my $rsort =3D $map{o_sort} || 'o_sort';
+ $rsort ||=3D " ORDER BY $map{o_sort}";
=20=09=09
my $q =3D "SELECT " . join(",", @rf);
- $q .=3D " FROM $table where $lcol =3D $lval ORDER BY $rsort";
+ $q .=3D " FROM $table where $lcol =3D $lval $rsort";
+#::logDebug("tag_options matrix query: $q");
my $ary =3D $db->query($q);=20
my $ref;
my $price =3D {};
@@ -1817,6 +1839,7 @@
$item || undef,
);
$out .=3D "</td>" if $opt->{td};
+#::logDebug("matrix option returning $out");
}
elsif($record->{o_modular}) {
#::logDebug("modular options");
@@ -1830,6 +1853,8 @@
my $rsel =3D $db->quote($sku, $fsel);
=20=09=09
my $q =3D "SELECT " . join (",", @rf) . " FROM $table where $fsel =3D $r=
sel";
+ $q .=3D $rsort;
+#::logDebug("tag_options simple query: $q");
my $ary =3D $db->query($q);=20
my $ref;
foreach $ref (@$ary) {