[interchange-cvs] interchange - heins modified 2 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Fri Dec 28 12:56:01 2001
User: heins
Date: 2001-12-28 17:55:44 GMT
Modified: lib/Vend Data.pm Interpolate.pm
Log:
* Add new experimental [PREFIX-common field] that returns common
data based on code then mv_sku. Sequence is:
1. If mv_ib is set (i.e. item is ordered from a specific database)
then that is looked for first with item code.
2. Other ProductFiles are scanned in order for code match.
3. If mv_ib is set (i.e. item is ordered from a specific database)
then that is looked for with mv_sku (if existant).
4. Other ProductFiles are scanned in order for mv_sku match.
In all cases, the data is returned if it has a length.
Example:
products.txt:
sku description
os28005 Trim Brush
options.txt:
sku description
os28005-CAM-BLK Trim Brush, Camel Hair, Black
os28005-CAM-WHT
Cart:
[
{
code => 'os28005-CAM-BLK',
quantity => 1,
mv_ib => 'options',
mv_sku => 'os28005',
},
{
code => 'os28005-CAM-WHT',
quantity => 1,
mv_ib => 'options',
mv_sku => 'os28005',
},
]
[item-list]
FIELD [item-code]: [item-field description]
COMMON [item-code]: [item-common description]
[/item-list]
Yields:
FIELD os28005-CAM-BLK: Trim Brush, Camel Hair, Black
COMMON os28005-CAM-BLK: Trim Brush, Camel Hair, Black
FIELD os28005-CAM-WHT:
COMMON os28005-CAM-WHT: Trim Brush
* Add inventory check option for [item-options ...] tag. If the
item is a matrix option, the option will not be returned if
the quantity is less than 1.
Example:
[item-options inventory=inventory::quantity]
Revision Changes Path
2.4 +35 -1 interchange/lib/Vend/Data.pm
rev 2.4, prev_rev 2.3
Index: Data.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Data.pm,v
retrieving revision 2.3
retrieving revision 2.4
diff -u -r2.3 -r2.4
--- Data.pm 2001/10/25 23:31:03 2.3
+++ Data.pm 2001/12/28 17:55:44 2.4
@@ -1,6 +1,6 @@
# Vend::Data - Interchange databases
#
-# $Id: Data.pm,v 2.3 2001/10/25 23:31:03 jon Exp $
+# $Id: Data.pm,v 2.4 2001/12/28 17:55:44 mheins Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -38,6 +38,7 @@
import_database
increment_field
item_category
+item_common
item_description
item_field
item_price
@@ -48,6 +49,7 @@
product_code_exists_ref
product_code_exists_tag
product_description
+product_common
product_field
product_price
set_field
@@ -313,6 +315,21 @@
return $db->field($code, $field_name);
}
+
+sub product_common {
+ my ($field_name, $code) = @_;
+#::logDebug("product_field: name=$field_name code=$code base=$base");
+ my $result;
+ for(@{$Vend::Cfg->{ProductFiles}}) {
+ my $db = database_exists_ref($_)
+ or next;
+ next unless defined $db->test_column($field_name);
+ $result = database_field($db, $code, $field_name);
+ length($result) and last;
+ }
+ return $result;
+}
+
my %T;
TAGBUILD: {
@@ -1657,6 +1674,23 @@
my $item = shift;
my $base = $Vend::Database{$item->{mv_ib}} || $Products;
return database_field($base, $item->{code}, $Vend::Cfg->{DescriptionField});
+}
+
+sub item_common {
+ my ($item, $field) = @_;
+ my $base = $item->{mv_ib};
+ my $res;
+ foreach my $code ($item->{code}, $item->{mv_sku}) {
+ next if ! length($code);
+ for my $dbname ($base, @{$Vend::Cfg->{ProductFiles}} ) {
+ next if ! $dbname;
+ my $db = database_exists_ref($dbname)
+ or next;
+ last unless defined $db->test_column($field);
+ $res = database_field($db, $code, $field);
+ return $res if length $res;
+ }
+ }
}
sub item_field {
2.34 +28 -2 interchange/lib/Vend/Interpolate.pm
rev 2.34, prev_rev 2.33
Index: Interpolate.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.33
retrieving revision 2.34
diff -u -r2.33 -r2.34
--- Interpolate.pm 2001/12/28 17:16:26 2.33
+++ Interpolate.pm 2001/12/28 17:55:44 2.34
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.33 2001/12/28 17:16:26 mheins Exp $
+# $Id: Interpolate.pm,v 2.34 2001/12/28 17:55:44 mheins Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.33 $, 10);
+$VERSION = substr(q$Revision: 2.34 $, 10);
@EXPORT = qw (
@@ -294,6 +294,7 @@
_calc
_change
_code
+ _common
_data
_description
_discount
@@ -394,6 +395,7 @@
'_field_if' => qr($T{_field}(\d*)$Spacef(!?)\s*($Codere)$Optr\]($Some)),
'_field_if_wo' => qr($T{_field}$Spacef(!?)\s*($Codere$Optr)\]),
'_field' => qr($T{_field}$Mandf\]),
+ '_common' => qr($T{_common}$Mandf\]),
'_increment' => qr($T{_increment}\]),
'_last' => qr($T{_last}\]\s*($Some)\s*),
'_line' => qr($T{_line}$Opt\]),
@@ -2017,6 +2019,14 @@
my $remap;
my %map;
+ my $inv_func;
+ if($opt->{inventory}) {
+ my ($t, $c) = split /[.:]+/, $opt->{inventory};
+ if($db = database_exists_ref($t)) {
+ $inv_func = $db->field_accessor($c);
+ }
+ }
+
if($::Variable->{MV_OPTION_TABLE_MAP}) {
$remap = $::Variable->{MV_OPTION_TABLE_MAP};
$remap =~ s/^\s+//;
@@ -2077,6 +2087,13 @@
foreach $ref (@$ary) {
next unless $ref->[3];
+
+ # skip based on inventory if enabled
+ if($inv_func) {
+ my $oh = $inv_func->($ref->[0]);
+ next if $oh <= 0;
+ }
+
$i++;
# skip unless o_value
@@ -2146,6 +2163,13 @@
next unless $ref->[1];
# skip unless description
next unless $ref->[3];
+
+ # skip based on inventory if enabled
+ if($inv_func) {
+ my $oh = $inv_func->($ref->[0]);
+ next if $oh <= 0;
+ }
+
$ref->[3] =~ s/,/,/g;
$ref->[3] =~ s/=/=/g;
$price->{$ref->[0]} = $ref->[4];
@@ -4963,6 +4987,7 @@
$run =~ s:$B$QR{_code}:$code:ig;
$run =~ s:$B$QR{_description}:ed(product_description($code)):ige;
$run =~ s:$B$QR{_field}:ed(product_field($1, $code)):ige;
+ $run =~ s:$B$QR{_common}:ed(product_common($1, $code)):ige;
tag_labeled_data_row($code, \$run);
$run =~ s!$B$QR{_price}!
currency(product_price($code,$1), $2)!ige;
@@ -5102,6 +5127,7 @@
)!ge;
$run =~ s:$B$QR{_code}:$code:g;
$run =~ s:$B$QR{_field}:ed(item_field($item, $1) || $item->{$1}):ge;
+ $run =~ s:$B$QR{_common}:ed(item_common($item, $1) || $item->{$1}):ge;
$run =~ s:$B$QR{_description}:
ed(item_description($item) || $item->{description})
:ge;