diff --git a/facebook-commerce.php b/facebook-commerce.php index f2e215f5b..d76ff28ca 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -111,6 +111,15 @@ class WC_Facebookcommerce_Integration extends WC_Integration { /** @var string the WordPress option name where the merchant access token is stored */ const OPTION_MERCHANT_ACCESS_TOKEN = 'wc_facebook_merchant_access_token'; + /** @var string the WordPress option name where the business manager ID is stored */ + const OPTION_BUSINESS_MANAGER_ID = 'wc_facebook_business_manager_id'; + + /** @var string the WordPress option name where the ad account ID is stored */ + const OPTION_AD_ACCOUNT_ID = 'wc_facebook_ad_account_id'; + + /** @var string the WordPress option name where the system user ID is stored */ + const OPTION_SYSTEM_USER_ID = 'wc_facebook_system_user_id'; + /** @var string the WordPress option name where the commerce merchant settings ID is stored */ const OPTION_COMMERCE_MERCHANT_SETTINGS_ID = 'wc_facebook_commerce_merchant_settings_id'; diff --git a/includes/API/FBE/Installation/Read/Response.php b/includes/API/FBE/Installation/Read/Response.php index 2b1294e13..426eb34ce 100644 --- a/includes/API/FBE/Installation/Read/Response.php +++ b/includes/API/FBE/Installation/Read/Response.php @@ -95,6 +95,17 @@ public function get_commerce_merchant_settings_id() { return $this->get_data()['commerce_merchant_settings_id'] ?? ''; } + /** + * Gets the commerce partner integration ID. + * + * @since 3.5.0 + * + * @return string + */ + public function get_commerce_partner_integration_id() { + return $this->get_data()['commerce_partner_integration_id'] ?? ''; + } + /** * Gets the profiles. diff --git a/includes/API/Plugin/Settings/Handler.php b/includes/API/Plugin/Settings/Handler.php index 83ef5acf3..259f44a4e 100644 --- a/includes/API/Plugin/Settings/Handler.php +++ b/includes/API/Plugin/Settings/Handler.php @@ -191,6 +191,10 @@ private function map_params_to_options( array $params ): array { $options[ \WC_Facebookcommerce_Integration::OPTION_PROFILES ] = $params['profiles']; } + if ( ! empty( $params['business_manager_id'] ) ) { + $options[ \WC_Facebookcommerce_Integration::OPTION_BUSINESS_MANAGER_ID ] = $params['business_manager_id']; + } + return $options; } @@ -239,6 +243,10 @@ private function update_connection_status( array $params ) { private function clear_integration_options() { $options = [ \WC_Facebookcommerce_Integration::OPTION_ACCESS_TOKEN, + \WC_Facebookcommerce_Integration::OPTION_BUSINESS_MANAGER_ID, + \WC_Facebookcommerce_Integration::OPTION_AD_ACCOUNT_ID, + \WC_Facebookcommerce_Integration::OPTION_SYSTEM_USER_ID, + \WC_Facebookcommerce_Integration::OPTION_FEED_ID, \WC_Facebookcommerce_Integration::OPTION_COMMERCE_MERCHANT_SETTINGS_ID, \WC_Facebookcommerce_Integration::OPTION_COMMERCE_PARTNER_INTEGRATION_ID, \WC_Facebookcommerce_Integration::OPTION_ENABLE_MESSENGER, diff --git a/includes/Admin/Settings_Screens/Shops.php b/includes/Admin/Settings_Screens/Shops.php index 3c809b41c..84d6cb4bc 100644 --- a/includes/Admin/Settings_Screens/Shops.php +++ b/includes/Admin/Settings_Screens/Shops.php @@ -386,6 +386,10 @@ public function generate_inline_enhanced_onboarding_script() { const messageEvent = message.event; if (messageEvent === 'CommerceExtension::INSTALL' && message.success) { + const cms_id = message.installed_features.find( ( f ) => 'fb_shop' === f.feature_type )?.connected_assets?.commerce_merchant_settings_id || + message.installed_features.find( ( f ) => 'ig_shopping' === f.feature_type )?.connected_assets?.commerce_merchant_settings_id || ''; + const ad_account_id = message.installed_features.find( ( f ) => 'ads' === f.feature_type )?.connected_assets?.ad_account_id || ''; + const requestBody = { access_token: message.access_token, merchant_access_token: message.access_token, @@ -394,8 +398,8 @@ public function generate_inline_enhanced_onboarding_script() { pixel_id: message.pixel_id, page_id: message.page_id, business_manager_id: message.business_manager_id, - commerce_merchant_settings_id: message.installed_features.find(f => f.feature_type === 'fb_shop')?.connected_assets?.commerce_merchant_settings_id || '', - ad_account_id: message.installed_features.find(f => f.feature_type === 'ads')?.connected_assets?.ad_account_id || '', + commerce_merchant_settings_id: cms_id, + ad_account_id: ad_account_id, commerce_partner_integration_id: message.commerce_partner_integration_id || '', profiles: message.profiles, installed_features: message.installed_features diff --git a/includes/Handlers/Connection.php b/includes/Handlers/Connection.php index 554816c83..837175eb5 100644 --- a/includes/Handlers/Connection.php +++ b/includes/Handlers/Connection.php @@ -332,6 +332,12 @@ private function update_installation_data() { if ( $response->get_commerce_merchant_settings_id() ) { $this->update_commerce_merchant_settings_id( sanitize_text_field( $response->get_commerce_merchant_settings_id() ) ); } + + if ( $response->get_commerce_partner_integration_id() ) { + $this->update_commerce_partner_integration_id( sanitize_text_field( $response->get_commerce_partner_integration_id() ) ); + } else { + $this->update_commerce_partner_integration_id( "" ); + } }