added getCartBySession()
This commit is contained in:
parent
d47d2f2a9c
commit
7c184b26c3
4 changed files with 22 additions and 6 deletions
|
|
@ -109,7 +109,7 @@ sub www_cart {
|
|||
my $session = shift;
|
||||
my $output = undef;
|
||||
my $method = "www_". ( $session->form->get("method") || "view");
|
||||
my $cart = WebGUI::Shop::Cart->create($session);
|
||||
my $cart = WebGUI::Shop::Cart->getCartBySession($session);
|
||||
if ($cart->can($method)) {
|
||||
$output = $cart->$method();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,9 +92,7 @@ sub create {
|
|||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $cartId = $session->db->quickScalar("select cartId from cart where sessionId=?",[$session->getId]);
|
||||
return $class->new($session, $cartId) if (defined $cartId);
|
||||
$cartId = $session->id->generate;
|
||||
my $cartId = $session->id->generate;
|
||||
$session->db->write('insert into cart (cartId, sessionId) values (?,?)', [$cartId, $session->getId]);
|
||||
return $class->new($session, $cartId);
|
||||
}
|
||||
|
|
@ -183,6 +181,24 @@ sub getAddressBook {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getCartBySession ()
|
||||
|
||||
Class method that figures out if the user has a cart in their session. If they do it returns it. If they don't it creates it and returns it.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCartBySession {
|
||||
my ($class, $session) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $cartId = $session->db->quickScalar("select cartId from cart where sessionId=?",[$session->getId]);
|
||||
return $class->new($session, $cartId) if (defined $cartId);
|
||||
return $class->create($session);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id for this cart.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue