Changeset 2103605
- Timestamp:
- 06/10/2019 11:46:12 PM (7 years ago)
- Location:
- woocommerce-accommodation-bookings/trunk
- Files:
-
- 5 edited
-
changelog.txt (modified) (1 diff)
-
includes/class-wc-accommodation-booking.php (modified) (2 diffs)
-
includes/class-wc-product-accommodation-booking.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
woocommerce-accommodation-bookings.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-accommodation-bookings/trunk/changelog.txt
r2100652 r2103605 1 1 *** Changelog *** 2 3 = 1.1.8 - 2019-06-10 = 4 * Fix - Adds accommodation bookings support for WooCommerce Bookings Availability extension 2 5 3 6 = 1.1.7 - 2019-06-03 = -
woocommerce-accommodation-bookings/trunk/includes/class-wc-accommodation-booking.php
r1919134 r2103605 18 18 add_filter( 'get_booking_products_terms', array( $this, 'add_accommodation_to_booking_product_terms' ) ); 19 19 add_filter( 'get_booking_products_args', array( $this, 'add_accommodation_to_booking_products_args' ) ); 20 add_filter( 'woocommerce_bookings_product_rest_endpoint', array( $this, 'add_accommodation_to_booking_products_args' ) ); 21 add_filter( 'get_booking_products_args_for_slots_rest_endpoint', array( $this, 'add_accommodation_to_booking_products_args' ) ); 22 add_filter( 'woocommerce_bookings_product_type_rest_check', array( $this, 'validate_rest_product_type' ), 10, 2 ); 20 23 21 24 add_action( 'woocommerce_new_booking', array( $this, 'update_start_end_time' ) ); … … 43 46 $types[] = 'accommodation-booking'; 44 47 return $types; 48 } 49 50 /** 51 * Hooks into woocommerce_bookings_product_type_rest_check and verifies that product is a correct bookings type 52 */ 53 public function validate_rest_product_type( $is_product_valid, $product ) { 54 return $is_product_valid || 'accommodation-booking' === $product->get_type(); 45 55 } 46 56 -
woocommerce-accommodation-bookings/trunk/includes/class-wc-product-accommodation-booking.php
r2100652 r2103605 188 188 189 189 /** 190 * Find available and booked blocks for specific resources (if any) and return them as array. 191 * 192 * @param array $blocks 193 * @param array $intervals 194 * @param integer $resource_id 195 * @param integer $from The starting date for the set of blocks 196 * @param integer $to 197 * @return array 198 */ 199 public function get_time_slots( $blocks, $resource_id = 0, $from = 0, $to = 0, $include_sold_out = false ) { 200 $bookable_product = $this; 201 202 $transient_name = 'book_ts_' . md5( http_build_query( array( $bookable_product->get_id(), $resource_id, $from, $to ) ) ); 203 $available_slots = get_transient( $transient_name ); 204 $booking_slots_transient_keys = array_filter( (array) get_transient( 'booking_slots_transient_keys' ) ); 205 206 if ( ! isset( $booking_slots_transient_keys[ $bookable_product->get_id() ] ) ) { 207 $booking_slots_transient_keys[ $bookable_product->get_id() ] = array(); 208 } 209 210 $booking_slots_transient_keys[ $bookable_product->get_id() ][] = $transient_name; 211 212 // Give array of keys a long ttl because if it expires we won't be able to flush the keys when needed. 213 // We can't use 0 to never expire because then WordPress will autoload the option on every page. 214 set_transient( 'booking_slots_transient_keys', $booking_slots_transient_keys, YEAR_IN_SECONDS ); 215 216 if ( false === $available_slots ) { 217 if ( empty( $intervals ) ) { 218 $interval = $bookable_product->get_min_duration(); 219 $intervals = array( $interval, 1 ); 220 } 221 222 list( $interval, $base_interval ) = $intervals; 223 224 $existing_bookings = WC_Bookings_Controller::get_all_existing_bookings( $bookable_product, $from, $to ); 225 226 $booking_resource = $resource_id ? $bookable_product->get_resource( $resource_id ) : null; 227 $available_slots = array(); 228 $has_qty = ! is_null( $booking_resource ) ? $booking_resource->has_qty() : false; 229 $has_resources = $bookable_product->has_resources(); 230 231 foreach ( $blocks as $block ) { 232 $check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' ); 233 $check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' ); 234 // Blocks for accommodation products are initially calculated as days but the actuall time blocks are shifted by check in and checkout times. 235 $block_start_time = strtotime( "{$check_in}", $block ); 236 $block_end_time = strtotime( "{$check_out}", strtotime( "+1 days", $block ) ); 237 $resources = array(); 238 239 // Figure out how much qty have, either based on combined resource quantity, 240 // single resource, or just product. 241 if ( $has_resources && ( ! is_a( $booking_resource, 'WC_Product_Booking_Resource' ) || ! $has_qty ) ) { 242 $available_qty = 0; 243 244 foreach ( $bookable_product->get_resources() as $resource ) { 245 246 if ( ! $bookable_product->check_availability_rules_against_time( $block_start_time, $block_end_time, $block, $resource->get_id() ) ) { 247 continue; 248 } 249 250 $qty = $resource->get_qty(); 251 $available_qty += $qty; 252 $resources[ $resource->get_id() ] = $qty; 253 } 254 } elseif ( $has_resources && $has_qty ) { 255 // Only include if it is available for this selection. We set this block to be bookable by default, unless some of the rules apply. 256 if ( ! $bookable_product->check_availability_rules_against_time( $block_start_time, $block_end_time, $booking_resource->get_id() ) ) { 257 continue; 258 } 259 260 $qty = $booking_resource->get_qty(); 261 $available_qty = $qty; 262 $resources[ $booking_resource->get_id() ] = $qty; 263 } else { 264 $available_qty = $bookable_product->get_qty(); 265 $resources[0] = $bookable_product->get_qty(); 266 } 267 268 $qty_booked_in_block = 0; 269 270 foreach ( $existing_bookings as $existing_booking ) { 271 if ( $existing_booking->is_within_block( $block_start_time, $block_end_time ) ) { 272 $qty_to_add = $bookable_product->has_person_qty_multiplier() ? max( 1, array_sum( $existing_booking->get_persons() ) ) : 1; 273 if ( $has_resources ) { 274 if ( $existing_booking->get_resource_id() === absint( $resource_id ) ) { 275 // Include the quantity to subtract if an existing booking matches the selected resource id 276 $qty_booked_in_block += $qty_to_add; 277 $resources[ $resource_id ] = ( isset( $resources[ $resource_id ] ) ? $resources[ $resource_id ] : 0 ) - $qty_to_add; 278 } elseif ( ( is_null( $booking_resource ) || ! $has_qty ) && $existing_booking->get_resource() ) { 279 // Include the quantity to subtract if the resource is auto selected (null/resource id empty) 280 // but the existing booking includes a resource 281 $qty_booked_in_block += $qty_to_add; 282 $resources[ $existing_booking->get_resource_id() ] = ( isset( $resources[ $existing_booking->get_resource_id() ] ) ? $resources[ $existing_booking->get_resource_id() ] : 0 ) - $qty_to_add; 283 } 284 } else { 285 $qty_booked_in_block += $qty_to_add; 286 $resources[0] = ( isset( $resources[0] ) ? $resources[0] : 0 ) - $qty_to_add; 287 } 288 } 289 } 290 291 $available_slots[ $block ] = array( 292 'booked' => $qty_booked_in_block, 293 'available' => $available_qty - $qty_booked_in_block, 294 'resources' => $resources, 295 ); 296 } 297 298 299 set_transient( $transient_name, $available_slots ); 300 } 301 302 return $available_slots; 303 } 304 305 306 /** 190 307 * Get an array of blocks within in a specified date range 191 308 * -
woocommerce-accommodation-bookings/trunk/readme.txt
r2100652 r2103605 4 4 Requires at least: 4.1 5 5 Tested up to: 5.0 6 Stable tag: 1.1. 76 Stable tag: 1.1.8 7 7 License: GNU General Public License v3.0 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 37 37 == Changelog == 38 38 39 = 1.1.8 - 2019-06-10 = 40 * Fix - Adds accommodation bookings support for WooCommerce Bookings Availability extension 41 39 42 = 1.1.7 - 2019-06-03 = 40 43 * Fix - Mismatch function declaration causing PHP warnings. -
woocommerce-accommodation-bookings/trunk/woocommerce-accommodation-bookings.php
r2100652 r2103605 4 4 * Plugin URI: https://woocommerce.com/products/woocommerce-accommodation-bookings/ 5 5 * Description: An accommodations add-on for the WooCommerce Bookings extension. 6 * Version: 1.1. 76 * Version: 1.1.8 7 7 * Author: WooCommerce 8 8 * Author URI: https://woocommerce.com … … 22 22 23 23 require_once( 'includes/class-wc-accommodation-bookings-plugin.php' ); 24 $plugin = new WC_Accommodation_Bookings_Plugin( __FILE__, '1.1. 7' );24 $plugin = new WC_Accommodation_Bookings_Plugin( __FILE__, '1.1.8' ); 25 25 $plugin->run();
Note: See TracChangeset
for help on using the changeset viewer.