Skip to content
Closed
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions assets/js/admin/enhanced-settings-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,37 @@ jQuery(document).ready(function($) {
button.prop('disabled', false);
});
});

/**
* Handle the sync navigation menu button click event
*
* @since 3.5.0
*
* @param {object} event
*/
$('#wc-facebook-enhanced-settings-sync-navigation-menu').click(function(event) {
event.preventDefault();
var button = $(this);

button.html('Syncing...');
button.prop('disabled', true);

var data = {
action: "wc_facebook_sync_navigation_menu",
nonce: wc_facebook_enhanced_settings_sync.sync_navigation_menu_nonce
};

$.post(wc_facebook_enhanced_settings_sync.ajax_url, data, function(response) {
if (response.success) {
button.html('Sync completed');
button.prop('disabled', false);
} else {
button.html('Sync failed');
button.prop('disabled', false);
}
}).fail(function() {
button.html('Sync failed');
button.prop('disabled', false);
});
});
});
21 changes: 21 additions & 0 deletions includes/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function __construct() {
// sync all shipping profiles via AJAX
add_action( 'wp_ajax_wc_facebook_sync_shipping_profiles', array( $this, 'sync_shipping_profiles' ) );

// sync navigation menu via AJAX
add_action( 'wp_ajax_wc_facebook_sync_navigation_menu', array( $this, 'sync_navigation_menu' ) );

// get the current sync status
add_action( 'wp_ajax_wc_facebook_get_sync_status', array( $this, 'get_sync_status' ) );

Expand Down Expand Up @@ -184,6 +187,24 @@ public function sync_shipping_profiles() {
}
}

/**
* Syncs navigation menu via AJAX.
*
* @internal
*
* @since 3.5.0
*/
public function sync_navigation_menu() {
check_admin_referer( Shops::ACTION_SYNC_NAVIGATION_MENU, 'nonce' );

try {
facebook_for_woocommerce()->feed_manager->get_feed_instance( 'navigation_menu' )->regenerate_feed();
wp_send_json_success();
} catch ( \Exception $exception ) {
wp_send_json_error( $exception->getMessage() );
}
}


/**
* Gets the current sync status.
Expand Down
20 changes: 20 additions & 0 deletions includes/Admin/Settings_Screens/Shops.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Shops extends Abstract_Settings_Screen {
/** @var string */
const ACTION_SYNC_SHIPPING_PROFILES = 'wc_facebook_sync_shipping_profiles';

/** @var string */
const ACTION_SYNC_NAVIGATION_MENU = 'wc_facebook_sync_navigation_menu';

/**
* Shops constructor.
*
Expand Down Expand Up @@ -133,6 +136,7 @@ public function enqueue_assets() {
'sync_products_nonce' => wp_create_nonce( self::ACTION_SYNC_PRODUCTS ),
'sync_coupons_nonce' => wp_create_nonce( self::ACTION_SYNC_COUPONS ),
'sync_shipping_profiles_nonce' => wp_create_nonce( self::ACTION_SYNC_SHIPPING_PROFILES ),
'sync_navigation_menu_nonce' => wp_create_nonce( self::ACTION_SYNC_NAVIGATION_MENU ),
)
);
}
Expand Down Expand Up @@ -254,6 +258,22 @@ class="button"
</p>
</td>
</tr>
<tr valign="top" class="wc-facebook-shops-sample">
<th scope="row" class="titledesc">
Navigation menu sync
</th>
<td class="forminp">
<button
id="wc-facebook-enhanced-settings-sync-navigation-menu"
class="button"
type="button">
<?php esc_html_e( 'Sync now', 'facebook-for-woocommerce' ); ?>
</button>
<p id="navigation-menu-sync-description" class="sync-description">
Manually sync your category navigation menu from WooCommerce to your shop. It may take a couple of minutes for the changes to populate.
</p>
</td>
</tr>
</tbody>
</table>
<?php parent::render(); ?>
Expand Down
3 changes: 1 addition & 2 deletions includes/Feed/FeedManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private function create_feed( string $data_stream_name ): AbstractFeed {
* @since 3.5.0
*/
public static function get_active_feed_types(): array {
// TODO add self::NAVIGATION_MENU once category sync is implemented
return array( self::PROMOTIONS, self::RATINGS_AND_REVIEWS, self::SHIPPING_PROFILES );
return array( self::PROMOTIONS, self::RATINGS_AND_REVIEWS, self::SHIPPING_PROFILES, self::NAVIGATION_MENU );
}

/**
Expand Down