Merge remote branch 'upstream/WebGUI8' into 8-merge
Conflicts: docs/gotcha.txt docs/previousVersion.sql lib/WebGUI/Asset/Wobject/GalleryAlbum.pm lib/WebGUI/Asset/Wobject/Navigation.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/Config.pm lib/WebGUI/Form/Template.pm lib/WebGUI/Group.pm lib/WebGUI/VersionTag.pm lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm t/AdSpace.t t/Asset/AssetExportHtml.t t/Asset/AssetLineage.t t/Asset/Story.t t/Asset/Template/HTMLTemplateExpr.t t/Asset/Wobject/Gallery/00base.t t/Asset/Wobject/GalleryAlbum/00base.t t/Asset/Wobject/GalleryAlbum/ajax.t t/Asset/Wobject/InOutBoard.t t/Asset/Wobject/StoryArchive.t t/Asset/Wobject/Survey/ExpressionEngine.t t/Asset/Wobject/Survey/Reports.t t/AssetAspect/RssFeed.t t/Auth/mech.t t/Group.t t/Mail/Send.t t/Operation/AdSpace.t t/Session/ErrorHandler.t t/Session/Scratch.t t/Session/Url.t t/Shop/Cart.t t/Shop/Pay.t t/Shop/Ship.t t/Shop/ShipDriver.t t/Shop/TaxDriver/Generic.t t/Shop/Vendor.t t/VersionTag.t t/lib/WebGUI/Test.pm
This commit is contained in:
commit
708b47d73c
165 changed files with 3199 additions and 5718 deletions
|
|
@ -15,7 +15,85 @@ package WebGUI::Shop::Address;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use Class::InsideOut qw{ :std };
|
||||
use Moose;
|
||||
use WebGUI::Definition;
|
||||
|
||||
property label => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property firstName => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property lastName => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property address1 => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property address2 => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property address3 => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property city => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property state => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property code => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property country => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property phoneNumber => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property email => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property organization => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property "addressBookId" => (
|
||||
noFormPost => 1,
|
||||
required => 1,
|
||||
);
|
||||
|
||||
has [ qw/addressId addressBook/] => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
use Scalar::Util qw/blessed/;
|
||||
use WebGUI::Exception::Shop;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -39,166 +117,30 @@ These subroutines are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
readonly addressBook => my %addressBook;
|
||||
private properties => my %properties;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addressBook ( )
|
||||
=head2 new ( $book, $addressId )
|
||||
|
||||
Returns a reference to the Address Book.
|
||||
Constructor. Instanciates an address based upon an addressId.
|
||||
|
||||
=cut
|
||||
=head2 new ( $book, $properties )
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
Constructor. Builds a new, default address.
|
||||
|
||||
=head2 create ( addressBook, address)
|
||||
=head2 new ( $properties )
|
||||
|
||||
Constructor. Adds an address to an address book. Returns a reference to the address.
|
||||
Constructor. Builds a new, default address book object in Moose style with default properties set by $properties. This does not
|
||||
persist them to the database automatically. This needs to be done via $self->write.
|
||||
|
||||
=head3 addressBook
|
||||
=head3 $addressBook
|
||||
|
||||
A reference to a WebGUI::Shop::AddressBook object.
|
||||
A reference to an addressBook object
|
||||
|
||||
=head3 address
|
||||
=head3 $addressId
|
||||
|
||||
A hash reference containing the properties to set in the address.
|
||||
The unique id of an address to instanciate.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my ($class, $book, $addressData) = @_;
|
||||
unless (defined $book && $book->isa("WebGUI::Shop::AddressBook")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Shop::AddressBook", got=>(ref $book), error=>"Need an address book.", param=>$book);
|
||||
}
|
||||
unless (defined $addressData && ref $addressData eq "HASH") {
|
||||
WebGUI::Error::InvalidParam->throw(param=>$addressData, error=>"Need a hash reference.");
|
||||
}
|
||||
my $id = $book->session->db->setRow("address","addressId", {addressId=>"new", addressBookId=>$book->getId});
|
||||
my $address = $class->new($book, $id);
|
||||
$address->update($addressData);
|
||||
return $address;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 delete ( )
|
||||
|
||||
Removes this address from the book.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
$self->addressBook->session->db->deleteRow("address","addressId",$self->getId);
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( [ property ] )
|
||||
|
||||
Returns a duplicated hash reference of this object’s data.
|
||||
|
||||
=head3 property
|
||||
|
||||
Any field − returns the value of a field rather than the hash reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my ($self, $name) = @_;
|
||||
if (defined $name) {
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
my %copyOfHashRef = %{$properties{id $self}};
|
||||
return \%copyOfHashRef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getHtmlFormatted ()
|
||||
|
||||
Returns an HTML formatted address for display.
|
||||
|
||||
=cut
|
||||
|
||||
sub getHtmlFormatted {
|
||||
my $self = shift;
|
||||
my $address = $self->get("firstName"). " " .$self->get("lastName") . "<br />";
|
||||
$address .= $self->get("organization") . "<br />" if ($self->get("organization") ne "");
|
||||
$address .= $self->get("address1") . "<br />";
|
||||
$address .= $self->get("address2") . "<br />" if ($self->get("address2") ne "");
|
||||
$address .= $self->get("address3") . "<br />" if ($self->get("address3") ne "");
|
||||
$address .= $self->get("city") . ", ";
|
||||
$address .= $self->get("state") . " " if ($self->get("state") ne "");
|
||||
$address .= $self->get("code") if ($self->get("code") ne "");
|
||||
$address .= '<br />' . $self->get("country");
|
||||
$address .= '<br />'.$self->get("phoneNumber") if ($self->get("phoneNumber") ne "");
|
||||
$address .= '<br /><a href="mailto:'.$self->get("email").'">'.$self->get("email").'</a>' if ($self->get("email") ne "");
|
||||
return $address;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id of this item.
|
||||
|
||||
=cut
|
||||
|
||||
sub getId {
|
||||
my $self = shift;
|
||||
return $self->get("addressId");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( addressBook, addressId )
|
||||
|
||||
Constructor. Instanciates an existing address from the database based upon addressId.
|
||||
|
||||
=head3 addressBook
|
||||
|
||||
A reference to a WebGUI::Shop::AdressBook object.
|
||||
|
||||
=head3 addressId
|
||||
|
||||
The unique id of the address to instanciate.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $book, $addressId) = @_;
|
||||
unless (defined $book && $book->isa("WebGUI::Shop::AddressBook")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Shop::AddressBook", got=>(ref $book), error=>"Need an address book.");
|
||||
}
|
||||
unless (defined $addressId) {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Need an addressId.", param=>$addressId);
|
||||
}
|
||||
my $address = $book->session->db->quickHashRef('select * from address where addressId=?', [$addressId]);
|
||||
if ($address->{addressId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"Address not found.", id=>$addressId);
|
||||
}
|
||||
if ($address->{addressBookId} ne $book->getId) {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"Address not in this address book.", id=>$addressId);
|
||||
}
|
||||
my $self = register $class;
|
||||
my $id = id $self;
|
||||
$addressBook{ $id } = $book;
|
||||
$properties{ $id } = $address;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update ( properties )
|
||||
|
||||
Sets properties of the address.
|
||||
|
||||
=head3 properties
|
||||
=head3 $properties
|
||||
|
||||
A hash reference that contains one or more of the following:
|
||||
|
||||
|
|
@ -254,19 +196,165 @@ An email address for this user.
|
|||
|
||||
The organization or company that this user is a part of.
|
||||
|
||||
=head4 addressBookId
|
||||
=cut
|
||||
|
||||
The address book that this address belongs to.
|
||||
|
||||
around BUILDARGS => sub {
|
||||
my $orig = shift;
|
||||
my $class = shift;
|
||||
if (ref $_[0] eq 'HASH') {
|
||||
my $properties = $_[0];
|
||||
my $book = $properties->{addressBook};
|
||||
if (! (blessed $book && $book->isa('WebGUI::Shop::AddressBook')) ) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Shop::AddressBook", got=>(ref $book), error=>"Need an address book.", param=>$book);
|
||||
}
|
||||
my ($addressId) = $class->_init($book);
|
||||
$properties->{addressId} = $addressId;
|
||||
$properties->{addressBookId} = $book->addressBookId;
|
||||
$properties->{addressBook} = $book;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
my $book = shift;
|
||||
if (! (blessed $book && $book->isa('WebGUI::Shop::AddressBook')) ) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Shop::AddressBook", got=>(ref $book), error=>"Need an address book.", param=>$book);
|
||||
}
|
||||
my $argument2 = shift;
|
||||
if (!defined $argument2) {
|
||||
my ($addressId) = $class->_init($book);
|
||||
my $properties = {};
|
||||
$properties->{addressId} = $addressId;
|
||||
$properties->{addressBookId} = $book->addressBookId;
|
||||
$properties->{addressBook} = $book;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
elsif (ref $argument2 eq 'HASH') {
|
||||
my $properties = $argument2;
|
||||
my ($addressId) = $class->_init($book);
|
||||
$properties->{addressId} = $addressId;
|
||||
$properties->{addressBookId} = $book->addressBookId;
|
||||
$properties->{addressBook} = $book;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
##Look up one in the db
|
||||
my $address = $book->session->db->quickHashRef("select * from address where addressId=?", [$argument2]);
|
||||
if ($address->{addressId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"Address not found.", id=>$argument2);
|
||||
}
|
||||
if ($address->{addressBookId} ne $book->getId) {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"Address not in this address book.", id=>$argument2);
|
||||
}
|
||||
$address->{addressBook} = $book;
|
||||
return $class->$orig($address);
|
||||
};
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _init ( session )
|
||||
|
||||
Builds a stub of object information in the database, and returns the newly created
|
||||
addressId, and the creationDate fields so the object can be initialized correctly.
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
my ($self, $newProperties) = @_;
|
||||
my $id = id $self;
|
||||
foreach my $field (qw(addressBookId email organization address1 address2 address3 state code city label firstName lastName country phoneNumber)) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->addressBook->session->db->setRow("address","addressId",$properties{$id});
|
||||
sub _init {
|
||||
my $class = shift;
|
||||
my $book = shift;
|
||||
my $session = $book->session;
|
||||
my $addressId = $session->id->generate;
|
||||
$session->db->write('insert into address (addressId, addressBookId) values (?,?)', [$addressId, $book->getId]);
|
||||
return ($addressId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addressBook ( )
|
||||
|
||||
Returns a reference to the Address Book.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( book )
|
||||
|
||||
Deprecated, left as a stub for existing code. Use L<new> instead.
|
||||
|
||||
=head3 book
|
||||
|
||||
A reference to an address book.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my ($class, $book) = @_;
|
||||
return $class->new($book);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 delete ( )
|
||||
|
||||
Removes this address from the book.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
$self->addressBook->session->db->deleteRow("address","addressId",$self->getId);
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getHtmlFormatted ()
|
||||
|
||||
Returns an HTML formatted address for display.
|
||||
|
||||
=cut
|
||||
|
||||
sub getHtmlFormatted {
|
||||
my $self = shift;
|
||||
my $address = $self->firstName. " " .$self->lastName . "<br />";
|
||||
$address .= $self->organization . "<br />" if ($self->organization ne "");
|
||||
$address .= $self->address1 . "<br />";
|
||||
$address .= $self->address2 . "<br />" if ($self->address2 ne "");
|
||||
$address .= $self->address3 . "<br />" if ($self->address3 ne "");
|
||||
$address .= $self->city . ", ";
|
||||
$address .= $self->state . " " if ($self->state ne "");
|
||||
$address .= $self->code if ($self->code ne "");
|
||||
$address .= '<br />' . $self->country;
|
||||
$address .= '<br />'.$self->phoneNumber if ($self->phoneNumber ne "");
|
||||
$address .= '<br /><a href="mailto:'.$self->email.'">'.$self->email.'</a>' if ($self->email ne "");
|
||||
return $address;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id of this item.
|
||||
|
||||
=cut
|
||||
|
||||
sub getId {
|
||||
my $self = shift;
|
||||
return $self->get("addressId");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 write ( )
|
||||
|
||||
Store the object's properties to the db.
|
||||
|
||||
=cut
|
||||
|
||||
sub write {
|
||||
my ($self) = @_;
|
||||
my $properties = $self->get();
|
||||
my $book = delete $properties->{addressBook};
|
||||
$book->session->db->setRow("address","addressId",$properties);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,25 @@ package WebGUI::Shop::AddressBook;
|
|||
|
||||
use strict;
|
||||
|
||||
use Class::InsideOut qw{ :std };
|
||||
use Moose;
|
||||
use WebGUI::Definition;
|
||||
|
||||
property 'userId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'defaultAddressId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
has [ qw/addressBookId session/] => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
|
||||
use JSON;
|
||||
require WebGUI::Asset::Template;
|
||||
use WebGUI::Exception::Shop;
|
||||
|
|
@ -31,9 +49,103 @@ These subroutines are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
readonly session => my %session;
|
||||
private properties => my %properties;
|
||||
private addressCache => my %addressCache;
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( $session, $addressBookId )
|
||||
|
||||
Constructor. Instanciates an address book based upon an addressBookId.
|
||||
|
||||
=head2 new ( $session )
|
||||
|
||||
Constructor. Builds a new, default address book object.
|
||||
|
||||
=head2 new ( $properties )
|
||||
|
||||
Constructor. Builds a new, default address book object in Moose style with default properties set by $properties. This does not
|
||||
persist them to the database automatically. This needs to be done via $self->write.
|
||||
|
||||
=head3 $session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 $addressBookId
|
||||
|
||||
The unique id of a cart to instanciate.
|
||||
|
||||
=head3 $properties
|
||||
|
||||
A hash reference that contains one or more of the following:
|
||||
|
||||
=head4 defaultAddressId
|
||||
|
||||
The unique id for a address attached to this cart.
|
||||
|
||||
=head4 userId
|
||||
|
||||
The unique id for the user who owns this cart.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
around BUILDARGS => sub {
|
||||
my $orig = shift;
|
||||
my $class = shift;
|
||||
if (ref $_[0] eq 'HASH') {
|
||||
my $properties = $_[0];
|
||||
my $session = $properties->{session};
|
||||
if (! (blessed $session && $session->isa('WebGUI::Session')) ) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
if ($session->user->isVisitor) {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Visitor cannot have an address book.");
|
||||
}
|
||||
my ($addressBookId) = $class->_init($session);
|
||||
$properties->{addressBookId} = $addressBookId;
|
||||
$properties->{userId} = $session->user->userId;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
my $session = shift;
|
||||
if (! (blessed $session && $session->isa('WebGUI::Session'))) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
if ($session->user->isVisitor) {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Visitor cannot have an address book.");
|
||||
}
|
||||
my $argument2 = shift;
|
||||
if (!defined $argument2) {
|
||||
my ($addressBookId) = $class->_init($session);
|
||||
my $properties = {};
|
||||
$properties->{session} = $session;
|
||||
$properties->{addressBookId} = $addressBookId;
|
||||
$properties->{userId} = $session->user->userId;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
##Look up one in the db
|
||||
my $book = $session->db->quickHashRef("select * from addressBook where addressBookId=?", [$argument2]);
|
||||
if ($book->{addressBookId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"No such address book.", id=>$argument2);
|
||||
}
|
||||
$book->{session} = $session;
|
||||
return $class->$orig($book);
|
||||
};
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _init ( session )
|
||||
|
||||
Builds a stub of object information in the database, and returns the newly created
|
||||
addressBookId, and the creationDate fields so the object can be initialized correctly.
|
||||
|
||||
=cut
|
||||
|
||||
sub _init {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $addressBookId = $session->id->generate;
|
||||
$session->db->write('insert into addressBook (addressBookId, userId) values (?,?)', [$addressBookId, $session->user->userId]);
|
||||
return ($addressBookId);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -51,7 +163,8 @@ A hash reference containing address information.
|
|||
|
||||
sub addAddress {
|
||||
my ($self, $address) = @_;
|
||||
my $addressObj = WebGUI::Shop::Address->create( $self, $address);
|
||||
my $addressObj = WebGUI::Shop::Address->create($self);
|
||||
$addressObj->update($address);
|
||||
return $addressObj;
|
||||
}
|
||||
|
||||
|
|
@ -114,32 +227,19 @@ sub appendAddressFormVars {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( session, userId )
|
||||
=head2 create ( session )
|
||||
|
||||
Constructor. Creates a new address book for this user.
|
||||
Deprecated, left as a stub for existing code. Use L<new> instead.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 userId
|
||||
|
||||
The userId for the user. Throws an exception if it is Visitor. Defaults to the session
|
||||
user if omitted.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my ($class, $session, $userId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
$userId ||= $session->user->userId;
|
||||
if ($userId eq '1') {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Visitor cannot have an address book.");
|
||||
}
|
||||
my $id = $session->db->setRow("addressBook", "addressBookId", {addressBookId=>"new", userId=>$userId});
|
||||
return $class->new($session, $id);
|
||||
my ($class, $session) = @_;
|
||||
return $class->new($session);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -152,9 +252,7 @@ Deletes this address book and all addresses contained in it.
|
|||
|
||||
sub delete {
|
||||
my ($self) = @_;
|
||||
my $myId = id $self;
|
||||
foreach my $address (@{$self->getAddresses}) {
|
||||
delete $addressCache{$myId}{$address->getId};
|
||||
$address->delete;
|
||||
}
|
||||
$self->session->db->write("delete from addressBook where addressBookId=?",[$self->getId]);
|
||||
|
|
@ -181,28 +279,6 @@ sub formatCallbackForm {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( [ property ] )
|
||||
|
||||
Returns a duplicated hash reference of this object’s data.
|
||||
|
||||
=head3 property
|
||||
|
||||
Any field − returns the value of a field rather than the hash reference. See the
|
||||
C<update> method.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my ($self, $name) = @_;
|
||||
if (defined $name) {
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
my %copyOfHashRef = %{$properties{id $self}};
|
||||
return \%copyOfHashRef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getAddress ( id )
|
||||
|
||||
Returns an address object.
|
||||
|
|
@ -215,11 +291,10 @@ An address object's unique id.
|
|||
|
||||
sub getAddress {
|
||||
my ($self, $addressId) = @_;
|
||||
my $id = id $self;
|
||||
unless (exists $addressCache{$id}{$addressId}) {
|
||||
$addressCache{$id}{$addressId} = WebGUI::Shop::Address->new($self, $addressId);
|
||||
unless (exists $self->{_addressCache}->{$addressId}) {
|
||||
$self->{_addressCache}->{$addressId} = WebGUI::Shop::Address->new($self, $addressId);
|
||||
}
|
||||
return $addressCache{$id}{$addressId};
|
||||
return $self->{_addressCache}->{$addressId};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -337,41 +412,6 @@ sub missingFields {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session, addressBookId )
|
||||
|
||||
Constructor. Instanciates an addressBook based upon a addressBookId.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 addressBookId
|
||||
|
||||
The unique id of an address book to instanciate.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $session, $addressBookId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
unless (defined $addressBookId) {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Need an addressBookId.");
|
||||
}
|
||||
my $addressBook = $session->db->quickHashRef('select * from addressBook where addressBookId=?', [$addressBookId]);
|
||||
if ($addressBook->{addressBookId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"No such address book.", id=>$addressBookId);
|
||||
}
|
||||
my $self = register $class;
|
||||
my $id = id $self;
|
||||
$session{ $id } = $session;
|
||||
$properties{ $id } = $addressBook;
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newByUserId ( session, userId )
|
||||
|
||||
Constructor. Creates a new address book for this user if they don't have one. In any case returns a reference to the address book.
|
||||
|
|
@ -418,7 +458,7 @@ sub newByUserId {
|
|||
}
|
||||
else {
|
||||
# nope create one for the user
|
||||
return $class->create($session);
|
||||
return $class->new($session);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -465,31 +505,15 @@ sub processAddressForm {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update ( properties )
|
||||
=head2 write ( )
|
||||
|
||||
Sets properties in the addressBook
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference that contains one of the following:
|
||||
|
||||
=head4 userId
|
||||
|
||||
Assign the user that owns this address book.
|
||||
|
||||
=head4 defaultAddressId
|
||||
|
||||
The id of the address to be made the default for this address book.
|
||||
Writes the object properties to the database.
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
sub write {
|
||||
my ($self, $newProperties) = @_;
|
||||
my $id = id $self;
|
||||
foreach my $field (qw(userId defaultAddressId)) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->session->db->setRow("addressBook","addressBookId",$properties{$id});
|
||||
$self->session->db->setRow("addressBook","addressBookId",$self->get());
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,7 +1,27 @@
|
|||
package WebGUI::Shop::Admin;
|
||||
|
||||
use strict;
|
||||
use Class::InsideOut qw{ :std };
|
||||
|
||||
use Moose;
|
||||
|
||||
has session => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
around BUILDARGS => sub {
|
||||
my $orig = shift;
|
||||
my $className = shift;
|
||||
|
||||
##Original arguments start here.
|
||||
my $protoSession = $_[0];
|
||||
if (blessed $protoSession && $protoSession->isa('WebGUI::Session')) {
|
||||
return $className->$orig(session => $protoSession);
|
||||
}
|
||||
return $className->$orig(@_);
|
||||
};
|
||||
|
||||
|
||||
use WebGUI::AdminConsole;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::HTMLForm;
|
||||
|
|
@ -28,8 +48,6 @@ These subroutines are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
readonly session => my %session;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 canManage ( [ $user ] )
|
||||
|
|
@ -103,17 +121,6 @@ A reference to the current session.
|
|||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $session) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $self = register $class;
|
||||
my $id = id $self;
|
||||
$session{ $id } = $session;
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,58 @@ package WebGUI::Shop::Cart;
|
|||
|
||||
use strict;
|
||||
|
||||
use Class::InsideOut qw{ :std };
|
||||
use Scalar::Util qw/blessed/;
|
||||
use Moose;
|
||||
use WebGUI::Definition;
|
||||
|
||||
property 'shippingAddressId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'billingAddressId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'shipperId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'gatewayId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'posUserId' => (
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property creationDate => (
|
||||
required => 1,
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
has [ qw/cartId session/] => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
);
|
||||
has sessionId => (
|
||||
is => 'ro',
|
||||
lazy => 1,
|
||||
builder => '_default_sessionId',
|
||||
);
|
||||
sub _default_sessionId {
|
||||
my $self = shift;
|
||||
return $self->session->getId;
|
||||
}
|
||||
has error => (
|
||||
is => 'rw',
|
||||
);
|
||||
|
||||
|
||||
use JSON;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Exception::Shop;
|
||||
|
|
@ -38,10 +89,110 @@ These subroutines are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
readonly session => my %session;
|
||||
private properties => my %properties;
|
||||
public error => my %error;
|
||||
private addressBookCache => my %addressBookCache;
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( $session, $cartId )
|
||||
|
||||
Constructor. Instanciates a cart based upon a cartId.
|
||||
|
||||
=head2 new ( $session )
|
||||
|
||||
Constructor. Builds a new, default cart object.
|
||||
|
||||
=head2 new ( $properties )
|
||||
|
||||
Constructor. Builds a new, default cart object in Moose style with default properties set by $properties. This does not
|
||||
persist them to the database automatically. This needs to be done via $self->write.
|
||||
|
||||
=head3 $session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 $cartId
|
||||
|
||||
The unique id of a cart to instanciate.
|
||||
|
||||
=head3 $properties
|
||||
|
||||
A hash reference that contains one or more of the following:
|
||||
|
||||
=head4 shippingAddressId
|
||||
|
||||
The unique id for a shipping address attached to this cart.
|
||||
|
||||
=head4 billingAddressId
|
||||
|
||||
The unique id for a billing address attached to this cart.
|
||||
|
||||
=head4 shipperId
|
||||
|
||||
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.
|
||||
|
||||
=head4 creationDate
|
||||
|
||||
The date the cart was created.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
around BUILDARGS => sub {
|
||||
my $orig = shift;
|
||||
my $class = shift;
|
||||
if (ref $_[0] eq 'HASH') {
|
||||
my $properties = $_[0];
|
||||
my $session = $properties->{session};
|
||||
if (! (blessed $session && $session->isa('WebGUI::Session')) ) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my ($cartId, $creationDate) = $class->_init($session);
|
||||
$properties->{cartId} = $cartId;
|
||||
$properties->{creationDate} = $creationDate;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
my $session = shift;
|
||||
if (! (blessed $session && $session->isa('WebGUI::Session'))) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $argument2 = shift;
|
||||
if (!defined $argument2) {
|
||||
my ($cartId, $creationDate) = $class->_init($session);
|
||||
my $properties = {};
|
||||
$properties->{session} = $session;
|
||||
$properties->{cartId} = $cartId;
|
||||
$properties->{creationDate} = $creationDate;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
##Look up one in the db
|
||||
my $cart = $session->db->quickHashRef("select * from cart where cartId=?", [$argument2]);
|
||||
if ($cart->{cartId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"No such cart.", id=>$argument2);
|
||||
}
|
||||
$cart->{session} = $session;
|
||||
return $class->$orig($cart);
|
||||
};
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _init ( session )
|
||||
|
||||
Builds a stub of object information in the database, and returns the newly created
|
||||
cartId, and the creationDate fields so the object can be initialized correctly.
|
||||
|
||||
=cut
|
||||
|
||||
sub _init {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $creationDate = WebGUI::DateTime->new($session)->epoch;
|
||||
my $cartId = $session->id->generate;
|
||||
$session->db->write('insert into cart (cartId, sessionId, creationDate) values (?,?,?)', [$cartId, $session->getId, $creationDate]);
|
||||
return ($cartId, $creationDate);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -83,7 +234,7 @@ sub calculateShopCreditDeduction {
|
|||
}
|
||||
# cannot use in-shop credit on recurring items
|
||||
return $self->formatCurrency(0) if $self->requiresRecurringPayment;
|
||||
return $self->formatCurrency(WebGUI::Shop::Credit->new($self->session, $self->get('posUserId'))->calculateDeduction($total));
|
||||
return $self->formatCurrency(WebGUI::Shop::Credit->new($self->session, $self->posUserId)->calculateDeduction($total));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -160,7 +311,7 @@ sub calculateTotal {
|
|||
|
||||
=head2 create ( session )
|
||||
|
||||
Constructor. Creates a new cart object if there’s not one already attached to the current session object. Otherwise just instanciates the existing one. Returns a reference to the object.
|
||||
Deprecated, left as a stub for existing code. Use L<new> instead.
|
||||
|
||||
=head3 session
|
||||
|
||||
|
|
@ -170,12 +321,7 @@ A reference to the current session.
|
|||
|
||||
sub create {
|
||||
my ($class, $session) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $cartId = $session->id->generate;
|
||||
$session->db->write('insert into cart (cartId, sessionId, creationDate) values (?,?,UNIX_TIMESTAMP())', [$cartId, $session->getId]);
|
||||
return $class->new($session, $cartId);
|
||||
return $class->new($session);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -230,27 +376,6 @@ sub formatCurrency {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( [ property ] )
|
||||
|
||||
Returns a duplicated hash reference of this object’s data.
|
||||
|
||||
=head3 property
|
||||
|
||||
Any field − returns the value of a field rather than the hash reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my ($self, $name) = @_;
|
||||
if (defined $name) {
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
my %copyOfHashRef = %{$properties{id $self}};
|
||||
return \%copyOfHashRef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getAddressBook ()
|
||||
|
||||
Returns a reference to the address book for the user who's cart this is.
|
||||
|
|
@ -259,11 +384,10 @@ Returns a reference to the address book for the user who's cart this is.
|
|||
|
||||
sub getAddressBook {
|
||||
my $self = shift;
|
||||
my $id = id $self;
|
||||
unless (exists $addressBookCache{$id}) {
|
||||
$addressBookCache{$id} = WebGUI::Shop::AddressBook->newByUserId($self->session);
|
||||
unless (exists $self->{_addressBook}) {
|
||||
$self->{_addressBook} = WebGUI::Shop::AddressBook->newByUserId($self->session);
|
||||
}
|
||||
return $addressBookCache{$id};
|
||||
return $self->{_addressBook};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -277,7 +401,7 @@ Returns the WebGUI::Shop::Address object that is attached to this cart for billi
|
|||
sub getBillingAddress {
|
||||
my $self = shift;
|
||||
my $book = $self->getAddressBook;
|
||||
if (my $addressId = $self->get("billingAddressId")) {
|
||||
if (my $addressId = $self->billingAddressId) {
|
||||
return $book->getAddress($addressId);
|
||||
}
|
||||
my $address = $book->getDefaultAddress;
|
||||
|
|
@ -332,7 +456,7 @@ Returns the unique id for this cart.
|
|||
|
||||
sub getId {
|
||||
my ($self) = @_;
|
||||
return $self->get("cartId");
|
||||
return $self->cartId;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -409,7 +533,7 @@ Returns the WebGUI::Shop::PayDriver object that is attached to this cart for pay
|
|||
|
||||
sub getPaymentGateway {
|
||||
my $self = shift;
|
||||
return WebGUI::Shop::Pay->new($self->session)->getPaymentGateway($self->get("gatewayId"));
|
||||
return WebGUI::Shop::Pay->new($self->session)->getPaymentGateway($self->gatewayId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -422,7 +546,7 @@ Returns the userId of the user making a purchase. If there is a cashier and the
|
|||
|
||||
sub getPosUser {
|
||||
my $self = shift;
|
||||
if ($self->get('posUserId') ne "") {
|
||||
if ($self->posUserId ne "") {
|
||||
return WebGUI::User->new($self->session, $self->get('posUserId'));
|
||||
}
|
||||
return $self->session->user;
|
||||
|
|
@ -438,7 +562,7 @@ Returns the WebGUI::Shop::ShipDriver object that is attached to this cart for sh
|
|||
|
||||
sub getShipper {
|
||||
my $self = shift;
|
||||
return WebGUI::Shop::Ship->new(session => $self->session)->getShipper($self->get("shipperId"));
|
||||
return WebGUI::Shop::Ship->new(session => $self->session)->getShipper($self->shipperId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -452,8 +576,8 @@ Returns the WebGUI::Shop::Address object that is attached to this cart for shipp
|
|||
sub getShippingAddress {
|
||||
my $self = shift;
|
||||
my $book = $self->getAddressBook;
|
||||
if ($self->get("shippingAddressId")) {
|
||||
return $book->getAddress($self->get("shippingAddressId"));
|
||||
if ($self->shippingAddressId) {
|
||||
return $book->getAddress($self->shippingAddressId);
|
||||
}
|
||||
my $address = $book->getDefaultAddress;
|
||||
$self->update({shippingAddressId=>$address->getId});
|
||||
|
|
@ -487,41 +611,6 @@ sub hasMixedItems {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session, cartId )
|
||||
|
||||
Constructor. Instanciates a cart based upon a cartId.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 cartId
|
||||
|
||||
The unique id of a cart to instanciate.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $session, $cartId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
unless (defined $cartId && $cartId =~ m/^[A-Za-z0-9_-]{22}$/) {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Need a cartId.");
|
||||
}
|
||||
my $cart = $session->db->quickHashRef('select * from cart where cartId=?', [$cartId]);
|
||||
if ($cart->{cartId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"No such cart.", id=>$cartId);
|
||||
}
|
||||
my $self = register $class;
|
||||
my $id = id $self;
|
||||
$session{ $id } = $session;
|
||||
$properties{ $id } = $cart;
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newBySession ( session )
|
||||
|
||||
Class method that figures out if the user has a cart in their session. If they do it returns it. If they don't it creates it and returns it.
|
||||
|
|
@ -538,8 +627,7 @@ sub newBySession {
|
|||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $cartId = $session->db->quickScalar("select cartId from cart where sessionId=?",[$session->getId]);
|
||||
return $class->new($session, $cartId) if (defined $cartId and $cartId ne '');
|
||||
return $class->create($session);
|
||||
return $class->new($session, $cartId); ##Falls back to creating a new cart if there's no 2nd argument
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -597,12 +685,12 @@ sub readyForCheckout {
|
|||
|
||||
if ($self->requiresShipping) {
|
||||
##Must have a configured shipping id.
|
||||
if (! $self->get('shipperId')) {
|
||||
if (! $self->shipperId) {
|
||||
$self->error('no shipping method set');
|
||||
return 0;
|
||||
}
|
||||
|
||||
my $shipper = eval { WebGUI::Shop::ShipDriver->new($session, $self->get('shipperId'))};
|
||||
my $shipper = eval { WebGUI::Shop::ShipDriver->new($session, $self->shipperId)};
|
||||
if (my $e = WebGUI::Error->caught) {
|
||||
$self->error($e->error);
|
||||
return 0;
|
||||
|
|
@ -628,19 +716,19 @@ sub readyForCheckout {
|
|||
}
|
||||
|
||||
##Must have a configured payment method.
|
||||
if (! $self->get('gatewayId')) {
|
||||
if (! $self->gatewayId) {
|
||||
$self->error('no payment gateway set');
|
||||
return 0;
|
||||
}
|
||||
|
||||
my $gateway = eval { WebGUI::Shop::PayDriver->new($session, $self->get('gatewayId'))};
|
||||
my $gateway = eval { WebGUI::Shop::PayDriver->new($session, $self->gatewayId)};
|
||||
if (my $e = WebGUI::Error->caught) {
|
||||
$self->error($e->error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
##Check for any other logged errors
|
||||
return 0 if $error{ id $self };
|
||||
return 0 if $self->error;
|
||||
|
||||
# All checks passed so return true
|
||||
return 1;
|
||||
|
|
@ -688,46 +776,17 @@ sub requiresShipping {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update ( properties )
|
||||
=head2 write ( )
|
||||
|
||||
Sets properties in the cart.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference that contains one of the following:
|
||||
|
||||
=head4 shippingAddressId
|
||||
|
||||
The unique id for a shipping address attached to this cart.
|
||||
|
||||
=head4 billingAddressId
|
||||
|
||||
The unique id for a billing address attached to this cart.
|
||||
|
||||
=head4 shipperId
|
||||
|
||||
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.
|
||||
|
||||
=head4 creationDate
|
||||
|
||||
The date the cart was created.
|
||||
Serialize the current set of cart properties to the database.
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
my ($self, $newProperties) = @_;
|
||||
unless (defined $newProperties && ref $newProperties eq 'HASH') {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
|
||||
}
|
||||
my $id = id $self;
|
||||
foreach my $field (qw(billingAddressId shippingAddressId posUserId gatewayId shipperId creationDate)) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->session->db->setRow("cart","cartId",$properties{$id});
|
||||
sub write {
|
||||
my ($self) = @_;
|
||||
my $properties = $self->get();
|
||||
delete $properties->{error};
|
||||
$self->session->db->setRow("cart", "cartId", $properties);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -747,10 +806,10 @@ sub updateFromForm {
|
|||
eval { $item->setQuantity($form->get("quantity-".$item->getId)) };
|
||||
if (WebGUI::Error->caught("WebGUI::Error::Shop::MaxOfItemInCartReached")) {
|
||||
my $i18n = WebGUI::International->new($self->session, "Shop");
|
||||
$error{id $self} = sprintf($i18n->get("too many of this item"), $item->get("configuredTitle"));
|
||||
$self->error(sprintf($i18n->get("too many of this item"), $item->get("configuredTitle")));
|
||||
}
|
||||
elsif (my $e = WebGUI::Error->caught) {
|
||||
$error{id $self} = "An unknown error has occured: ".$e->message;
|
||||
$self->error("An unknown error has occured: ".$e->message);
|
||||
}
|
||||
}
|
||||
if (my $itemAddressId = $form->get("itemAddress_".$item->getId)) {
|
||||
|
|
@ -759,7 +818,7 @@ sub updateFromForm {
|
|||
}
|
||||
if ($self->hasMixedItems) {
|
||||
my $i18n = WebGUI::International->new($self->session, "Shop");
|
||||
$error{id $self} = $i18n->get('mixed items warning');
|
||||
$self->error($i18n->get('mixed items warning'));
|
||||
}
|
||||
|
||||
my @cartItemIds = $form->process('remove_item', 'checkList');
|
||||
|
|
@ -782,7 +841,7 @@ sub updateFromForm {
|
|||
my $newAddress = $book->addAddress(\%billingData);
|
||||
$cartProperties->{billingAddressId} = $newAddress->get('addressId');
|
||||
}
|
||||
elsif ($billingAddressId eq 'update_address' && $self->get('billingAddressId') && ! @missingBillingFields) {
|
||||
elsif ($billingAddressId eq 'update_address' && $self->billingAddressId && ! @missingBillingFields) {
|
||||
##User updated the current address
|
||||
my $address = $self->getBillingAddress();
|
||||
$address->update(\%billingData);
|
||||
|
|
@ -802,7 +861,7 @@ sub updateFromForm {
|
|||
|
||||
if ($self->requiresShipping) {
|
||||
if ($form->process('sameShippingAsBilling', 'yesNo')) {
|
||||
$cartProperties->{shippingAddressId} = $self->get('billingAddressId');
|
||||
$cartProperties->{shippingAddressId} = $self->billingAddressId;
|
||||
}
|
||||
else {
|
||||
my %shippingData = $book->processAddressForm('shipping_');
|
||||
|
|
@ -817,7 +876,7 @@ sub updateFromForm {
|
|||
my $newAddress = $book->addAddress(\%shippingData);
|
||||
$cartProperties->{shippingAddressId} = $newAddress->get('addressId');
|
||||
}
|
||||
elsif ($shippingAddressId eq 'update_address' && $self->get('shippingAddressId') && ! @missingShippingFields) {
|
||||
elsif ($shippingAddressId eq 'update_address' && $self->shippingAddressId && ! @missingShippingFields) {
|
||||
##User changed the address selector
|
||||
my $address = $self->getBillingAddress();
|
||||
$address->update(\%shippingData);
|
||||
|
|
@ -918,8 +977,8 @@ sub www_checkout {
|
|||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
##Setting a shipping address greatly simplifies the Transaction
|
||||
if (! $self->requiresShipping && ! $self->get('shippingAddressId')) {
|
||||
$self->update({shippingAddressId => $self->get('billingAddressId')});
|
||||
if (! $self->requiresShipping && ! $self->shippingAddressId) {
|
||||
$self->update({shippingAddressId => $self->billingAddressId});
|
||||
}
|
||||
if ($self->readyForCheckout()) {
|
||||
my $total = $self->calculateTotal;
|
||||
|
|
@ -1049,7 +1108,7 @@ sub www_view {
|
|||
|
||||
# get the shipping address
|
||||
my $address = eval { $self->getShippingAddress };
|
||||
if (my $e = WebGUI::Error->caught("WebGUI::Error::ObjectNotFound") && $self->get('shippingAddressId')) {
|
||||
if (my $e = WebGUI::Error->caught("WebGUI::Error::ObjectNotFound") && $self->shippingAddressId) {
|
||||
# choose another address cuz we've got a problem
|
||||
$self->update({shippingAddressId=>''});
|
||||
}
|
||||
|
|
@ -1125,7 +1184,7 @@ sub www_view {
|
|||
$formOptions{$optionId} .= ' ('.$self->formatCurrency($options->{$optionId}{price}).')';
|
||||
}
|
||||
}
|
||||
my $shipperId = $self->get('shipperId');
|
||||
my $shipperId = $self->shipperId;
|
||||
if (!$shipperId && $numberOfOptions == 1) {
|
||||
my ($option) = keys %{ $options };
|
||||
$self->update({shipperId => $option});
|
||||
|
|
@ -1172,7 +1231,7 @@ sub www_view {
|
|||
tie my %billingAddressOptions, 'Tie::IxHash';
|
||||
$billingAddressOptions{'new_address'} = $i18n->get('Add new address');
|
||||
|
||||
my $billingAddressId = $self->get('billingAddressId');
|
||||
my $billingAddressId = $self->billingAddressId;
|
||||
if ($billingAddressId) {
|
||||
$billingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $self->getBillingAddress->get('label');
|
||||
}
|
||||
|
|
@ -1188,7 +1247,7 @@ sub www_view {
|
|||
tie my %shippingAddressOptions, 'Tie::IxHash';
|
||||
$shippingAddressOptions{'new_address'} = $i18n->get('Add new address');
|
||||
|
||||
my $shippingAddressId = $self->get('shippingAddressId');
|
||||
my $shippingAddressId = $self->shippingAddressId;
|
||||
if ($shippingAddressId) {
|
||||
$shippingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $self->getShippingAddress->get('label');
|
||||
}
|
||||
|
|
@ -1200,15 +1259,15 @@ sub www_view {
|
|||
value => $shippingAddressId ? $shippingAddressId : 'new_address',
|
||||
});
|
||||
|
||||
my $shippingAddressData = $self->get('shippingAddressId') ? $self->getShippingAddress->get() : {};
|
||||
my $billingAddressData = $self->get('billingAddressId') ? $self->getBillingAddress->get() : {};
|
||||
my $shippingAddressData = $self->shippingAddressId ? $self->getShippingAddress->get() : {};
|
||||
my $billingAddressData = $self->billingAddressId ? $self->getBillingAddress->get() : {};
|
||||
my $addressBook = $self->getAddressBook;
|
||||
$addressBook->appendAddressFormVars(\%var, 'shipping_', $shippingAddressData);
|
||||
$addressBook->appendAddressFormVars(\%var, 'billing_', $billingAddressData);
|
||||
|
||||
$var{sameShippingAsBilling} = WebGUI::Form::yesNo($session, {
|
||||
name => 'sameShippingAsBilling',
|
||||
value => $self->get('billingAddressId') && $self->get('billingAddressId') eq $self->get('shippingAddressId'),
|
||||
value => $self->billingAddressId && $self->billingAddressId eq $self->shippingAddressId,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1223,7 +1282,7 @@ sub www_view {
|
|||
$var{paymentOptions} = WebGUI::Form::selectBox($session, {
|
||||
name => 'gatewayId',
|
||||
options => \%paymentOptions,
|
||||
value => $self->get('gatewayId') || $form->get('gatewayId') || '',
|
||||
value => $self->gatewayId || $form->get('gatewayId') || '',
|
||||
});
|
||||
|
||||
# POS variables
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
package WebGUI::Shop::Credit;
|
||||
|
||||
use strict;
|
||||
use Class::InsideOut qw{ :std };
|
||||
use Moose;
|
||||
use Scalar::Util qw/blessed/;
|
||||
|
||||
has [ qw/session userId/ ] => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
|
||||
use WebGUI::Shop::Admin;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::International;
|
||||
|
|
@ -28,8 +36,18 @@ These subroutines are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
readonly session => my %session;
|
||||
readonly userId => my %userId;
|
||||
around BUILDARGS => sub {
|
||||
my $orig = shift;
|
||||
my $className = shift;
|
||||
|
||||
##Original arguments start here.
|
||||
my $protoSession = $_[0];
|
||||
if (blessed $protoSession && $protoSession->isa('WebGUI::Session')) {
|
||||
return $className->$orig(session => $protoSession, userId => $_[1], );
|
||||
}
|
||||
return $className->$orig(@_);
|
||||
};
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -137,21 +155,6 @@ A unique id for a user that you want to adjust the credit of. Defaults to the cu
|
|||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $session, $userId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
unless (defined $userId) {
|
||||
$userId = $session->user->userId;
|
||||
}
|
||||
my $self = register $class;
|
||||
my $id = id $self;
|
||||
$session{ $id } = $session;
|
||||
$userId{ $id } = $userId;
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ package WebGUI::Shop::Pay;
|
|||
|
||||
use strict;
|
||||
|
||||
#use Class::InsideOut qw{ :std };
|
||||
use Moose;
|
||||
use WebGUI::Exception;
|
||||
use WebGUI::International;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,93 @@
|
|||
package WebGUI::Shop::Vendor;
|
||||
|
||||
use strict;
|
||||
use Class::InsideOut qw{ :std };
|
||||
use Scalar::Util qw/blessed/;
|
||||
use Moose;
|
||||
use WebGUI::Definition;
|
||||
|
||||
property 'name' => (
|
||||
is => 'rw',
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'userId' => (
|
||||
is => 'rw',
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'url' => (
|
||||
is => 'rw',
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'paymentInformation' => (
|
||||
is => 'rw',
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
property 'preferredPaymentType' => (
|
||||
is => 'rw',
|
||||
noFormPost => 1,
|
||||
default => '',
|
||||
);
|
||||
|
||||
has 'dateCreated' => (
|
||||
is => 'ro',
|
||||
);
|
||||
has [ qw/session vendorId/ ] => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
around BUILDARGS => sub {
|
||||
my $orig = shift;
|
||||
my $class = shift;
|
||||
if (ref $_[0] eq 'HASH') {
|
||||
##Need same db code as below here.
|
||||
##Session check goes here?
|
||||
##Build a new one
|
||||
my $properties = $_[0];
|
||||
my $session = $properties->{session};
|
||||
if (! (blessed $session && $session->isa('WebGUI::Session')) ) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my ($vendorId, $dateCreated) = $class->_init($session);
|
||||
$properties->{vendorId} = $vendorId;
|
||||
$properties->{dateCreated} = $dateCreated;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
my $session = shift;
|
||||
if (! (blessed $session && $session->isa('WebGUI::Session'))) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $argument2 = shift;
|
||||
if (!defined $argument2) {
|
||||
WebGUI::Error::InvalidParam->throw( param=>$argument2, error=>"Need a vendorId.");
|
||||
}
|
||||
if (ref $argument2 eq 'HASH') {
|
||||
##Build a new one
|
||||
my ($vendorId, $dateCreated) = $class->_init($session);
|
||||
my $properties = $argument2;
|
||||
$properties->{session} = $session;
|
||||
$properties->{vendorId} = $vendorId;
|
||||
$properties->{dateCreated} = $dateCreated;
|
||||
return $class->$orig($properties);
|
||||
}
|
||||
else {
|
||||
##Look up one in the db
|
||||
my $vendor = $session->db->quickHashRef("select * from vendor where vendorId=?", [$argument2]);
|
||||
if ($vendor->{vendorId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"Vendor not found.", id=>$argument2);
|
||||
}
|
||||
$vendor->{session} = $session;
|
||||
return $class->$orig($vendor);
|
||||
}
|
||||
};
|
||||
|
||||
use WebGUI::Shop::Admin;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::International;
|
||||
|
|
@ -21,7 +107,7 @@ Keeps track of vendors that sell merchandise in the store.
|
|||
|
||||
use WebGUI::Shop::Vendor;
|
||||
|
||||
my $vendor = WebGUI::Shop::Vendor->new($session, $vendord);
|
||||
my $vendor = WebGUI::Shop::Vendor->new($session, $vendorId);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
|
@ -29,35 +115,35 @@ These subroutines are available from this package:
|
|||
|
||||
=cut
|
||||
|
||||
readonly session => my %session;
|
||||
readonly properties => my %properties;
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _init ( session )
|
||||
|
||||
Builds a stub of object information in the database, and returns the newly created
|
||||
vendorId, and the dateCreated fields so the object can be initialized correctly.
|
||||
|
||||
=cut
|
||||
|
||||
sub _init {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $vendorId = $session->id->generate;
|
||||
my $dateCreated = WebGUI::DateTime->new($session)->toDatabase;
|
||||
$session->db->write("insert into vendor (vendorId, dateCreated) values (?, ?)",[$vendorId, $dateCreated]);
|
||||
return ($vendorId, $dateCreated);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( session, properties )
|
||||
|
||||
Constructor. Creates a new vendor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference containing the properties for this vendor. See update() for details.
|
||||
Constructor. Creates a new vendor. Really an alias for WebGUI::Shop::Vendor->new($session, $properties)
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my ($class, $session, $properties) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $id = $session->id->generate;
|
||||
$session->db->write("insert into vendor (vendorId, dateCreated) values (?, now())",[$id]);
|
||||
my $self = $class->new($session, $id);
|
||||
$self->update($properties);
|
||||
return $self;
|
||||
return $class->new($session, $properties);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -70,51 +156,20 @@ Deletes this vendor.
|
|||
|
||||
sub delete {
|
||||
my ($self) = @_;
|
||||
$self->session->db->deleteRow("vendor","vendorId",$self->getId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( [ property ] )
|
||||
|
||||
Returns a duplicated hash reference of this objectÕs data. See update() for details.
|
||||
|
||||
=head3 property
|
||||
|
||||
Any field returns the value of a field rather than the hash reference.
|
||||
|
||||
=head3 Additional properties
|
||||
|
||||
=head4 dateCreated
|
||||
|
||||
The date this vendor was created in the system.
|
||||
|
||||
=head4 vendorId
|
||||
|
||||
The id of this vendor from the database. Use getId() instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my ($self, $name) = @_;
|
||||
if (defined $name) {
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
my %copyOfHashRef = %{$properties{id $self}};
|
||||
return \%copyOfHashRef;
|
||||
$self->session->db->deleteRow("vendor", "vendorId", $self->vendorId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id of this item.
|
||||
Returns the unique id of this item. You should use $self->vendorId instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub getId {
|
||||
my $self = shift;
|
||||
return $self->get("vendorId");
|
||||
return $self->vendorId;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -147,7 +202,7 @@ sub getPayoutTotals {
|
|||
my %totals = $self->session->db->buildHash(
|
||||
'select vendorPayoutStatus, sum(vendorPayoutAmount) as amount from transactionItem as t1, transaction as t2 '
|
||||
.'where t1.transactionId = t2.transactionId and t2.isSuccessful <> 0 and vendorId=? group by vendorPayoutStatus ',
|
||||
[ $self->getId ]
|
||||
[ $self->vendorId ]
|
||||
);
|
||||
|
||||
# Format the payout categories and calc the total those.
|
||||
|
|
@ -204,10 +259,10 @@ sub isVendorInfoComplete {
|
|||
my $self = shift;
|
||||
|
||||
my $complete =
|
||||
defined $self->get( 'name' )
|
||||
&& defined $self->get( 'userId' )
|
||||
&& defined $self->get( 'preferredPaymentType' )
|
||||
&& defined $self->get( 'paymentInformation' );
|
||||
defined $self->name
|
||||
&& defined $self->userId
|
||||
&& defined $self->preferredPaymentType
|
||||
&& defined $self->paymentInformation;
|
||||
|
||||
return $complete
|
||||
}
|
||||
|
|
@ -216,7 +271,12 @@ sub isVendorInfoComplete {
|
|||
|
||||
=head2 new ( session, vendorId )
|
||||
|
||||
Constructor. Returns a WebGUI::Shop::Vendor object.
|
||||
=head2 new ( session, properties )
|
||||
|
||||
=head2 new ( hashref )
|
||||
|
||||
Constructor. Returns a WebGUI::Shop::Vendor object, either by fetching information from the database,
|
||||
or using passed in properties.
|
||||
|
||||
=head3 session
|
||||
|
||||
|
|
@ -229,26 +289,44 @@ A unique id for a vendor that already exists in the database. If the vendorId i
|
|||
in, then a WebGUI::Error::InvalidParam Exception will be thrown. If the requested Id cannot
|
||||
be found in the database, then a WebGUI::Error::ObjectNotFound exception will be thrown.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hashref of properties to assign to the object when it is created.
|
||||
|
||||
=head3 hashref
|
||||
|
||||
A classic Moose-style hashref of options. It must include a WebGUI::Session object.
|
||||
|
||||
=head3 Attributes
|
||||
|
||||
=head4 name
|
||||
|
||||
The name of the vendor.
|
||||
|
||||
=head4 userId
|
||||
|
||||
The unique GUID of the vendor.
|
||||
|
||||
=head4 url
|
||||
|
||||
The vendor's url.
|
||||
|
||||
=head4 vendorId
|
||||
|
||||
A unique identifier for this vendor. This option may be included in the properties for the new object, but it will
|
||||
be ignored.
|
||||
|
||||
=head4 dateCreated
|
||||
|
||||
The date this vendor was created, in database format. This option may be included in the properties for the new object,
|
||||
but it will be ignored.
|
||||
|
||||
=head4 paymentInformation
|
||||
|
||||
=head4 preferredPaymentType
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $session, $vendorId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
unless (defined $vendorId) {
|
||||
WebGUI::Error::InvalidParam->throw( param=>$vendorId, error=>"Need a vendorId.");
|
||||
}
|
||||
my $vendor = $session->db->quickHashRef("select * from vendor where vendorId=?",[$vendorId]);
|
||||
if ($vendor->{vendorId} eq "") {
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"Vendor not found.", id=>$vendorId);
|
||||
}
|
||||
my $self = register $class;
|
||||
my $id = id $self;
|
||||
$session{ $id } = $session;
|
||||
$properties{ $id } = $vendor;
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -262,7 +340,7 @@ A reference to the current session.
|
|||
|
||||
=head3 userId
|
||||
|
||||
A unique userId. Will pull from the session if not specified.
|
||||
A unique userId. Will pull from the session if not specified.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -289,44 +367,16 @@ Returns a reference to the current session.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update ( properties )
|
||||
=head2 write ( )
|
||||
|
||||
Sets properties of the vendor
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference that contains one of the following:
|
||||
|
||||
=head4 name
|
||||
|
||||
The name of the vendor.
|
||||
|
||||
=head4 userId
|
||||
|
||||
The unique GUID of the vendor.
|
||||
|
||||
=head4 url
|
||||
|
||||
The vendor's url.
|
||||
|
||||
=head4 paymentInformation
|
||||
|
||||
????
|
||||
|
||||
=head4 preferredPaymentType
|
||||
|
||||
????
|
||||
Serializes the object's properties to the database
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
my ($self, $newProperties) = @_;
|
||||
my $id = id $self;
|
||||
my @fields = (qw(name userId url paymentInformation preferredPaymentType));
|
||||
foreach my $field (@fields) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->session->db->setRow("vendor","vendorId",$properties{$id});
|
||||
sub write {
|
||||
my ($self) = @_;
|
||||
my $properties = $self->get();
|
||||
$self->session->db->setRow("vendor", "vendorId", $properties);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -447,7 +497,7 @@ sub www_manage {
|
|||
.WebGUI::Form::formHeader($session, {extras=>'style="float: left;"' })
|
||||
.WebGUI::Form::hidden($session, { name => "shop", value => "vendor" })
|
||||
.WebGUI::Form::hidden($session, { name => "method", value => "delete" })
|
||||
.WebGUI::Form::hidden($session, { name => "vendorId", value => $vendor->getId })
|
||||
.WebGUI::Form::hidden($session, { name => "vendorId", value => $vendor->vendorId })
|
||||
.WebGUI::Form::submit($session, { value => $i18n->get("delete"), extras => 'class="backwardButton"' })
|
||||
.WebGUI::Form::formFooter($session)
|
||||
|
||||
|
|
@ -455,12 +505,12 @@ sub www_manage {
|
|||
.WebGUI::Form::formHeader($session, {extras=>'style="float: left;"' })
|
||||
.WebGUI::Form::hidden($session, { name => "shop", value => "vendor" })
|
||||
.WebGUI::Form::hidden($session, { name => "method", value => "edit" })
|
||||
.WebGUI::Form::hidden($session, { name => "vendorId", value => $vendor->getId })
|
||||
.WebGUI::Form::hidden($session, { name => "vendorId", value => $vendor->vendorId })
|
||||
.WebGUI::Form::submit($session, { value => $i18n->get("edit"), extras => 'class="normalButton"' })
|
||||
.WebGUI::Form::formFooter($session)
|
||||
|
||||
# Append name
|
||||
.' '. $vendor->get("name")
|
||||
.' '. $vendor->name
|
||||
.'</div>';
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue