Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions includes/API/Plugin/Settings/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function register_routes() {
public function handle_update( \WP_REST_Request $wp_request ) {
try {
$request = new UpdateRequest( $wp_request );
$request_data = $request->get_data();
$validation_result = $request->validate();

if ( is_wp_error( $validation_result ) ) {
Expand All @@ -74,19 +75,15 @@ public function handle_update( \WP_REST_Request $wp_request ) {
);
}

// Maybe trigger products sync and/or metadata feed uploads
$this->maybe_trigger_feed_uploads( $request_data );

// Map parameters to options and update settings
$options = $this->map_params_to_options( $request->get_data() );
$options = $this->map_params_to_options( $request_data );
$this->update_settings( $options );

// Update connection status flags
$this->update_connection_status( $request->get_data() );

// Allow opt-out of full batch-API sync, for example if store has a large number of products.
if ( facebook_for_woocommerce()->get_integration()->allow_full_batch_api_sync() ) {
facebook_for_woocommerce()->get_products_sync_handler()->create_or_update_all_products();
} else {
\WC_Facebookcommerce_Utils::logToMeta( 'Initial full product sync disabled by filter hook `facebook_for_woocommerce_allow_full_batch_api_sync`' );
}
$this->update_connection_status( $request_data );

return $this->success_response(
[
Expand Down Expand Up @@ -253,4 +250,37 @@ private function clear_integration_options() {
delete_option( $option );
}
}

/**
* Triggers products sync if catalog id is being set to a different value.
*
* @since 3.5.0
*
* @param array $params Request parameters.
* @return void
*/
private function maybe_trigger_feed_uploads( $params ) {
// Only sync products if catalog id has been updated.
try {
if ( ! empty( $params['product_catalog_id'] ) && facebook_for_woocommerce()->get_integration()->get_product_catalog_id() !== $params['product_catalog_id'] ) {
// Allow opt-out of full batch-API sync, for example if store has a large number of products.
if ( facebook_for_woocommerce()->get_integration()->allow_full_batch_api_sync() ) {
facebook_for_woocommerce()->get_products_sync_handler()->create_or_update_all_products();
} else {
\WC_Facebookcommerce_Utils::logToMeta( 'Initial full product sync disabled by filter hook `facebook_for_woocommerce_allow_full_batch_api_sync`' );
}
}
} catch ( \Exception $exception ) {
\WC_Facebookcommerce_Utils::logExceptionImmediatelyToMeta(
$exception,
[
'event' => 'product_sync',
'event_type' => 'sync_products_after_settings_update',
'extra_data' => [
'message' => 'failed sync products during the update settings request.',
],
]
);
}
}
}