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 @@ -73,4 +73,37 @@ jQuery(document).ready(function($) {
button.prop('disabled', false);
});
});

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

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

var data = {
action: "wc_facebook_sync_shipping_profiles",
nonce: wc_facebook_enhanced_settings_sync.sync_shipping_profiles_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);
});
});
});
35 changes: 28 additions & 7 deletions includes/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function __construct() {
// sync all coupons via AJAX
add_action( 'wp_ajax_wc_facebook_sync_coupons', array( $this, 'sync_coupons' ) );

// sync all shipping profiles via AJAX
add_action( 'wp_ajax_wc_facebook_sync_shipping_profiles', array( $this, 'sync_shipping_profiles' ) );

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

Expand Down Expand Up @@ -117,13 +120,13 @@ public function sync_products() {
}
}

/**
* Syncs all coupons via AJAX.
*
* @internal
*
* @since 3.5.0
*/
/**
* Syncs all coupons via AJAX.
*
* @internal
*
* @since 3.5.0
*/
public function sync_coupons() {
check_admin_referer( Shops::ACTION_SYNC_COUPONS, 'nonce' );

Expand All @@ -135,6 +138,24 @@ public function sync_coupons() {
}
}

/**
* Syncs all shipping profiles via AJAX.
*
* @internal
*
* @since 3.5.0
*/
public function sync_shipping_profiles() {
check_admin_referer( Shops::ACTION_SYNC_SHIPPING_PROFILES, 'nonce' );

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


/**
* Gets the current sync status.
Expand Down
26 changes: 23 additions & 3 deletions includes/Admin/Settings_Screens/Shops.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Shops extends Abstract_Settings_Screen {
/** @var string */
const ACTION_SYNC_COUPONS = 'wc_facebook_sync_coupons';

/** @var string */
const ACTION_SYNC_SHIPPING_PROFILES = 'wc_facebook_sync_shipping_profiles';

/**
* Shops constructor.
*
Expand Down Expand Up @@ -126,9 +129,10 @@ public function enqueue_assets() {
'wc-facebook-enhanced-settings-sync',
'wc_facebook_enhanced_settings_sync',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'sync_products_nonce' => wp_create_nonce( self::ACTION_SYNC_PRODUCTS ),
'sync_coupons_nonce' => wp_create_nonce( self::ACTION_SYNC_COUPONS ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'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 ),
)
);
}
Expand Down Expand Up @@ -234,6 +238,22 @@ class="button"
</p>
</td>
</tr>
<tr valign="top" class="wc-facebook-shops-sample">
<th scope="row" class="titledesc">
Shipping profiles sync
</th>
<td class="forminp">
<button
id="wc-facebook-enhanced-settings-sync-shipping-profiles"
class="button"
type="button">
<?php esc_html_e( 'Sync now', 'facebook-for-woocommerce' ); ?>
</button>
<p id="shipping-profile-sync-description" class="sync-description">
Manually sync your shipping profiles 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
5 changes: 0 additions & 5 deletions includes/Feed/ShippingProfiles/ShippingProfilesFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ protected static function get_data_stream_name(): string {
return FeedManager::SHIPPING_PROFILES;
}

protected static function get_feed_gen_interval(): int {
return HOUR_IN_SECONDS;
}


/**
* @throws \Exception If an error is encountered mapping shipping profile data.
*/
Expand Down