woocommerce / woocommerce-accommodation-bookings

An accommodations add-on for the WooCommerce Bookings extension.
87 stars 31 forks source link

Fix missing product id when getting check-in time #402

Closed axi closed 4 months ago

axi commented 6 months ago

Fix missing product id when getting check-in time Apply same code style within file

All Submissions:


Changes proposed in this Pull Request:

Fix missing product id when getting check-in time Apply same code style (call static method) within file

Changelog entry

Fix - Missing product ID when getting check-in time. Dev - Apply same code style (call static method) within file.

dkotter commented 5 months ago

@axi Thanks for the contribution! Code here looks fine to me but wondering if you could add more details on the issue that this resolves, just so we can properly test?

axi commented 5 months ago

I can't remember my usecase but because the product id wasn't passed, I was getting the default check-in time when I needed the custom one.

axi commented 5 months ago

re-found my usecase. php8.1

A booking has been added to the cart so the product is not 100% available anymore. When I open the product page, the calendar opens and try to find availabilities but there's a PHP warning in the ajax call response and the json response is broken (and loader keep turning):

<br/><b>Deprecated</b>:  strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in <b>..../web/app/plugins/woocommerce-accommodation-bookings/includes/class-wc-accommodation-booking-date-picker.php</b> on line <b>165</b>
<br/><br/><b>Deprecated</b>:  strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in <b>.......web/app/plugins/woocommerce-accommodation-bookings/includes/class-wc-accommodation-booking-date-picker.php</b> on line <b>165</b><br/>
axi commented 5 months ago

I guess my "woocommerce_accommodation_booking_get_check_times" filter should also never returns a null :-)

faisal-alvi commented 5 months ago

I can't remember my usecase but because the product id wasn't passed, I was getting the default check-in time when I needed the custom one.

@axi to replicate the issue, could you confirm if the following steps are accurate?

  1. Create an accommodation product.
  2. Apply the filter woocommerce_accommodation_booking_get_check_times to set a custom check-in time for the product.
  3. Add the product to the cart.
  4. Verify if the cart displays an incorrect check-in time for the added product.
axi commented 5 months ago

I would say: 1) create an Accommodation product 2) Make the filter woocommerce_accommodation_booking_get_check_times set a custom check-in time for the product. In my case, because no product id was passed, the filter was returning a null value (I agree it shouldn't). Basically, the bug happens if this filter return null. 3) use the calendar to book a period (clicking "book now") 4) calendar is broken (infinite loader) on page load because of the ajax call to "/?wc-ajax=wc_bookings_find_booked_day_blocks&wc-ajax=wc_bookings_find_booked_day_blocks&product_id=PRODUCT_ID&security=lalala&resource_id=0&min_date=2024-01-19&max_date=2024-02-26" displays the "strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated" warning

ankitguptaindia commented 5 months ago

@dkotter I tried to reproduce this issue by adding a custom check-in time with use of filter woocommerce_accommodation_booking_get_check_times but unable to reproduce this issue. Could you please help by providing detailed info to reproduce this issue from QA point of view? thanks!

axi commented 5 months ago

@ankitguptaindia just to be sure, are you trying reproducing with php8.1 (minimum) (https://php.watch/versions/8.1/internal-func-non-nullable-null-deprecation) and with display_errors on ?

ankitguptaindia commented 5 months ago

@ankitguptaindia just to be sure, are you trying reproducing with php8.1 (minimum) (https://php.watch/versions/8.1/internal-func-non-nullable-null-deprecation) and with display_errors on ?

@axi I can reproduce the issue. Thanks for the help.

ankitguptaindia commented 5 months ago

QA/Test Report-

Testing Environment -

* WordPress: 6.4.2 * Theme: Storefront Version: 4.5.4 * WooCommerce - Version 8.5.2 * PHP: 8.1.23 * Web Server: Nginx * Browser: Chrome - Version 121 * OS: macOS Monterey

Test Results - Issue has been fixed with this PR, no warnings and errors appears now. Calendar also works fine after adding the booking to cart.

Next Step- Ready to Code Review(Woo) UAT.

Testing Documentation Status- Use Cases related to this PR/Issue, are added to Critical Flow Wiki Pages:

axi commented 4 months ago

Thanks guys