[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Cart programming question
Quoting Steffen Dettmer (steffen@dett.de):
> Hi,
>
> ... and my loved customers have a requirement.
> There are multiple (shop-) users organized in groups. Now it's
> 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.
>
> Here I see two possibilities: I could make a page that loads the
> cart value from userdb from the other user (A), parse it in some
> way, and add the selected cart to the value in userdb for this
> user (B). The second possibility: I could add some new button
> which stores the contents of "uneval $Carts->{'main'}" into a
> database table (I would use my groups-table I think).
>
> $cart_string = uneval $Carts->{'main'};
> query "insert into group_carts ( content, group_id )
> VALUES ( $cart_string, $group_id )";
> # (or some Data-Tag instead of query)
>
> So far this shouldn't be a problem. For loading/getting, I think
> I just need somethink like
>
>
> $db_field_content = query "select content from group_carts
> where group_id = $group_id
> and cart_id = $cart_to_load";
> # (or some Data-Tag instead of query)
> $Carts->{'main'} = eval $db_field_content;
>
> Now my questions:
>
> - Is there a better third way to do it?
No, not that I know of.
>
> - 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.
>
> - 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]
>
> - I never wrote into a table from IC. Do I have to expect
> problems here (catalog.cfg permissions or similar)?
>
Not unless you have WRITE_CONTROL set, in which case you need
to [flag type=write table=foo].
> - Should I use another approach by editing UserDB.pm and
> modify get_cart (and others) in a way, that they handle
> group-assigned carts on this level?
Probably not the best way for a one-off.
>
> I don't have the right idea, since the cart functionality is part
> of the IC core and cannot be modified easily, so I would prefere
> method 2 (saving a uneval $Carts->{'main'}, and for reloading it
> doing a eval $field_content).
>
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
}
sub group_set_cart {
## Some code
}
package Vend::Interpolate;
sub {
# Normal usertag stuff
}
EOR
Now [userdb function=group_get_cart ....] will do what you want....
--
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH 45013
phone +1.513.523.7621 <mheins@redhat.com>
For a successful technology, reality must take precedence over public
relations, for Nature cannot be fooled. -- Dick Feynman