tests are getting closer to working

This commit is contained in:
JT Smith 2008-02-26 16:52:21 +00:00
parent d207994e90
commit 449c3c26e0
4 changed files with 29 additions and 82 deletions

View file

@ -43,7 +43,7 @@ A reference to a subclass of WebGUI::Asset::Sku.
sub addItem {
my ($self, $sku) = @_;
croak "Need a SKU item." unless (defined $item && $item->isa("WebGUI::Asset::Sku"));
croak "Need a SKU item." unless (defined $sku && $sku->isa("WebGUI::Asset::Sku"));
my $item = WebGUI::Shop::CartItem->create( $self, $sku);
return $item;
}
@ -94,7 +94,7 @@ Removes all items from this cart.
sub empty {
my ($self) = @_;
foreach my $item = (@{$self->getItems}) {
foreach my $item (@{$self->getItems}) {
$item->remove;
}
}
@ -114,7 +114,7 @@ Any field returns the value of a field rather than the hash reference.
sub get {
my ($self, $name) = @_;
if (defined $name) {
return $self->properties->{$name};
return $properties{id $self}{$name};
}
my %copyOfHashRef = $properties{id $self};
return \%copyOfHashRef;
@ -169,12 +169,11 @@ The unique id of a cart to instanciate.
sub new {
my ($class, $session, $cartId) = @_;
croak "Need a session" unless (defined $session && $session->isa("WebGUI::Session");
croak "Need a session" unless (defined $session && $session->isa("WebGUI::Session"));
croak "Need a cartId" unless defined $cartId;
my $cart = $session->db->quickHashRef('select * from cart where cartId=?', [$cartId]);
croak "No cart with id of $cartId" if ($cart->{cartId} eq "");
bless my $self, $class;
register $self;
my $self = register $class;
my $id = id $self;
$session{ $id } = $session;
$properties{ $id } = $cart;
@ -204,9 +203,9 @@ The unique id for a shipping address attached to this cart.
sub update {
my ($self, $newProperties) = @_;
my $id = id $self;
$properties{$id}{couponId} = $newProperties->{couponId} || $self->properties->{couponId};
$properties{$id}{shippingAddressId} = $newProperties->{shippingAddressId} || $self->properties->{shippingAddressId};
$self->session->db->setRow("cart","cartId",$self->properties);
$properties{$id}{couponId} = $newProperties->{couponId} || $properties{$id}{couponId};
$properties{$id}{shippingAddressId} = $newProperties->{shippingAddressId} || $properties{$id}{shippingAddressId};
$self->session->db->setRow("cart","cartId",$properties{$id});
}

View file

@ -81,9 +81,9 @@ sub get {
my ($self, $name) = @_;
if (defined $name) {
if ($name eq "options") {
return JSON::from_json($self->properties->{$name});
return JSON::from_json($properties{id $self}{$name});
}
return $self->properties->{$name};
return $properties{id $self}{$name};
}
my %copyOfHashRef = $properties{id $self};
return \%copyOfHashRef;
@ -125,7 +125,7 @@ sub incrementQuantity {
croak "Cannot have that many in cart.";
}
$properties{$id}{quantity} += $quantity;
$cart->session->db->setRow("cartItems","itemId", $properties{$id});
$self->session->db->setRow("cartItems","itemId", $properties{$id});
}
@ -147,13 +147,12 @@ The unique id of the item to instanciate.
sub new {
my ($class, $cart, $itemId) = @_;
croak "Need a cart" unless (defined $cart && $session->isa("WebGUI::Shop::Cart");
croak "Need a cart" unless (defined $cart && $cart->isa("WebGUI::Shop::Cart"));
croak "Need an itemId" unless defined $itemId;
my $item = $cart->session->db->quickHashRef('select * from cart where itemId=?', [$itemId]);
croak "No item with id of $itemId" if ($item->{itemId} eq "");
croak "Item $itemId is not in this cart." if ($item->{cartId} ne $cart->getId);
bless my $self, $class;
register $self;
my $self = register $class;
my $id = id $self;
$cart{ $id } = $cart;
$properties{ $id } = $item;
@ -195,12 +194,12 @@ sub update {
$newProperties->{options} = $newProperties->{asset}->getOptions;
$newProperties->{assetId} = $newProperties->{asset}->getId;
}
$properties{$id}{assetId} = $newProperties->{assetId} || $self->properties->{assetId};
$properties{$id}{assetId} = $newProperties->{assetId} || $properties{$id}{assetId};
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
$properties{$id}{options} = JSON::to_json($newProperties->{options});
}
$properties{$id}{shippingAddressId} = $newProperties->{shippingAddressId} || $self->properties->{shippingAddressId};
$self->session->db->setRow("cart","cartId",$self->properties);
$properties{$id}{shippingAddressId} = $newProperties->{shippingAddressId} || $properties{$id}{shippingAddressId};
$self->session->db->setRow("cart","cartId",$properties{$id});
}