changed the name of getCartBySession to newBySession

created the CartItemCount and MiniCart macros
added help for MinCart, Cart, Address Book, and Edit Address templates
This commit is contained in:
JT Smith 2008-05-24 23:27:30 +00:00
parent e3061a1606
commit 57c85fde5a
18 changed files with 895 additions and 43 deletions

View file

@ -0,0 +1,44 @@
package WebGUI::Macro::CartItemCount;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Shop::Cart;
=head1 NAME
Package WebGUI::Macro::CartItemCount
=head1 DESCRIPTION
Returns an integer of the number of items currently in the cart.
=head2 process( $session )
Renders the macro.
=cut
#-------------------------------------------------------------------
sub process {
my ($session) = @_;
my $cart = WebGUI::Shop::Cart->newBySession($session);
my $count = 0;
foreach my $item (@{$cart->getItems}) {
$count += $item->get('quantity');
}
return $count;
}
1;

View file

@ -0,0 +1,68 @@
package WebGUI::Macro::MiniCart;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Asset::Template;
use WebGUI::Shop::Cart;
=head1 NAME
Package WebGUI::Macro::MiniCart
=head1 DESCRIPTION
Displays a miniature view of the shopping cart.
=head2 process( $session, [templateId])
Renders the macro.
=head3 templateId
Pass in a template id other than the default.
=cut
#-------------------------------------------------------------------
sub process {
my ($session, $templateId) = @_;
my $cart = WebGUI::Shop::Cart->newBySession($session);
my @items = ();
my $totalItems = 0;
my $totalPrice = 0;
foreach my $item (@{$cart->getItems}) {
my $sku = $item->getSku;
my $price = $sku->getPrice;
my $quantity = $item->get('quantity');
push @items, {
name => $item->get('configuredTitle'),
quantity => $quantity,
price => $price,
url => $sku->getUrl('shop=cart;method=viewItem;itemId='.$item->getId),
};
$totalItems += $quantity;
$totalPrice += $quantity * $price;
}
my %var = (
items => \@items,
totalPrice => sprintf(".2f",$totalPrice),
totalItems => $totalItems,
);
my $template = WebGUI::Asset::Template->new($session, $templateId || 'EBlxJpZQ9o-8VBOaGQbChA');
return $template->process(\%var);
}
1;

View file

@ -27,7 +27,7 @@ Renders the macro.
=head3 linktext
Defaults to "View Cart".
Defaults to "View Cart". "linkonly" will return only the URL to the cart.
=cut
@ -35,10 +35,16 @@ Defaults to "View Cart".
#-------------------------------------------------------------------
sub process {
my ($session, $text) = @_;
unless ($text) {
my $url = $session->url->page("shop=cart");
if ($text eq "linkonly") {
return $url;
}
elsif ($text) {
# us text specified
}
else {
$text = WebGUI::International->new($session,"Shop")->get("view cart");
}
my $url = $session->url->page("shop=cart");
return '<a href="'.$url.'"><img src="'.$session->url->extras('/macro/ViewCart/cart.gif').'" alt="'.$text.'" style="border: 0px;vertical-align: middle;" /></a> <a href="'.$url.'">'.$text.'</a>';
}