started adding cart UI
This commit is contained in:
parent
152e96f695
commit
3cb0ccd0e2
5 changed files with 165 additions and 4 deletions
|
|
@ -105,6 +105,7 @@ sub migrateToNewCart {
|
|||
index cartId_assetId (cartId,assetId)
|
||||
)");
|
||||
$session->db->write("drop table shoppingCart");
|
||||
$session->db->write("insert into settings values ('shopCartTemplateId','HKwB9Y7jKKfpL4bkQEmX0w')");
|
||||
}
|
||||
|
||||
#-------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -471,6 +471,7 @@
|
|||
"WebGUI::Content::Maintenance",
|
||||
"WebGUI::Content::Operation",
|
||||
"WebGUI::Content::Setup",
|
||||
"WebGUI::Content::Shop",
|
||||
"WebGUI::Content::Asset",
|
||||
"WebGUI::Content::NotFound"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ sub handler {
|
|||
my ($session) = @_;
|
||||
my $output = undef;
|
||||
my $function = "www_".$session->form->get("shop");
|
||||
if ($function ne "www_" && __PACKAGE__->can($function)) {
|
||||
$output = &$function($session);
|
||||
if ($function ne "www_" && (my $sub = __PACKAGE__->can($function))) {
|
||||
$output = $sub->($session);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
@ -69,9 +69,9 @@ Hand off to the cart.
|
|||
sub www_cart {
|
||||
my $session = shift;
|
||||
my $output = undef;
|
||||
my $method = "www_".$session->form->get("method");
|
||||
my $method = "www_". ( $session->form->get("method") || "view");
|
||||
my $cart = WebGUI::Shop::Cart->create($session);
|
||||
if ($method ne "www_" && $cart->can($method)) {
|
||||
if ($cart->can($method)) {
|
||||
$output = $cart->$method();
|
||||
}
|
||||
return $output;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,13 @@ package WebGUI::Shop::Cart;
|
|||
use strict;
|
||||
|
||||
use Class::InsideOut qw{ :std };
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Shop::CartItem;
|
||||
# use WebGUI::Shop::Coupon;
|
||||
use WebGUI::Shop::Ship;
|
||||
use WebGUI::Shop::Tax;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -220,5 +225,127 @@ sub update {
|
|||
$self->session->db->setRow("cart","cartId",$properties{$id});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_continueShopping ( )
|
||||
|
||||
Update the cart and the return the user back to the asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_continueShopping {
|
||||
my $self = shift;
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_removeItem ( )
|
||||
|
||||
Remove an item from the cart and then display the cart again.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_removeItem {
|
||||
my $self = shift;
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_update ( )
|
||||
|
||||
Updates the cart totals and then displays the cart again.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_update {
|
||||
my $self = shift;
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_view ( )
|
||||
|
||||
Displays the shopping cart.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $url = $session->url;
|
||||
my $i18n = WebGUI::International->new($session, "Shop");
|
||||
my @items = ();
|
||||
foreach my $item (@{$self->getItems}) {
|
||||
my $sku = $item->getSku;
|
||||
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->isShippable,
|
||||
extendedPrice => sprintf("%.2f", ($properties{price} * $properties{quantity})),
|
||||
price => sprintf("%.2f", $properties{price}),
|
||||
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;"}),
|
||||
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;"}),
|
||||
);
|
||||
push(@items, \%properties);
|
||||
}
|
||||
my %var = (
|
||||
%{$self->get},
|
||||
items => \@items,
|
||||
formHeader => WebGUI::Form::formHeader($session)
|
||||
. WebGUI::Form::hidden($session, {name=>"shop", value=>"cart"})
|
||||
. WebGUI::Form::hidden($session, {name=>"method", value=>"update"})
|
||||
. WebGUI::Form::hidden($session, {name=>"itemId", value=>""}),
|
||||
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;"}),
|
||||
continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"),
|
||||
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;"}),
|
||||
shipppingAddress => "todo",
|
||||
shippingOptions => "todo",
|
||||
changeShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("change shipping button"),
|
||||
onclick=>"this.form.shop.value='ship';this.form.method.value='viewAddressbook';this.form.submit;"}),
|
||||
hasShippingAddress => "todo",
|
||||
couponField => WebGUI::Form::text($session, {name=>"couponCode", value=>""}),
|
||||
couponDiscount => "todo",
|
||||
totalPrice => "todo",
|
||||
tax => "todo",
|
||||
subtotalPrice => "todo",
|
||||
);
|
||||
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId"));
|
||||
$template->prepare;
|
||||
return $template->process(\%var);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_viewItem ( )
|
||||
|
||||
Displays the configured item.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewItem {
|
||||
my $self = shift;
|
||||
my $itemId = $self->session->form->get("itemId");
|
||||
my $item = eval { WebGUI::Shop::CartItem->new($self, $itemId) };
|
||||
if (WebGUI::Error->caught()) {
|
||||
return $self->www_view;
|
||||
}
|
||||
my $sku = $item->getSku;
|
||||
$sku->applyOptions($item->get("options"));
|
||||
return $sku->www_view;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
32
lib/WebGUI/i18n/English/Shop.pm
Normal file
32
lib/WebGUI/i18n/English/Shop.pm
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package WebGUI::i18n::English::Shop;
|
||||
|
||||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'remove button' => {
|
||||
message => q|Remove|,
|
||||
lastUpdated => 0,
|
||||
context => q|a button a user clicks on to remove an item from the cart|
|
||||
},
|
||||
|
||||
'update button' => {
|
||||
message => q|Update Cart|,
|
||||
lastUpdated => 0,
|
||||
context => q|a button the user clicks on to apply changes to a cart|
|
||||
},
|
||||
|
||||
'continue shopping button' => {
|
||||
message => q|Continue Shopping|,
|
||||
lastUpdated => 0,
|
||||
context => q|a button the user clicks on to go back to shopping after viewing the cart|
|
||||
},
|
||||
|
||||
'ship to button' => {
|
||||
message => q|Ship To|,
|
||||
lastUpdated => 0,
|
||||
context => q|a button the user clicks on to set shipping information|
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue