We have updated one of our customers Wp-Ecommerce plugin. We found that the products categories where sortable using drag and drop. The fact is that feature does not save the order you set using it.
The fix is really simple, but it is so difficult to have a single line of code (even if its a fix) included in Wp-Ecommerce that we publish it here. Fortunately, the fix doesn’t need to be applied to core files.
This hack simply replaces the wpsc_ajax_set_category_order() function with our own. Ideally, it would be better to modify the core javascript that orders the categories. Nervermind it works and will hopefully survive to Wp-Ecommerce updates.
To fix that issue, simply paste that code in your active theme’s functions.php file:
add_action('admin_init', 'my_admin_init');
function my_admin_init () {
remove_action( 'wp_ajax_category_sort_order', 'wpsc_ajax_set_category_order' );
add_action( 'wp_ajax_category_sort_order', 'my_wpsc_ajax_set_category_order' );
}
function my_wpsc_ajax_set_category_order(){
global $wpdb;
$sort_order = $_POST['sort_order'];
$parent_id = $_POST['parent_id'];
$result = true;
foreach( $sort_order as $key=>$value ){
// ignore empty value (bad javascript makes them)
if(!$value) continue;
$value = substr($value, strpos($value, '-')+1); // removes the "tag-" prefix from object id
if( ! wpsc_update_meta( $value, 'sort_order', $key, 'wpsc_category' ) )
$result = false;
}
}







