[ic] using scratch variables with bar_link simple searches

Doug Alcorn interchange-users@interchange.redhat.com
Fri Mar 1 17:01:02 2002


--=-=-=

I've made this simple little patch for catalog_before that makes the
bar_link subroutine evaluate scratch variables in the simple
searches.  Here's how I use it.  I have a catalog selling cell phone
accessories.  I have general categories for things like headsets,
batteries, and face-plates.  I want to have those categories on the
left hand side for navigation.  However, I want the searches generated
by clicking on those links to only show parts that are compatible with
the shopper's phone.  On the results page I have a little test for the
value of a scratch variable.  If it's null, the customer gets bounced
to a page where they can select their phone.  This selection gets
saved in the scratch variable.  From that point on, the left hand side
navigation links will use that scratch variable as a search criteria.

The bar_link routine simply takes column=value pairs separated with
either commas or newlines from the selector field of the cat table.
This patch looks at the value of each pair and determines if it is
"[scratch foobar]".  If so, it checks the $Scratch hash to see if
$Scratch->{foobar} key is defined.  If not, the entire name=value pair
is ignored.  If so, it uses that value in the search.  So, if you
never use the column=[scratch foobar] format no harm is done.  If you
do use column=[scratch foobar] and the foobar variable is never set,
no harm done.  Only if the foobar variable is set will the search be
filtered.  

Anyway, I hope someone finds this useful and Mike sees fit to apply
this patch to CVS (that would at least save me the trouble of having
to apply this patch each time ;)


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=catalog_before.patch
Content-Description: make bar_link use scratch variables for simple searches

--- /usr/lib/interchange/catalog_before.cfg	Sat Dec  1 17:21:24 2001
+++ catalog_before.cfg	Sat Feb 23 15:00:33 2002
@@ -129,6 +129,11 @@
 			push @out, "co=yes";
 			for(@items) {
 				my ($col, $string) = split /\s*=\s*/;
+				if ($string =~ /\[scratch (\w+)\]/) {
+					my $variable = $1;
+					next unless ($Scratch->{$variable});
+					$string = $Scratch->{$variable};
+				}
 				push @out, "sf=$col";
 				push @out, "se=$string";
 			}

--=-=-=


-- 
 (__) Doug Alcorn (mailto:doug@lathi.net http://www.lathi.net)
 oo / PGP 02B3 1E26 BCF2 9AAF 93F1  61D7 450C B264 3E63 D543
 |_/  If you're a capitalist and you have the best goods and they're
      free, you don't have to proselytize, you just have to wait. 

--=-=-=--