Add better support for user profile fields for addresses to the Cart and the EMS.
This commit is contained in:
parent
39049e1c7c
commit
428ea58327
21 changed files with 1657 additions and 62 deletions
|
|
@ -432,16 +432,67 @@ sub www_editSave {
|
|||
|
||||
unless(scalar(@{$retHash->{errors}})) {
|
||||
my $profile = $retHash->{profile};
|
||||
|
||||
my $privacy = {};
|
||||
$session->user->update($profile);
|
||||
|
||||
my $address = {};
|
||||
my $address_mappings = WebGUI::Shop::AddressBook->getProfileAddressMappings;
|
||||
foreach my $fieldName (keys %{$profile}) {
|
||||
#set the shop address fields
|
||||
my $address_key = $address_mappings->{$fieldName};
|
||||
$address->{$address_key} = $profile->{ $fieldName } if ($address_key);
|
||||
|
||||
#set the privacy settings
|
||||
my $privacySetting = $session->form->get("privacy_".$fieldName);
|
||||
next unless $privacySetting;
|
||||
$privacy->{$fieldName} = $privacySetting;
|
||||
}
|
||||
|
||||
$session->user->setProfileFieldPrivacySetting($privacy);
|
||||
|
||||
#Update or create and update the shop address
|
||||
if ( keys %$address ) {
|
||||
$address->{'isProfile' } = 1;
|
||||
|
||||
#Get the address book for the user (one is created if it does not exist)
|
||||
my $addressBook = WebGUI::Shop::AddressBook->newByUserId($session,$self->uid);
|
||||
my $profileAddress = eval { $addressBook->getProfileAddress() };
|
||||
|
||||
my $e;
|
||||
if($e = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound')) {
|
||||
#Get home address only mappings to avoid creating addresses with just firstName, lastName, email
|
||||
my %home_address_map = %{$address_mappings};
|
||||
foreach my $exclude ( qw{ firstName lastName email } ) {
|
||||
delete $home_address_map{$exclude};
|
||||
}
|
||||
#Add the profile address for the user if there are homeAddress fields
|
||||
if( grep { $address->{$_} } values %home_address_map ) {
|
||||
$address->{label} = "Profile Address";
|
||||
my $new_address = $addressBook->addAddress($address);
|
||||
#Set this as the default address if one doesn't already exist
|
||||
my $defaultAddress = eval{ $addressBook->getDefaultAddress };
|
||||
if(WebGUI::Error->caught('WebGUI::Error::ObjectNotFound')) {
|
||||
$addressBook->update( {
|
||||
defaultAddressId => $new_address->getId
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ($e = WebGUI::Error->caught) {
|
||||
#Bad stuff happened - log an error but don't fail since this isn't a vital function
|
||||
$session->log->error(
|
||||
q{Could not update Shop Profile Address for user }
|
||||
.$self->username.q{ : }.$e->error
|
||||
);
|
||||
}
|
||||
else {
|
||||
#Update the profile address for the user
|
||||
$profileAddress->update($address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Store the category the error occurred in the object for reference
|
||||
$self->store->{selected} = $retHash->{errorCategory};
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use base 'WebGUI::Asset::Sku';
|
|||
use JSON;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Shop::Admin;
|
||||
use WebGUI::Shop::AddressBook;
|
||||
use WebGUI::Utility;
|
||||
|
||||
|
|
@ -212,6 +213,28 @@ sub getMaxAllowedInCart {
|
|||
return 1;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getPostPurchaseActions ( item )
|
||||
|
||||
Return a hash reference of "label" => "url" to do things with this item after
|
||||
it is purchased. C<item> is the WebGUI::Shop::TransactionItem for this item
|
||||
|
||||
=cut
|
||||
|
||||
sub getPostPurchaseActions {
|
||||
my ( $self, $item ) = @_;
|
||||
my $session = $self->session;
|
||||
my $opts = $self->SUPER::getPostPurchaseActions();
|
||||
if($self->getParent->isRegistrationStaff) {
|
||||
my $i18n = WebGUI::International->new( $session, "Asset_EventManagementSystem" );
|
||||
my $badgeId = $item->get('options')->{badgeId};
|
||||
|
||||
$opts->{ $i18n->get('print') } = $self->getParent->getUrl( "func=printBadge;badgeId=$badgeId" );
|
||||
}
|
||||
return $opts;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getPrice
|
||||
|
|
@ -404,11 +427,19 @@ sub view {
|
|||
;
|
||||
|
||||
# instanciate address
|
||||
my $address = WebGUI::Shop::AddressBook->newByUserId($self->session)->getAddress($form->get("addressId")) if ($form->get("addressId"));
|
||||
my $address = undef;
|
||||
my $address_book = WebGUI::Shop::AddressBook->newByUserId($self->session);
|
||||
if ($form->get("addressId")) {
|
||||
$address = $address_book->getAddress($form->get("addressId"));
|
||||
}
|
||||
else {
|
||||
$address = eval{ $address_book->getDefaultAddress }
|
||||
}
|
||||
|
||||
# build the form that the user needs to fill out with badge holder information
|
||||
$vars{formHeader} = WebGUI::Form::formHeader($session, {action => $self->getUrl})
|
||||
. WebGUI::Form::hidden($session, {name=>"func", value =>'addToCart'});
|
||||
. WebGUI::Form::hidden($session, {name=>"func", value =>'addToCart'})
|
||||
. WebGUI::Form::hidden($session, {name=>"addressId", value=>(defined $address ? $address->getId : "" )});;
|
||||
$vars{formFooter} = WebGUI::Form::formFooter($session);
|
||||
$vars{name} = WebGUI::Form::text($session, {
|
||||
name => 'name',
|
||||
|
|
@ -457,9 +488,20 @@ sub view {
|
|||
if($self->getQuantityAvailable() > 0){
|
||||
$vars{submitAddress} = WebGUI::Form::submit($session, {value => $i18n->get('add to cart'),});
|
||||
}
|
||||
$vars{resetButton} = q{<input type="button" value="}.$i18n->get('clear form'). q{" onclick="WebGUI.Form.clearForm(this.form)" />};
|
||||
$vars{title} = $self->getTitle;
|
||||
$vars{description} = $self->get('description');
|
||||
|
||||
$vars{search_url } = $self->getUrl("shop=address;method=ajaxSearch");
|
||||
|
||||
my $shopAdmin = WebGUI::Shop::Admin->new($session);
|
||||
my $isStaff = $self->getParent->isRegistrationStaff;
|
||||
my $canManageShop = $shopAdmin->canManage;
|
||||
my $isCashier = $shopAdmin->isCashier;
|
||||
|
||||
if($isStaff && ($canManageShop || $isCashier)) {
|
||||
$vars{canSearch} = 1;
|
||||
}
|
||||
|
||||
# render the page;
|
||||
return $self->processTemplate(\%vars, undef, $self->{_viewTemplate});
|
||||
}
|
||||
|
|
@ -495,13 +537,46 @@ sub www_addToCart {
|
|||
if ($badgeInfo{name} eq "") {
|
||||
$error = sprintf $i18n->get('is required'), $i18n->get('name','Shop');
|
||||
}
|
||||
|
||||
|
||||
# return them back to the previous screen if they messed up
|
||||
if ($error) {
|
||||
$self->{_errorMessage} = $error;
|
||||
return $self->www_view($error);
|
||||
}
|
||||
|
||||
|
||||
#check to see if address has changed - if so, create a new address and set it to the default
|
||||
my $address_id = $form->get("addressId");
|
||||
if($address_id) {
|
||||
my $address = undef;
|
||||
my $address_book = WebGUI::Shop::AddressBook->newByUserId($self->session);
|
||||
$address = $address_book->getAddress($address_id);
|
||||
my $has_changes = 0;
|
||||
my $new_address = {};
|
||||
foreach my $field_name (qw/name address1 address2 address3 city state country code phoneNumber organization email/) {
|
||||
my $form_field_name = $field_name;
|
||||
$form_field_name = "zipcode" if ($field_name eq "code");
|
||||
if($field_name eq "name") {
|
||||
if($address->get('firstName')." ".$address->get('lastName') ne $badgeInfo{name}) {
|
||||
$has_changes = 1;
|
||||
}
|
||||
($new_address->{firstName},$new_address->{lastName}) = split(" ",$badgeInfo{name});
|
||||
next;
|
||||
}
|
||||
elsif($address->get($field_name) ne $badgeInfo{$form_field_name}) {
|
||||
$has_changes = 1;
|
||||
}
|
||||
$new_address->{$field_name} = $badgeInfo{$form_field_name};
|
||||
}
|
||||
|
||||
if($has_changes) {
|
||||
my $address_book = WebGUI::Shop::AddressBook->newByUserId($self->session);
|
||||
$new_address->{label} = $form->get("label")." New";
|
||||
my $new_address = $address_book->addAddress($new_address);
|
||||
$address_book->update({defaultAddressId => $new_address->getId });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# add it to the cart
|
||||
$self->addToCart(\%badgeInfo);
|
||||
return $self->getParent->www_buildBadge($self->getOptions->{badgeId});
|
||||
|
|
|
|||
|
|
@ -2594,15 +2594,52 @@ sub www_printBadge {
|
|||
my $session = $self->session;
|
||||
return $session->privilege->insufficient unless ($self->isRegistrationStaff);
|
||||
my $form = $session->form;
|
||||
my $registrant = $self->getRegistrant($form->get('badgeId'));
|
||||
my $badgeId = $form->get('badgeId');
|
||||
my $registrant = $self->getRegistrant($badgeId);
|
||||
my $badge = WebGUI::Asset::Sku::EMSBadge->new($session, $registrant->{badgeAssetId});
|
||||
$registrant->{badgeTitle} = $badge->getTitle;
|
||||
|
||||
# Add badge metadata
|
||||
my $meta = $badge->getMetaDataAsTemplateVariables;
|
||||
for my $key ( keys %{$meta} ) {
|
||||
$registrant->{ "badgeMeta_" . $key } = $meta->{ $key };
|
||||
}
|
||||
# Add badge metadata
|
||||
my $meta = $badge->getMetaDataAsTemplateVariables;
|
||||
for my $key ( keys %{$meta} ) {
|
||||
$registrant->{ "badgeMeta_" . $key } = $meta->{ $key };
|
||||
}
|
||||
|
||||
#Add tickets
|
||||
my @tickets = $session->db->buildArray(
|
||||
q{select ticketAssetId from EMSRegistrantTicket where badgeId=?},
|
||||
[$badgeId]
|
||||
);
|
||||
|
||||
$registrant->{ticket_loop} = [];
|
||||
foreach my $ticketId (@tickets) {
|
||||
my $ticket = WebGUI::Asset::Sku::EMSTicket->new($session, $ticketId);
|
||||
push (@{$registrant->{ticket_loop}}, $ticket->get);
|
||||
}
|
||||
|
||||
#Add ribbons
|
||||
my @ribbons = $session->db->buildArray(
|
||||
q{select ribbonAssetId from EMSRegistrantRibbon where badgeId=?},
|
||||
[$badgeId]
|
||||
);
|
||||
|
||||
$registrant->{ribbon_loop} = [];
|
||||
foreach my $ribbonId (@ribbons) {
|
||||
my $ribbon = WebGUI::Asset::Sku::EMSRibbon->new($session, $ribbonId);
|
||||
push (@{$registrant->{ribbon_loop}}, $ribbon->get);
|
||||
}
|
||||
|
||||
## Add tokens
|
||||
my @tokens = $session->db->buildArray(
|
||||
q{select tokenAssetId from EMSRegistrantToken where badgeId=?},
|
||||
[$badgeId]
|
||||
);
|
||||
|
||||
$registrant->{token_loop} = [];
|
||||
foreach my $tokenId (@tokens) {
|
||||
my $token = WebGUI::Asset::Sku::EMSRibbon->new($session, $tokenId);
|
||||
push (@{$registrant->{token_loop}}, $token->get);
|
||||
}
|
||||
|
||||
return $self->processTemplate($registrant,$self->get('printBadgeTemplateId'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use WebGUI::User;
|
|||
use WebGUI::Operation::Shared;
|
||||
use WebGUI::Operation::Profile;
|
||||
use WebGUI::Workflow::Instance;
|
||||
use WebGUI::Shop::AddressBook;
|
||||
use WebGUI::Inbox;
|
||||
use WebGUI::Friends;
|
||||
|
||||
|
|
@ -315,6 +316,35 @@ sub createAccountSave {
|
|||
}
|
||||
$u->karma($self->session->setting->get("karmaPerLogin"),"Login","Just for logging in.") if ($self->session->setting->get("useKarma"));
|
||||
$u->updateProfileFields($profile) if ($profile);
|
||||
#Update the shop address
|
||||
my $address = {};
|
||||
my $address_mappings = WebGUI::Shop::AddressBook->getProfileAddressMappings;
|
||||
foreach my $fieldId (keys %$profile) {
|
||||
#set the shop address fields
|
||||
my $address_key = $address_mappings->{$fieldId};
|
||||
$address->{$address_key} = $profile->{$fieldId} if ($address_key);
|
||||
}
|
||||
|
||||
#Update or create and update the shop address
|
||||
if ( keys %$address ) {
|
||||
$address->{'isProfile' } = 1;
|
||||
|
||||
#Get home address only mappings to avoid creating addresses with just firstName, lastName, email
|
||||
my %home_address_map = %{$address_mappings};
|
||||
foreach my $exclude ( qw{ firstName lastName email } ) {
|
||||
delete $home_address_map{$exclude};
|
||||
}
|
||||
#Add the profile address for the user if there are homeAddress fields
|
||||
if( grep { $address->{$_} } values %home_address_map ) {
|
||||
#Create the address book for the user
|
||||
my $addressBook = WebGUI::Shop::AddressBook->newByUserId($self->session,$userId);
|
||||
$address->{label} = "Profile Address";
|
||||
my $new_address = $addressBook->addAddress($address);
|
||||
#Set this as the default address if one doesn't already exist
|
||||
$addressBook->update( { defaultAddressId => $new_address->getId } );
|
||||
}
|
||||
}
|
||||
|
||||
$self->saveParams($userId,$self->authMethod,$properties);
|
||||
|
||||
if ($self->getSetting("sendWelcomeMessage")){
|
||||
|
|
|
|||
|
|
@ -805,7 +805,7 @@ sub www_editUserSave {
|
|||
|
||||
return $session->privilege->adminOnly() unless ($isAdmin || $isSecondary) && $session->form->validToken;
|
||||
|
||||
# Check to see if
|
||||
# Check to see if
|
||||
# 1) the userId associated with the posted username matches the posted userId (we're editing an account)
|
||||
# or that the userId is new and the username selected is unique (creating new account)
|
||||
# or that the username passed in isn't assigned a userId (changing a username)
|
||||
|
|
@ -816,11 +816,11 @@ sub www_editUserSave {
|
|||
my $postedUsername = $session->form->process("username");
|
||||
$postedUsername = WebGUI::HTML::filter($postedUsername, "all");
|
||||
|
||||
if (($existingUserId eq $postedUserId || ($postedUserId eq "new" && !$existingUserId) || $existingUserId eq '')
|
||||
if (($existingUserId eq $postedUserId || ($postedUserId eq "new" && !$existingUserId) || $existingUserId eq '')
|
||||
&& $postedUsername ne '')
|
||||
{
|
||||
# Create a user object with the id passed in. If the Id is 'new', the new method will return a new user,
|
||||
# otherwise return the existing users properties
|
||||
# Create a user object with the id passed in. If the Id is 'new', the new method will return a new user,
|
||||
# otherwise return the existing users properties
|
||||
my $u = WebGUI::User->new($session,$postedUserId);
|
||||
$actualUserId = $u->userId;
|
||||
|
||||
|
|
@ -838,10 +838,58 @@ sub www_editUserSave {
|
|||
}
|
||||
|
||||
# Loop through all profile fields, and update them with new values.
|
||||
foreach my $field (@{WebGUI::ProfileField->getFields($session)}) {
|
||||
my $address = {};
|
||||
my $address_mappings = WebGUI::Shop::AddressBook->getProfileAddressMappings;
|
||||
foreach my $field (@{WebGUI::ProfileField->getFields($session)}) {
|
||||
next if $field->getId =~ /contentPositions/;
|
||||
$u->profileField($field->getId,$field->formProcess($u));
|
||||
my $field_value = $field->formProcess($u);
|
||||
$u->profileField($field->getId,$field_value);
|
||||
|
||||
#set the shop address fields
|
||||
my $address_key = $address_mappings->{$field->getId};
|
||||
$address->{$address_key} = $field_value if ($address_key);
|
||||
}
|
||||
|
||||
#Update or create and update the shop address
|
||||
if ( keys %$address ) {
|
||||
$address->{'isProfile' } = 1;
|
||||
|
||||
#Get the address book for the user (one is created if it does not exist)
|
||||
my $addressBook = WebGUI::Shop::AddressBook->newByUserId($session,$actualUserId);
|
||||
my $profileAddress = eval { $addressBook->getProfileAddress() };
|
||||
|
||||
my $e;
|
||||
if($e = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound')) {
|
||||
#Get home address only mappings to avoid creating addresses with just firstName, lastName, email
|
||||
my %home_address_map = %{$address_mappings};
|
||||
foreach my $exclude ( qw{ firstName lastName email } ) {
|
||||
delete $home_address_map{$exclude};
|
||||
}
|
||||
#Add the profile address for the user if there are homeAddress fields
|
||||
if( grep { $address->{$_} } values %home_address_map ) {
|
||||
$address->{label} = "Profile Address";
|
||||
my $new_address = $addressBook->addAddress($address);
|
||||
#Set this as the default address if one doesn't already exist
|
||||
my $defaultAddress = eval{ $addressBook->getDefaultAddress };
|
||||
if(WebGUI::Error->caught('WebGUI::Error::ObjectNotFound')) {
|
||||
$addressBook->update( {
|
||||
defaultAddressId => $new_address->getId
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ($e = WebGUI::Error->caught) {
|
||||
#Bad stuff happened - log an error but don't fail since this isn't a vital function
|
||||
$session->log->error(
|
||||
q{Could not update Shop Profile Address for user }
|
||||
.$u->username.q{ : }.$e->error
|
||||
);
|
||||
}
|
||||
else {
|
||||
#Update the profile address for the user
|
||||
$profileAddress->update($address);
|
||||
}
|
||||
}
|
||||
|
||||
# Update group assignements
|
||||
my @groups = $session->form->group("groupsToAdd");
|
||||
|
|
|
|||
|
|
@ -153,6 +153,19 @@ sub getId {
|
|||
return $self->get("addressId");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isProfile ()
|
||||
|
||||
Returns 1 if the address is linked to the user's profile.
|
||||
|
||||
=cut
|
||||
|
||||
sub isProfile {
|
||||
my $self = shift;
|
||||
return ($self->get("isProfile") eq 1);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -192,7 +205,6 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update ( properties )
|
||||
|
|
@ -259,16 +271,20 @@ The organization or company that this user is a part of.
|
|||
|
||||
The address book that this address belongs to.
|
||||
|
||||
=head4 isProfile
|
||||
|
||||
Whether or not this address is linked to the user profile. Defaults to 0
|
||||
|
||||
=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)) {
|
||||
|
||||
foreach my $field (qw(addressBookId email organization address1 address2 address3 state code city label firstName lastName country phoneNumber isProfile)) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->addressBook->session->db->setRow("address","addressId",$properties{$id});
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use WebGUI::Asset::Template;
|
|||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Shop::Admin;
|
||||
use WebGUI::Shop::Address;
|
||||
use Scalar::Util qw/blessed/;
|
||||
|
||||
|
|
@ -195,6 +196,11 @@ C<update> method.
|
|||
|
||||
sub get {
|
||||
my ($self, $name) = @_;
|
||||
if($name eq "profileAddressId" && !$properties{id $self}{$name}) {
|
||||
$properties{id $self}{$name} = $self->session->db->quickScalar(q{
|
||||
select addressId from address where addressBookId=? and isProfile=1
|
||||
},[$self->getId]);
|
||||
}
|
||||
if (defined $name) {
|
||||
return $properties{id $self}{$name};
|
||||
}
|
||||
|
|
@ -295,6 +301,55 @@ sub getDefaultAddress {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getProfileAddress ()
|
||||
|
||||
Returns the profile address for this address book if there is one. Otherwise throws a WebGUI::Error::ObjectNotFound exception.
|
||||
|
||||
=cut
|
||||
|
||||
sub getProfileAddress {
|
||||
my ($self) = @_;
|
||||
my $id = $self->get('profileAddressId');
|
||||
if ($id ne '') {
|
||||
my $address = eval { $self->getAddress($id) };
|
||||
my $e;
|
||||
if ($e = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound')) {
|
||||
$e->rethrow;
|
||||
}
|
||||
elsif ($e = WebGUI::Error->caught) {
|
||||
$e->rethrow;
|
||||
}
|
||||
else {
|
||||
return $address;
|
||||
}
|
||||
}
|
||||
WebGUI::Error::ObjectNotFound->throw(error=>"No profile address.");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getProfileAddressMappings ( )
|
||||
|
||||
Class or object method which returns the profile address field mappings
|
||||
|
||||
=cut
|
||||
|
||||
sub getProfileAddressMappings {
|
||||
return {
|
||||
homeAddress => 'address1',
|
||||
homeCity => 'city',
|
||||
homeState => 'state',
|
||||
homeZip => 'code',
|
||||
homeCountry => 'country',
|
||||
homePhone => 'phoneNumber',
|
||||
email => 'email',
|
||||
firstName => 'firstName',
|
||||
lastName => 'lastName'
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id for this addressBook.
|
||||
|
|
@ -419,7 +474,7 @@ sub newByUserId {
|
|||
}
|
||||
else {
|
||||
# nope create one for the user
|
||||
return $class->create($session);
|
||||
return $class->create($session,$userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -442,19 +497,19 @@ sub processAddressForm {
|
|||
$prefix ||= '';
|
||||
my $form = $self->session->form;
|
||||
my %addressData = (
|
||||
label => $form->get($prefix . "label"),
|
||||
firstName => $form->get($prefix . "firstName"),
|
||||
lastName => $form->get($prefix . "lastName"),
|
||||
address1 => $form->get($prefix . "address1"),
|
||||
address2 => $form->get($prefix . "address2"),
|
||||
address3 => $form->get($prefix . "address3"),
|
||||
city => $form->get($prefix . "city"),
|
||||
state => $form->get($prefix . "state"),
|
||||
code => $form->get($prefix . "code", "zipcode"),
|
||||
country => $form->get($prefix . "country", "country"),
|
||||
phoneNumber => $form->get($prefix . "phoneNumber", "phone"),
|
||||
email => $form->get($prefix . "email", "email"),
|
||||
organization => $form->get($prefix . "organization"),
|
||||
label => $form->get($prefix . "label") || '',
|
||||
firstName => $form->get($prefix . "firstName") || '',
|
||||
lastName => $form->get($prefix . "lastName") || '',
|
||||
address1 => $form->get($prefix . "address1") || '',
|
||||
address2 => $form->get($prefix . "address2") || '',
|
||||
address3 => $form->get($prefix . "address3") || '',
|
||||
city => $form->get($prefix . "city") || '',
|
||||
state => $form->get($prefix . "state") || '',
|
||||
code => $form->get($prefix . "code", "zipcode") || '',
|
||||
country => $form->get($prefix . "country", "country") || '',
|
||||
phoneNumber => $form->get($prefix . "phoneNumber", "phone") || '',
|
||||
email => $form->get($prefix . "email", "email") || '',
|
||||
organization => $form->get($prefix . "organization") || '',
|
||||
);
|
||||
|
||||
##Label is optional in the form, but required for the UI and API.
|
||||
|
|
@ -489,9 +544,26 @@ sub update {
|
|||
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});
|
||||
|
||||
my %postProperties = %{$properties{$id}};
|
||||
delete $postProperties{profileAddressId};
|
||||
$self->session->db->setRow("addressBook","addressBookId",\%postProperties);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 uncache ( )
|
||||
|
||||
Deletes the addressBook cache
|
||||
|
||||
=cut
|
||||
|
||||
sub uncache {
|
||||
my $self = shift;
|
||||
delete $addressCache{id $self};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_ajaxGetAddress ( )
|
||||
|
|
@ -536,6 +608,80 @@ sub www_ajaxSave {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_ajaxSearch ( )
|
||||
|
||||
Gets a JSON object with addresses returned based on the search
|
||||
parameters from the form.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_ajaxSearch {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $session->form;
|
||||
|
||||
my $name = $form->get('name');
|
||||
my $fields = {
|
||||
firstName => (split(" ",$name))[0] || "",
|
||||
lastName => (split(" ",$name))[1] || "",
|
||||
organization => $form->get('organization') || "",
|
||||
address1 => $form->get('address1') || "",
|
||||
address2 => $form->get('address2') || "",
|
||||
address3 => $form->get('address3') || "",
|
||||
city => $form->get('city') || "",
|
||||
state => $form->get('state') || "",
|
||||
code => $form->get('zipcode') || "",
|
||||
country => $form->get('country') || "",
|
||||
email => $form->get('email') || "",
|
||||
phoneNumber => $form->get('phone') || "",
|
||||
};
|
||||
|
||||
my $clause = [];
|
||||
my $params = [];
|
||||
|
||||
foreach my $field (keys %$fields) {
|
||||
my $field_value = $fields->{$field};
|
||||
if($field_value) {
|
||||
$field = $session->db->dbh->quote_identifier($field);
|
||||
$field_value = $field_value."%";
|
||||
push(@$clause,qq{$field like ?});
|
||||
push(@$params,$field_value);
|
||||
}
|
||||
}
|
||||
|
||||
my $admin = WebGUI::Shop::Admin->new($session);
|
||||
unless ($session->user->isAdmin || $admin->canManage || $admin->isCashier) {
|
||||
push(@$clause,qq{users.userId=?});
|
||||
push(@$params,$session->user->getId);
|
||||
}
|
||||
|
||||
my $where = "";
|
||||
$where = "where ".join(" and ",@$clause) if scalar(@$clause);
|
||||
|
||||
my $query = qq{
|
||||
select
|
||||
address.*,
|
||||
users.username
|
||||
from
|
||||
address
|
||||
join addressBook on address.addressBookId = addressBook.addressBookId
|
||||
join users on addressBook.userId = users.userId
|
||||
$where
|
||||
limit 3
|
||||
};
|
||||
|
||||
my $sth = $session->db->read($query,$params);
|
||||
my $var = [];
|
||||
while (my $hash = $sth->hashRef) {
|
||||
push(@$var,$hash);
|
||||
}
|
||||
|
||||
$session->http->setMimeType('text/plain');
|
||||
return JSON->new->encode($var);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_deleteAddress ( )
|
||||
|
||||
Deletes an address from the book.
|
||||
|
|
@ -544,7 +690,10 @@ Deletes an address from the book.
|
|||
|
||||
sub www_deleteAddress {
|
||||
my $self = shift;
|
||||
$self->getAddress($self->session->form->get("addressId"))->delete;
|
||||
my $address = $self->getAddress($self->session->form->get("addressId"));
|
||||
if (defined $address && !$address->isProfile) {
|
||||
$address->delete;
|
||||
}
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
|
|
@ -700,8 +849,20 @@ sub www_editAddressSave {
|
|||
$self->addAddress(\%addressData);
|
||||
}
|
||||
else {
|
||||
$self->getAddress($form->get('addressId'))->update(\%addressData);
|
||||
my $addressId = $form->get('addressId');
|
||||
my $address = $self->getAddress($addressId);
|
||||
$address->update(\%addressData);
|
||||
if($address->isProfile) {
|
||||
my $u = WebGUI::User->new($self->session, $self->get("userId"));
|
||||
my $address_mappings = $self->getProfileAddressMappings;
|
||||
foreach my $field (keys %$address_mappings) {
|
||||
my $addr_field = $address_mappings->{$field};
|
||||
$u->profileField($field,$address->get($addr_field));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#profile fields updated in WebGUI::Shop::Address->update
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
|
|
@ -732,12 +893,12 @@ sub www_view {
|
|||
return $self->www_editAddress;
|
||||
}
|
||||
foreach my $address (@availableAddresses) {
|
||||
|
||||
push(@addresses, {
|
||||
%{$address->get},
|
||||
address => $address->getHtmlFormatted,
|
||||
isDefault => ($self->get('defaultAddressId') eq $address->getId),
|
||||
deleteButton =>
|
||||
WebGUI::Form::formHeader( $session )
|
||||
deleteButton => $address->get("isProfile") ? undef : WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, { name => 'shop', value => 'address' } )
|
||||
. WebGUI::Form::hidden( $session, { name => 'method', value => 'deleteAddress' } )
|
||||
. WebGUI::Form::hidden( $session, { name => 'addressId', value => $address->getId } )
|
||||
|
|
|
|||
|
|
@ -1054,6 +1054,13 @@ sub www_view {
|
|||
$self->update({shippingAddressId=>''});
|
||||
}
|
||||
|
||||
#get the billing address
|
||||
my $billingAddress = eval { $self->getBillingAddress };
|
||||
if (my $e = WebGUI::Error->caught("WebGUI::Error::ObjectNotFound") && $self->get('billingAddressId')) {
|
||||
# choose another address cuz we've got a problem
|
||||
$self->update({billingAddressId=>''});
|
||||
}
|
||||
|
||||
# generate template variables for the items in the cart
|
||||
my @items = ();
|
||||
tie my %addressOptions, 'Tie::IxHash';
|
||||
|
|
@ -1215,9 +1222,11 @@ sub www_view {
|
|||
$addressBook->appendAddressFormVars(\%var, 'shipping_', $shippingAddressData);
|
||||
$addressBook->appendAddressFormVars(\%var, 'billing_', $billingAddressData);
|
||||
|
||||
my $has_billing_addr - $self->get('billingAddressId') ? 1 : 0;
|
||||
|
||||
$var{sameShippingAsBilling} = WebGUI::Form::yesNo($session, {
|
||||
name => 'sameShippingAsBilling',
|
||||
value => $self->get('billingAddressId') && $self->get('billingAddressId') eq $self->get('shippingAddressId'),
|
||||
value => (($has_billing_addr && $self->get('billingAddressId') eq $self->get('shippingAddressId')) || !$has_billing_addr),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1422,27 +1422,28 @@ sub update {
|
|||
delete $properties->{wg_privacySettings};
|
||||
|
||||
# $self->{_user} contains all fields in `users` table
|
||||
my @userFields = ();
|
||||
my @userValues = ();
|
||||
my @userFields = ();
|
||||
my @userValues = ();
|
||||
for my $key ( keys %{$self->{_user}} ) {
|
||||
if ( exists $properties->{$key} ) {
|
||||
# Delete the value because it's not a profile field
|
||||
my $value = delete $properties->{$key};
|
||||
my $value = delete $properties->{$key};
|
||||
push @userFields, $db->dbh->quote_identifier( $key ) . " = ?";
|
||||
push @userValues, $value;
|
||||
$self->{_user}->{$key} = $value;
|
||||
}
|
||||
}
|
||||
# No matter what we update properties
|
||||
my $userFields = join ", ", @userFields;
|
||||
my $userFields = join ", ", @userFields;
|
||||
$db->write(
|
||||
"UPDATE users SET $userFields WHERE userId=?",
|
||||
[@userValues, $self->{_userId}]
|
||||
);
|
||||
|
||||
# Everything else must be a profile field
|
||||
my @profileFields = ();
|
||||
my @profileValues = ();
|
||||
my @profileFields = ();
|
||||
my @profileValues = ();
|
||||
|
||||
for my $key ( keys %{$properties} ) {
|
||||
if (!exists $self->{_profile}{$key} && !WebGUI::ProfileField->exists($session,$key)) {
|
||||
$self->session->errorHandler->warn("No such profile field: $key");
|
||||
|
|
@ -1453,7 +1454,7 @@ sub update {
|
|||
$self->{_profile}->{$key} = $properties->{ $key };
|
||||
}
|
||||
if ( @profileFields ) {
|
||||
my $profileFields = join ", ", @profileFields;
|
||||
my $profileFields = join ", ", @profileFields;
|
||||
$db->write(
|
||||
"UPDATE userProfileData SET $profileFields WHERE userId=?",
|
||||
[@profileValues, $self->{_userId}]
|
||||
|
|
|
|||
|
|
@ -2307,6 +2307,12 @@ normal templates.|,
|
|||
context => q{Error message when trying to add too many tickets to a badge},
|
||||
},
|
||||
|
||||
'clear form' => {
|
||||
message => q|Clear|,
|
||||
lastUpdated => 0,
|
||||
context => q|a button on the add badge to clear the form|,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue