[ic] Cart programming question

Steffen Dettmer interchange-users@interchange.redhat.com
Sat Mar 16 14:37:00 2002


* Mike Heins wrote on Thu, Feb 14, 2002 at 14:32 -0500:
> Quoting Steffen Dettmer (steffen@dett.de):
[...]
> > possible that a user A saves a cart or a recurring order. Now it
> > should made possible that a customer B (which is in the same
> > group as user A) can get the carts A saved.
 [...] 
> > 	$Carts->{'main'} = eval $db_field_content;

Thank you for your helpful response! I reply so lately since we
had trouble with the shop layout designers (it just resulted in
completly screwed pages... hum, luckly we used CVS for the
pages!).

I wasn't successful in the most important detail: eval the
returned string to become a array ref to become assigned to the
cart. I just was able to assign the cart the scalar string.
Details follow.

Please give me another hint or pointer to the right direction!

 [...] 
> > 	- Would method 2 work if I program a global user tag for
> > 	  it (inside pages or catalog.cfg "eval" wouldn't work
> > 	  beacuse of Safe, is this correct)?
> 
> Yes, it would work fine. I have done it. 

oki, I'll try it tomorrow or so.

> > 	- Is there a better way to "reload" this cart than with
> > 	  eval?
> 
> If you want to use embedded Perl with safe, it is OK to do
> 
> [try]
>     [calc]
> 	$Carts->{main} = <<'EOF';
> [data table=group_carts column=content key=cart_id]
> EOF
>     [/calc]
> [/try]
> 
> [catch]
> 	Eval error in cart.
> [/catch]

This is not working! The data tag gets evaluated, returning a string
(!) that *looks* like a cart. The example assigns that string to
the cart (which was used to be a array *ref*, now it's a *scalar*!)
and IC reports an error ("cannot use string as ref while in
strict refs" or similar, you know). I need someting like:

$Carts->{main} = eval($Tag->data(...));

Is that really possible in a page by ITL? Wouldn't this be a
security risk allowing eval("rm -rf /");?

Well, I decided to not try to extend userdb, since I don't think
this is the right place. Instead, I decided to make a simple
usertag group_cart_fetch (param cart_id). I started implementing
it in a [per] tag, since otherwise I had to restart on every typo
in the perl code :) 

Well, most things work (experimental), except the
eval(cart_string) (or ready->reval($cart) as written in
UserDB.pm). I have a string only in my cart, not a array ref to a
hash ref. I wasn't even able to do a working version of

[perl]
        $string = uneval $Carts->{main};
        $Tag->tmp("cart_string", $string);
        return "Got it.";
[/perl]

[calc]
$Carts->{main} = <<'EOF';
[scratch cart_string]
EOF
[/calc]

But cart contains a scalar (a string) and not a array ref.



Please give me another hint, I just don't get this detail
working!



Ohh, and BTW: the try / catch is really cool. If I do a throw
(i.e. a "die" or return undef ?) in any [perl], this catch works?
I didn't found anything about "throw" or "raise" in the docs,
maybe someone could point me?

> Au contraire. It is easy to add functionality to UserDB.pm. Consider:
> 
> UserTag  my-cart-stuff  Routine <<EOR
> 
> package UserDB;
> 
> sub group_get_cart {
> 	## Some code
> }

Ohh, the userdb functions are determined dynamically? Yes, would
be possible, it's Perl :) Well, for use C++ people sometimes such
things look like black magic :)

> package Vend::Interpolate;
> 
> sub {
> 	# Normal usertag stuff
> }
> EOR

I do not understand. What should that do? But I think I don't
need it, since I started a user tag. But thank you for the help
anyway!

oki,

Steffen

-- 
Dieses Schreiben wurde maschinell erstellt,
es trägt daher weder Unterschrift noch Siegel.