diff --git a/designdocs/cart.pod b/designdocs/cart.pod index 752558d10..c093187ff 100644 --- a/designdocs/cart.pod +++ b/designdocs/cart.pod @@ -28,9 +28,6 @@ Adds an item to the cart. Returns the number of items now in the cart. param: asset - the asset object to be added already configured as needed -param: quantity - the number of this item that the -user wants - =head3 create Creates a new cart object if there's not one already attached to the @@ -93,6 +90,7 @@ The following fields are needed to construct this object's table called "cartItems". Field Schema Description + itemId guid primary key cartId guid The unique id for this cart. assetId guid The assetId for this item. options medium Text A json serialized hashref of any configuration data associated with this item so that it can be edited or whatnot. @@ -108,14 +106,11 @@ class. Creates a new cart item object. Returns a reference to the object. -param: session - a reference to the current session - -param: cartId - the unique id of the cart +param: cart - a reference to a cart param: asset - A reference to the asset you wish to create. -param: quantity - the quantity of sku to purchase =head3 get @@ -128,6 +123,12 @@ rather than the hash reference Returns an instanciated WebGUI::Asset::Sku object for this cart item. +=head3 incrementQuantity + +Increment the amount in cart by one. + +param: quantity - up it by more than one + =head3 new Instanciates a cart item based upon a cartId and assetId. diff --git a/docs/upgrades/upgrade_7.5.2-7.5.3.pl b/docs/upgrades/upgrade_7.5.2-7.5.3.pl index 300461f8d..a03b244cf 100644 --- a/docs/upgrades/upgrade_7.5.2-7.5.3.pl +++ b/docs/upgrades/upgrade_7.5.2-7.5.3.pl @@ -61,6 +61,7 @@ sub migrateToNewCart { index sessionId (sessionId) )"); $session->db->write("create table cartItems ( + itemId varchar(22) binary not null primary key, cartId varchar(22) binary not null, assetId varchar(22) binary not null, options mediumtext, diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 3a30ec7fd..784e1a0f7 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -67,12 +67,7 @@ sub create { return $class->new($session, $cartId) if (defined $cartId); my $cartId = $session->id->generate; $session->db->write('insert into cart (cartId, sessionId) values (?,?)', [$cartId, $session->getId]); - bless my $self, $class; - register $self; - my $id = id $self; - $session{ $id } = $session; - $properties{ $id } = {cartId=>$cartId, sessionId=>$session->getId}; - return $self; + return $class->new($session, $cartId); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Shop/CartItem.pm b/lib/WebGUI/Shop/CartItem.pm index dd7b27f7f..0176dbab7 100644 --- a/lib/WebGUI/Shop/CartItem.pm +++ b/lib/WebGUI/Shop/CartItem.pm @@ -121,24 +121,14 @@ sub incrementQuantity { my ($self, $quantity) = @_; $quantity ||= 1; my $id = $self; + if ($self->get("quantity") + $quantity > $self->getSku->getMaxAllowedInCart) { + croak "Cannot have that many in cart."; + } $properties{$id}{quantity} += $quantity; $cart->session->db->setRow("cartItems","itemId", $properties{$id}); } -#------------------------------------------------------------------- - -=head2 isAtMaxQuantity ( ) - -Returns a boolean indicating whether the item is already at max quantity in the cart. - -=cut - -sub isAtMaxQuantity { - my ($self) = @_; -} - - #------------------------------------------------------------------- =head2 new ( session, cart, itemId )