| @@ -44,13 +44,17 @@ | ||
| 44 | 44 | $config = $order->config; |
| 45 | 45 | $bookingId = Arr::get($cart->checkout_data, 'fluent_booking_data.booking_id'); |
| 46 | 46 | if ($bookingId) { |
| 47 | 47 | $config['fcal_booking_id'] = $bookingId; |
| 48 | + $config['fcal_target_variant_id'] = Arr::get($cart->checkout_data, 'fluent_booking_data.target_variant_id'); | |
| 48 | 49 | $order->config = $config; |
| 49 | 50 | $order->save(); |
| 50 | 51 | } |
| 51 | 52 | }); |
| 52 | 53 | |
| 54 | + // The booking cart is locked to pin its booking item, which also hides order bumps | |
| 55 | + add_filter('fluent_cart/cart/accepts_additional_items', [$this, 'maybeAcceptOrderBumps'], 10, 2); | |
| 56 | + | |
| 53 | 57 | // after order confirmation |
| 54 | 58 | add_action('fluent_booking/cart/booking_order_completed', [$this, 'maybeScheduleBooking'], 10, 1); |
| 55 | 59 | |
| 56 | 60 | // Offline and async payments settle after their cart is closed, so the |
| @@ -59,8 +63,24 @@ | ||
| 59 | 63 | |
| 60 | 64 | add_filter('fluent_cart/checkout_page_name_fields_schema', [$this, 'maybeFillSplitNameFields'], 10, 2); |
| 61 | 65 | } |
| 62 | 66 | |
| 67 | + public function maybeAcceptOrderBumps($accepts, $context) | |
| 68 | + { | |
| 69 | + $cart = Arr::get($context, 'cart'); | |
| 70 | + | |
| 71 | + if ($accepts || !$cart || empty($cart->checkout_data['fluent_booking_data'])) { | |
| 72 | + return $accepts; | |
| 73 | + } | |
| 74 | + | |
| 75 | + // A draft order binds the cart, and upgrade carts keep their own restriction | |
| 76 | + if ($cart->order_id || !empty($cart->checkout_data['upgrade_data'])) { | |
| 77 | + return $accepts; | |
| 78 | + } | |
| 79 | + | |
| 80 | + return true; | |
| 81 | + } | |
| 82 | + | |
| 63 | 83 | public function maybeFillSplitNameFields($nameFields, $context) |
| 64 | 84 | { |
| 65 | 85 | $cart = Arr::get($context, 'cart'); |
| 66 | 86 | if (!$cart || empty($cart->checkout_data['fluent_booking_data'])) { |
| @@ -131,12 +151,10 @@ | ||
| 131 | 151 | return $response; |
| 132 | 152 | } |
| 133 | 153 | |
| 134 | 154 | $quantity = $booking->getMeta('quantity', 1); |
| 135 | - $newItem = $product->toArray(); | |
| 155 | + $instantCart = \FluentCart\App\Helpers\CartHelper::generateCartFromVariation($product, $quantity); | |
| 136 | 156 | |
| 137 | - $instantCart = \FluentCart\App\Helpers\CartHelper::generateCartFromCustomVariation($newItem, $quantity); | |
| 138 | - | |
| 139 | 157 | $cartData = $instantCart->cart_data; |
| 140 | 158 | $cartData[0]['fcal_booking_id'] = $booking->id; |
| 141 | 159 | $instantCart->cart_data = $cartData; |
| 142 | 160 | |
| @@ -180,9 +198,9 @@ | ||
| 180 | 198 | 'booking_id' => $booking->id, |
| 181 | 199 | 'status' => 'closed', |
| 182 | 200 | 'type' => 'info', |
| 183 | 201 | 'title' => __('Redirect to FluentCart checkout page', 'fluent-booking'), |
| 184 | - 'description' => __('User redirected to FluentCart checkout page to comeplete the order.', 'fluent-booking') | |
| 202 | + 'description' => __('User redirected to FluentCart checkout page to complete the order.', 'fluent-booking') | |
| 185 | 203 | ]); |
| 186 | 204 | |
| 187 | 205 | return $response; |
| 188 | 206 | }, 10, 2); |
| @@ -287,8 +305,26 @@ | ||
| 287 | 305 | } |
| 288 | 306 | |
| 289 | 307 | $calendarEvent = $booking->calendar_event; |
| 290 | 308 | if (!CartHelper::isEnabled($calendarEvent)) { |
| 309 | + return; | |
| 310 | + } | |
| 311 | + | |
| 312 | + // The cart takes order bumps, so a paid order is not proof the booking item was bought. | |
| 313 | + // Orders drafted before the variant was recorded carry no id and skip the check. | |
| 314 | + $targetVariantId = (int) Arr::get($order->config, 'fcal_target_variant_id', 0); | |
| 315 | + if ($targetVariantId && !$order->order_items()->where('object_id', $targetVariantId)->exists()) { | |
| 316 | + do_action('fluent_booking/log_booking_activity', [ | |
| 317 | + 'booking_id' => $booking->id, | |
| 318 | + 'status' => 'closed', | |
| 319 | + 'type' => 'error', | |
| 320 | + 'title' => __('Cart: Booking status could not be changed', 'fluent-booking'), | |
| 321 | + 'description' => sprintf( | |
| 322 | + /* translators: %1$s and %2$s are the HTML link tags for "View Order" */ | |
| 323 | + __('The paid order does not contain the booking item. %1$sView Order%2$s', 'fluent-booking'), | |
| 324 | + '<a target="_blank" href="' . $order->getViewUrl('admin') . '">', | |
| 325 | + '</a>') | |
| 326 | + ]); | |
| 291 | 327 | return; |
| 292 | 328 | } |
| 293 | 329 | |
| 294 | 330 | if ($booking->status != 'pending') { |