base cart UI is working
This commit is contained in:
parent
12d2ce6c16
commit
99f1fc5eb8
6 changed files with 32 additions and 23 deletions
|
|
@ -67,7 +67,7 @@ sub addToCart {
|
|||
my ($self, $options) = @_;
|
||||
$self->applyOptions($options);
|
||||
my $cart = WebGUI::Shop::Cart->create($self->session);
|
||||
my $cart->addItem($self);
|
||||
$cart->addItem($self);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ sub get {
|
|||
if (defined $name) {
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
my %copyOfHashRef = $properties{id $self};
|
||||
my %copyOfHashRef = %{$properties{id $self}};
|
||||
return \%copyOfHashRef;
|
||||
}
|
||||
|
||||
|
|
@ -249,6 +249,8 @@ Remove an item from the cart and then display the cart again.
|
|||
|
||||
sub www_removeItem {
|
||||
my $self = shift;
|
||||
my $item = WebGUI::Shop::CartItem->new($self, $self->session->form->get("itemId"));
|
||||
$item->remove;
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
|
|
@ -291,19 +293,20 @@ sub www_view {
|
|||
my @items = ();
|
||||
foreach my $item (@{$self->getItems}) {
|
||||
my $sku = $item->getSku;
|
||||
$sku->applyOptions($item->get("options"));
|
||||
my %properties = (
|
||||
%{$item->get},
|
||||
url => $sku->getUrl("shop=cart;method=viewItem;itemId=".$item->getId),
|
||||
quantityField => WebGUI::Form::integer($session, {name=>"quantity-".$item->getId, value=>$item->get("quantity")}),
|
||||
isUnique => ($sku->getMaxAllowedInCart == 1),
|
||||
isShippable => $sku->isShippingRequired,
|
||||
extendedPrice => sprintf("%.2f", ($properties{price} * $properties{quantity})),
|
||||
price => sprintf("%.2f", $properties{price}),
|
||||
extendedPrice => sprintf("%.2f", ($sku->getPrice * $item->get("quantity"))),
|
||||
price => sprintf("%.2f", $sku->getPrice),
|
||||
removeButton => WebGUI::Form::submit($session, {value=>$i18n->get("remove button"),
|
||||
onclick=>"this.form.method.value='removeItem';this.form.itemId.value='".$item->getId."';this.form.submit;"}),
|
||||
extras=>q|onclick="this.form.method.value='removeItem';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}),
|
||||
shippingAddress => "todo",
|
||||
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
||||
onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.itemId.value='".$item->getId."';this.form.submit;"}),
|
||||
extras=>q|onclick="this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}),
|
||||
);
|
||||
push(@items, \%properties);
|
||||
}
|
||||
|
|
@ -318,15 +321,15 @@ sub www_view {
|
|||
formFooter => WebGUI::Form::formFooter($session),
|
||||
updateButton => WebGUI::Form::submit($session, {value=>$i18n->get("update cart button")}),
|
||||
checkoutButton => WebGUI::Form::submit($session, {value=>$i18n->get("checkout button"),
|
||||
onclick=>"this.form.shop.value='pay';this.form.methodvalue='viewOptions';this.form.submit;"}),
|
||||
extras=>q|onclick="this.form.shop.value='pay';this.form.methodvalue='viewOptions';this.form.submit;"|}),
|
||||
continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"),
|
||||
onclick=>"this.form.method.value='continueShopping';this.form.submit;"}),
|
||||
extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;"|}),
|
||||
chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"),
|
||||
onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"}),
|
||||
extras=>q|onclick="this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"|}),
|
||||
shipppingAddress => "todo",
|
||||
shippingOptions => "todo",
|
||||
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
||||
onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"}),
|
||||
extras=>q|onclick="this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"|}),
|
||||
hasShippingAddress => "todo",
|
||||
couponField => WebGUI::Form::text($session, {name=>"couponCode", value=>"", size=>20}),
|
||||
couponDiscount => "todo",
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ sub get {
|
|||
}
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
my %copyOfHashRef = $properties{id $self};
|
||||
my %copyOfHashRef = %{$properties{id $self}};
|
||||
return \%copyOfHashRef;
|
||||
}
|
||||
|
||||
|
|
@ -143,16 +143,8 @@ If specified may increment quantity by more than one. Specify a negative number
|
|||
sub incrementQuantity {
|
||||
my ($self, $quantity) = @_;
|
||||
$quantity ||= 1;
|
||||
my $id = id $self;
|
||||
if ($self->get("quantity") + $quantity > $self->getSku->getMaxAllowedInCart) {
|
||||
WebGUI::Error::Shop::MaxOfItemInCartReached->throw(error=>"Cannot have that many of this item in cart.");
|
||||
}
|
||||
if ($self->get("quantity") + $quantity <= 0) {
|
||||
return $self->remove;
|
||||
}
|
||||
$properties{$id}{quantity} += $quantity;
|
||||
$self->cart->session->db->setRow("cartItems","itemId", $properties{$id});
|
||||
return $properties{$id}{quantity};
|
||||
$self->setQuantity($quantity + $self->get("quantity"));
|
||||
return $self->get("quantity");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -224,7 +216,15 @@ The number to set the quantity to. Zero or less will remove the item from cart.
|
|||
|
||||
sub setQuantity {
|
||||
my ($self, $quantity) = @_;
|
||||
return $self->incrementQuantity($quantity - $self->get("quantity"));
|
||||
my $id = id $self;
|
||||
if ($quantity > $self->getSku->getMaxAllowedInCart) {
|
||||
WebGUI::Error::Shop::MaxOfItemInCartReached->throw(error=>"Cannot have that many of this item in cart.");
|
||||
}
|
||||
if ($quantity <= 0) {
|
||||
return $self->remove;
|
||||
}
|
||||
$properties{$id}{quantity} = $quantity;
|
||||
$self->cart->session->db->setRow("cartItems","itemId", $properties{$id});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@ package WebGUI::i18n::English::Shop;
|
|||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'too many of this item' => {
|
||||
message => q|Can't add that many %s to your cart.|,
|
||||
lastUpdated => 0,
|
||||
context => q|an error message|
|
||||
},
|
||||
|
||||
'subtotal' => {
|
||||
message => q|Subtotal|,
|
||||
lastUpdated => 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue