diff --git a/docs/upgrades/packages-7.5.21/default-shopping-cart-template.wgpkg b/docs/upgrades/packages-7.5.21/default-shopping-cart-template.wgpkg new file mode 100644 index 000000000..3aa8050ae Binary files /dev/null and b/docs/upgrades/packages-7.5.21/default-shopping-cart-template.wgpkg differ diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index b933b5583..a846ba02a 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -694,9 +694,21 @@ sub www_view { } |); + + my @items = @{$self->getItems}; + if(scalar(@items) < 1) { + # there are no items in the cart, return a message to the template + my %var = ( + message => $i18n->get('empty cart') + ); + + # render the cart + my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId")); + return $session->style->userStyle($template->process(\%var)); + } # generate template variables for the items in the cart - foreach my $item (@{$self->getItems}) { + foreach my $item (@items) { my $sku = $item->getSku; $sku->applyOptions($item->get("options")); my %properties = ( diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index 962b07288..cbb95960c 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -873,6 +873,13 @@ our $I18N = { context => q|a button the user clicks on to go back to shopping after viewing the cart| }, + 'empty cart' => { + message => q|There are no items currently in your cart.|, + lastUpdated => 0, + context => q|a message to the user that the cart is empty| + }, + + 'shop' => { message => q|Shop|, lastUpdated => 0, diff --git a/t/Shop/Cart.t b/t/Shop/Cart.t index 56ef3a80f..472f10728 100644 --- a/t/Shop/Cart.t +++ b/t/Shop/Cart.t @@ -27,7 +27,7 @@ use WebGUI::TestException; #---------------------------------------------------------------------------- # Init my $session = WebGUI::Test->session; - +my $i18n = WebGUI::International->new($session, "Shop"); #---------------------------------------------------------------------------- # Tests @@ -52,6 +52,9 @@ my $cart = WebGUI::Shop::Cart->newBySession($session); isa_ok($cart, "WebGUI::Shop::Cart"); isa_ok($cart->session, "WebGUI::Session"); +my $message = $i18n->get('empty cart') . "\n"; +like($cart->www_view, qr/There are no items currently in your cart./, 'Display empty cart message'); + my $root = WebGUI::Asset->getRoot($session); my $product = $root->addChild({ className=>"WebGUI::Asset::Sku::Donation",