Skip to content

Commit

Permalink
Cache single pickup location result when updating from list.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Jul 19, 2024
1 parent d5354cf commit fe57226
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ShippingProvider/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ public function get_pickup_locations( $address, $query_args = array() ) {
$cache_key = $this->get_pickup_locations_cache_key( $address, $query_args['limit'] );
$pickup_locations = get_transient( $cache_key );
$address = $this->parse_pickup_location_address_args( $address );
$pickup_locations = false;

if ( false === $pickup_locations && ( ! empty( $address['postcode'] ) || ! empty( $address['city'] ) ) ) {
$pickup_locations = $this->fetch_pickup_locations( $address, $query_args );
Expand All @@ -632,6 +631,13 @@ public function get_pickup_locations( $address, $query_args = array() ) {
*/
if ( ! empty( $pickup_locations ) ) {
foreach ( $pickup_locations as $k => $pickup_location ) {
$cache_key = $this->get_pickup_location_cache_key( $pickup_location->get_id(), $pickup_location->get_address() );
$single_cached_pickup_location = get_transient( $cache_key );

if ( false === $single_cached_pickup_location ) {
set_transient( $cache_key, $single_cached_pickup_location, DAY_IN_SECONDS );
}

if ( ! $pickup_location->supports_cart( $query_args ) ) {
unset( $pickup_locations[ $k ] );
}
Expand Down
12 changes: 12 additions & 0 deletions src/ShippingProvider/PickupLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public function get_address() {
return $this->address;
}

public function get_postcode() {
return $this->address['postcode'];
}

public function get_country() {
return $this->address['country'];
}

public function get_city() {
return $this->address['city'];
}

public function supports_customer_number() {
return $this->supports_customer_number;
}
Expand Down

0 comments on commit fe57226

Please sign in to comment.