mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge branch 'refs/heads/trunk' into modularity-module-migration
# Conflicts: # modules/ppcp-applepay/src/ApplepayModule.php # modules/ppcp-compat/src/CompatModule.php
This commit is contained in:
commit
789d979c80
113 changed files with 11616 additions and 2360 deletions
|
@ -9,6 +9,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Compat;
|
||||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Cart;
|
||||
use WC_Order;
|
||||
use WC_Order_Item_Product;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
|
@ -66,6 +71,14 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
if ( $is_nyp_active ) {
|
||||
$this->initialize_nyp_compat_layer();
|
||||
}
|
||||
|
||||
$logger = $c->get( 'woocommerce.logger.woocommerce' );
|
||||
|
||||
$is_wc_bookings_active = $c->get( 'compat.wc_bookings.is_supported_plugin_version_active' );
|
||||
if ( $is_wc_bookings_active ) {
|
||||
$this->initialize_wc_bookings_compat_layer( $logger );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -410,4 +423,62 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the compatibility layer for WooCommerce Bookings plugin.
|
||||
*
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @return void
|
||||
*/
|
||||
protected function initialize_wc_bookings_compat_layer( LoggerInterface $logger ): void {
|
||||
add_action(
|
||||
'woocommerce_paypal_payments_shipping_callback_woocommerce_order_created',
|
||||
static function ( WC_Order $wc_order, WC_Cart $wc_cart ) use ( $logger ): void {
|
||||
try {
|
||||
$cart_contents = $wc_cart->get_cart();
|
||||
foreach ( $cart_contents as $cart_item ) {
|
||||
if ( empty( $cart_item['booking'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $wc_order->get_items() as $wc_order_item ) {
|
||||
if ( ! is_a( $wc_order_item, WC_Order_Item_Product::class ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$product_id = $wc_order_item->get_variation_id() ?: $wc_order_item->get_product_id();
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( ! is_wc_booking_product( $product ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$booking_data = array(
|
||||
'cost' => $cart_item['booking']['_cost'] ?? 0,
|
||||
'start_date' => $cart_item['booking']['_start_date'] ?? 0,
|
||||
'end_date' => $cart_item['booking']['_end_date'] ?? 0,
|
||||
'all_day' => $cart_item['booking']['_all_day'] ?? 0,
|
||||
'local_timezone' => $cart_item['booking']['_local_timezone'] ?? 0,
|
||||
'order_item_id' => $wc_order_item->get_id(),
|
||||
);
|
||||
|
||||
if ( isset( $cart_item['booking']['_resource_id'] ) ) {
|
||||
$booking_data['resource_id'] = $cart_item['booking']['_resource_id'];
|
||||
}
|
||||
|
||||
if ( isset( $cart_item['booking']['_persons'] ) ) {
|
||||
$booking_data['persons'] = $cart_item['booking']['_persons'];
|
||||
}
|
||||
|
||||
create_wc_booking( $cart_item['product_id'], $booking_data, 'unpaid' );
|
||||
}
|
||||
}
|
||||
} catch ( Exception $exception ) {
|
||||
$logger->warning( 'Failed to create booking for WooCommerce Bookings plugin: ' . $exception->getMessage() );
|
||||
}
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue