address —
Interchange 5.9.0:
Source: lib/Vend/Interpolate.pm
Lines: 3912
sub tag_address {
my ($count, $item, $hash, $opt, $body) = @_;
#::logDebug("in ship_address");
return pull_else($body) if defined $opt->{if} and ! $opt->{if};
return pull_else($body) if ! $Vend::username || ! $Vend::Session->{logged_in};
#::logDebug("logged in with usernam=$Vend::username");
my $tag = 'address';
my $attr = 'mv_ad';
my $nattr = 'mv_an';
my $pre = '';
if($opt->{billing}) {
$tag = 'b_address';
$attr = 'mv_bd';
$nattr = 'mv_bn';
$pre = 'b_';
}
# if($item->{$attr} and ! $opt->{set}) {
# my $pre = $opt->{prefix};
# $pre =~ s/[-_]/[-_]/g;
# $body =~ s:\[$pre\]($Some)\[/$pre\]:$item->{$attr}:g;
# return pull_if($body);
# }
my $nick = $opt->{nick} || $opt->{nickname} || $item->{$nattr};
#::logDebug("nick=$nick");
my $user;
if(not $user = $Vend::user_object) {
$user = new Vend::UserDB username => ($opt->{username} || $Vend::username);
}
#::logDebug("user=$user");
! $user and return pull_else($body);
my $blob = $user->get_hash('SHIPPING') or return pull_else($body);
#::logDebug("blob=$blob");
my $addr = $blob->{$nick};
if (! $addr) {
%$addr = %{ $::Values };
}
#::logDebug("addr=" . uneval($addr));
$addr->{mv_an} = $nick;
my @nick = sort keys %$blob;
my $label;
if($label = $opt->{address_label}) {
@nick = sort { $blob->{$a}{$label} cmp $blob->{$a}{$label} } @nick;
@nick = map { "$_=" . ($blob->{$_}{$label} || $_) } @nick;
for(@nick) {
s/,/,/g;
}
}
$opt->{blank} = '--select--' unless $opt->{blank};
unshift(@nick, "=$opt->{blank}");
$opt->{address_book} = join ",", @nick
unless $opt->{address_book};
my $joiner = get_joiner($opt->{joiner}, "<br$Vend::Xtrailer>");
if(! $opt->{no_address}) {
my @vals = map { $addr->{$_} }
grep /^address_?\d*$/ && length($addr->{$_}), keys %$addr;
$addr->{address} = join $joiner, @vals;
}
if($opt->{widget}) {
$addr->{address_book} = tag_accessories(
$item->{code},
undef,
{
attribute => $nattr,
type => $opt->{widget},
passed => $opt->{address_book},
form => $opt->{form},
},
$item
);
}
if($opt->{set} || ! $item->{$attr}) {
my $template = '';
if($::Variable->{MV_SHIP_ADDRESS_TEMPLATE}) {
$template .= $::Variable->{MV_SHIP_ADDRESS_TEMPLATE};
}
else {
$template .= "{company}\n" if $addr->{"${pre}company"};
$template .= <<EOF;
{address}
{city}, {state} {zip}
{country} -- {phone_day}
EOF
}
$template =~ s/{(\w+.*?)}/{$pre$1}/g if $pre;
$addr->{mv_ad} = $item->{$attr} = tag_attr_list($template, $addr);
}
else {
$addr->{mv_ad} = $item->{$attr};
}
if($opt->{textarea}) {
$addr->{textarea} = tag_accessories(
$item->{code},
undef,
{
attribute => $attr,
type => 'textarea',
rows => $opt->{rows} || '4',
cols => $opt->{cols} || '40',
},
$item
);
}
$body =~ s:\[$tag\]($Some)\[/$tag\]:tag_attr_list($1, $addr):eg;
return pull_if($body);
}