Merge branch 'patch-1' of https://github.com/gjones2/Freeside
[freeside.git] / httemplate / misc / xmlhttp-address_standardize.html
index f53c35f..9880571 100644 (file)
@@ -16,8 +16,16 @@ my %old = %{ decode_json($cgi->param('arg')) }
 
 my %new;
 
-foreach my $pre ( '', 'ship_' ) {
-  next unless ($pre || !$old{onlyship});
+my @prefixes;
+if ($old{onlyship}) {
+  @prefixes = ('ship_');
+} elsif ( $old{same} ) {
+  @prefixes = ('bill_');
+} else {
+  @prefixes = ('bill_', 'ship_');
+}
+my $all_same = 1;
+foreach my $pre ( @prefixes ) {
 
   my $location = {
     map { $_ => $old{$pre.$_} }
@@ -31,8 +39,13 @@ foreach my $pre ( '', 'ship_' ) {
   foreach ( keys(%$cache) ) {
     $new{$pre.$_} = $cache->get($_);
   }
+
+  foreach ( qw(address1 address2 city state zip country) ) {
+    $all_same = 0 if ( $new{$pre.$_} ne $old{$pre.$_} );
+    last if !$all_same;
+  }
 }
 
-my $return = { old => \%old, new => \%new };
+my $return = { old => \%old, new => \%new, all_same => $all_same };
 warn "result:\n".encode_json($return) if $DEBUG;
 </%init>