- Added Cashier/Point of Sale mode for the Shop.
- Added the notion of a default address to the Shop's address book.
This commit is contained in:
parent
47419b9602
commit
16bd779fd4
9 changed files with 263 additions and 24 deletions
|
|
@ -13,6 +13,7 @@ use WebGUI::Shop::CartItem;
|
|||
use WebGUI::Shop::Credit;
|
||||
use WebGUI::Shop::Ship;
|
||||
use WebGUI::Shop::Tax;
|
||||
use WebGUI::User;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ sub calculateShopCreditDeduction {
|
|||
unless (defined $total) {
|
||||
$total = $self->calculateTotal
|
||||
}
|
||||
return $self->formatCurrency(WebGUI::Shop::Credit->new($self->session)->calculateDeduction($total));
|
||||
return $self->formatCurrency(WebGUI::Shop::Credit->new($self->session, $self->get('posUserId'))->calculateDeduction($total));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -344,6 +345,22 @@ sub getItemsByAssetId {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getPosUser
|
||||
|
||||
Returns the userId of the user making a purchase. If there is a cashier and the cashier has specified a user, then that user will be returned. Otherwise, if it's a direct sale then $session->user will be returned.
|
||||
|
||||
=cut
|
||||
|
||||
sub getPosUser {
|
||||
my $self = shift;
|
||||
if ($self->get('posUserId') ne "") {
|
||||
return WebGUI::User->new($self->session, $self->get('posUserId'));
|
||||
}
|
||||
return $self->session->user;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getShipper ()
|
||||
|
||||
Returns the WebGUI::Shop::ShipDriver object that is attached to this cart for shipping.
|
||||
|
|
@ -365,7 +382,13 @@ Returns the WebGUI::Shop::Address object that is attached to this cart for shipp
|
|||
|
||||
sub getShippingAddress {
|
||||
my $self = shift;
|
||||
return $self->getAddressBook->getAddress($self->get("shippingAddressId"));
|
||||
my $book = $self->getAddressBook;
|
||||
if ($self->get("shippingAddressId")) {
|
||||
return $book->getAddress($self->get("shippingAddressId"));
|
||||
}
|
||||
my $address = $book->getDefaultAddress;
|
||||
$self->update({shippingAddressId=>$address->getId});
|
||||
return $address;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -533,6 +556,10 @@ The unique id for a shipping address attached to this cart.
|
|||
|
||||
The unique id of the configured shipping driver that will be used to ship these goods.
|
||||
|
||||
=head4 posUserId
|
||||
|
||||
The ID of a user being checked out, if they're being checked out by a cashier.
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
|
|
@ -541,7 +568,7 @@ sub update {
|
|||
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
|
||||
}
|
||||
my $id = id $self;
|
||||
foreach my $field (qw(shippingAddressId shipperId)) {
|
||||
foreach my $field (qw(shippingAddressId posUserId shipperId)) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->session->db->setRow("cart","cartId",$properties{$id});
|
||||
|
|
@ -616,6 +643,31 @@ sub www_continueShopping {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_lookupPosUser ( )
|
||||
|
||||
Adds a Point of Sale user to the cart.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_lookupPosUser {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $email = $session->form->get('posEmail','email');
|
||||
my $user = WebGUI::User->newByEmail($session, $email);
|
||||
unless (defined $user) {
|
||||
$user = WebGUI::User->newByUsername($session, $email);
|
||||
unless (defined $user) {
|
||||
$user = WebGUI::User->new($session, "new");
|
||||
$user->username($email);
|
||||
$user->profileField('email', $email);
|
||||
}
|
||||
}
|
||||
$self->update({posUserId=>$user->userId});
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_removeItem ( )
|
||||
|
||||
Remove an item from the cart and then display the cart again.
|
||||
|
|
@ -756,7 +808,7 @@ sub www_view {
|
|||
my $address = eval { $self->getShippingAddress };
|
||||
if (WebGUI::Error->caught("WebGUI::Error::ObjectNotFound")) {
|
||||
# choose another address cuz we've got a problem
|
||||
$self->update({shippingAddressId=>""});
|
||||
$self->update({shippingAddressId=>''});
|
||||
}
|
||||
|
||||
# if there is no shipping address we can't check out
|
||||
|
|
@ -782,13 +834,22 @@ sub www_view {
|
|||
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||
}
|
||||
|
||||
# POS variables
|
||||
$var{isCashier} = WebGUI::Shop::Admin->new($session)->isCashier;
|
||||
$var{posLookupForm} = WebGUI::Form::email($session, {name=>"posEmail"})
|
||||
.WebGUI::Form::submit($session, {value=>$i18n->get('search for email'),
|
||||
extras=>q|onclick="this.form.method.value='lookupPosUser';this.form.submit;"|});
|
||||
my $posUser = $self->getPosUser;
|
||||
$var{posUsername} = $posUser->username;
|
||||
$var{posUserId} = $posUser->userId;
|
||||
|
||||
# calculate price adjusted for in-store credit
|
||||
$var{totalPrice} = $var{subtotalPrice} + $var{shippingPrice} + $var{tax};
|
||||
my $credit = WebGUI::Shop::Credit->new($session);
|
||||
my $credit = WebGUI::Shop::Credit->new($session, $posUser->userId);
|
||||
$var{inShopCreditAvailable} = $credit->getSum;
|
||||
$var{inShopCreditDeduction} = $credit->calculateDeduction($var{totalPrice});
|
||||
$var{totalPrice} = $self->formatCurrency($var{totalPrice} + $var{inShopCreditDeduction});
|
||||
|
||||
$var{totalPrice} = $self->formatCurrency($var{totalPrice} + $var{inShopCreditDeduction});
|
||||
|
||||
# render the cart
|
||||
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId"));
|
||||
return $session->style->userStyle($template->process(\%var));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue