agent-virtualize credit card surcharge percentage, RT#72961
[freeside.git] / FS / FS / location_Mixin.pm
index d457386..b010374 100644 (file)
@@ -11,9 +11,20 @@ Returns the location object, if any (see L<FS::cust_location>).
 =cut
 
 sub cust_location {
-  my $self = shift;
+  my( $self, %opt ) = @_;
+
   return '' unless $self->locationnum;
-  qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
+
+  return $opt{_cache}->{$self->locationnum}
+    if $opt{_cache} && $opt{_cache}->{$self->locationnum};
+
+  my $cust_location = 
+    qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
+
+  $opt{_cache}->{$self->locationnum} = $cust_location
+     if $opt{_cache};
+  
+  $cust_location;
 }
 
 =item cust_location_or_main
@@ -25,7 +36,7 @@ L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
 
 sub cust_location_or_main {
   my $self = shift;
-  $self->cust_location || $self->cust_main;
+  $self->cust_location(@_) || $self->cust_main;
 }
 
 =item location_label [ OPTION => VALUE ... ]
@@ -36,7 +47,7 @@ Returns the label of the location object (see L<FS::cust_location>).
 
 sub location_label {
   my $self = shift;
-  my $object = $self->cust_location_or_main;
+  my $object = $self->cust_location_or_main or return '';
   $object->location_label(@_);
 }