Quick edit Closes #258.

This commit is contained in:
Mike Jolley 2012-02-20 14:29:51 +00:00
parent 02abf6117b
commit 565987dd56
8 changed files with 393 additions and 15 deletions

View File

@ -155,6 +155,26 @@ function woocommerce_custom_product_columns( $column ) {
get_inline_data( $post );
/* Custom inline data for woocommerce */
echo '
<div class="hidden" id="woocommerce_inline_' . $post->ID . '">
<div class="sku">' . $product->sku . '</div>
<div class="regular_price">' . $product->regular_price . '</div>
<div class="sale_price">' . $product->sale_price . '</div>
<div class="weight">' . $product->weight . '</div>
<div class="length">' . $product->length . '</div>
<div class="width">' . $product->width . '</div>
<div class="height">' . $product->height . '</div>
<div class="visibility">' . $product->visibility . '</div>
<div class="stock_status">' . $product->stock_status . '</div>
<div class="stock">' . $product->stock . '</div>
<div class="manage_stock">' . $product->manage_stock . '</div>
<div class="featured">' . $product->featured . '</div>
<div class="product_type">' . $product->product_type . '</div>
<div class="product_is_virtual">' . $product->virtual . '</div>
</div>
';
break;
case "sku" :
if ($product->get_sku()) echo $product->get_sku(); else echo '<span class="na">&ndash;</span>';
@ -415,3 +435,202 @@ function woocommerce_admin_product_search_label($query) {
return $query;
}
/**
* Custom quick edit
**/
add_action('quick_edit_custom_box', 'woocommerce_admin_product_quick_edit', 10, 2);
add_action('admin_enqueue_scripts', 'woocommerce_admin_product_quick_edit_scripts', 10);
add_action('save_post', 'woocommerce_admin_product_quick_edit_save', 10, 2);
function woocommerce_admin_product_quick_edit( $column_name, $post_type ) {
if ($column_name != 'price' || $post_type != 'product') return;
?>
<fieldset class="inline-edit-col-left">
<div id="woocommerce-fields" class="inline-edit-col">
<h4><?php _e('Product Data', 'woocommerce'); ?></h4>
<?php if( get_option('woocommerce_enable_sku', true) !== 'no' ) : ?>
<label>
<span class="title"><?php _e('SKU', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<input type="text" name="_sku" class="text sku" value="">
</span>
</label>
<br class="clear" />
<?php endif; ?>
<div class="price_fields">
<label>
<span class="title"><?php _e('Price', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<input type="text" name="_regular_price" class="text regular_price" placeholder="<?php _e('Regular price', 'woocommerce'); ?>" value="">
</span>
</label>
<br class="clear" />
<label>
<span class="title"><?php _e('Sale', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<input type="text" name="_sale_price" class="text sale_price" placeholder="<?php _e('Sale price', 'woocommerce'); ?>" value="">
</span>
</label>
<br class="clear" />
</div>
<div class="dimension_fields">
<label>
<span class="title"><?php _e('Weight', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<input type="text" name="_weight" class="text weight" placeholder="<?php _e('0.00', 'woocommerce'); ?>" value="">
</span>
</label>
<br class="clear" />
<div class="inline-edit-group dimensions">
<div>
<span class="title"><?php _e('L/W/H', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<input type="text" name="_length" class="text length" placeholder="<?php _e('Length', 'woocommerce'); ?>" value="">
<input type="text" name="_width" class="text width" placeholder="<?php _e('Width', 'woocommerce'); ?>" value="">
<input type="text" name="_height" class="text height" placeholder="<?php _e('Height', 'woocommerce'); ?>" value="">
</span>
</div>
</div>
</div>
<label class="alignleft">
<span class="title"><?php _e('Visibility', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<select class="visibility" name="_visibility">
<?php
$options = array(
'visible' => __('Catalog &amp; search', 'woocommerce'),
'catalog' => __('Catalog', 'woocommerce'),
'search' => __('Search', 'woocommerce'),
'hidden' => __('Hidden', 'woocommerce')
);
foreach ($options as $key => $value) {
echo '<option value="'.$key.'">'. $value .'</option>';
}
?>
</select>
</span>
</label>
<label class="alignleft featured">
<input type="checkbox" name="_featured" value="1">
<span class="checkbox-title"><?php _e('Featured', 'woocommerce'); ?></span>
</label>
<br class="clear" />
<h4><?php _e('Inventory', 'woocommerce'); ?></h4>
<label class="alignleft">
<span class="title"><?php _e('In stock?', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<select class="stock_status" name="_stock_status">
<?php
$options = array(
'instock' => __('In stock', 'woocommerce'),
'outofstock' => __('Out of stock', 'woocommerce')
);
foreach ($options as $key => $value) {
echo '<option value="'.$key.'">'. $value .'</option>';
}
?>
</select>
</span>
</label>
<div class="stock_fields">
<?php if (get_option('woocommerce_manage_stock')=='yes') : ?>
<label class="alignleft manage_stock">
<input type="checkbox" name="_manage_stock" value="1">
<span class="checkbox-title"><?php _e('Manage stock?', 'woocommerce'); ?></span>
</label>
<br class="clear" />
<label class="stock_qty_field">
<span class="title"><?php _e('Stock Qty', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<input type="text" name="_stock" class="text stock" value="">
</span>
</label>
<?php endif; ?>
</div>
<input type="hidden" name="woocommerce_quick_edit_nonce" value="<?php echo wp_create_nonce( 'woocommerce_quick_edit_nonce' ); ?>" />
</div>
</fieldset>
<?php
}
function woocommerce_admin_product_quick_edit_scripts() {
global $woocommerce;
wp_enqueue_script( 'woocommerce_quick-edit', $woocommerce->plugin_url() . '/assets/js/admin/quick-edit.js', array('jquery') );
}
function woocommerce_admin_product_quick_edit_save( $post_id, $post ) {
if ( !$_POST ) return $post_id;
if ( is_int( wp_is_post_revision( $post_id ) ) ) return;
if( is_int( wp_is_post_autosave( $post_id ) ) ) return;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
if ( !isset($_POST['woocommerce_quick_edit_nonce']) || (isset($_POST['woocommerce_quick_edit_nonce']) && !wp_verify_nonce( $_POST['woocommerce_quick_edit_nonce'], 'woocommerce_quick_edit_nonce' ))) return $post_id;
if ( !current_user_can( 'edit_post', $post_id )) return $post_id;
if ( $post->post_type != 'product' ) return $post_id;
global $woocommerce, $wpdb;
$product = new WC_Product( $post_id );
// Save fields
if(isset($_POST['_sku'])) update_post_meta($post_id, '_sku', esc_html(stripslashes($_POST['_sku'])));
if(isset($_POST['_weight'])) update_post_meta($post_id, '_weight', esc_html(stripslashes($_POST['_weight'])));
if(isset($_POST['_length'])) update_post_meta($post_id, '_length', esc_html(stripslashes($_POST['_length'])));
if(isset($_POST['_width'])) update_post_meta($post_id, '_width', esc_html(stripslashes($_POST['_width'])));
if(isset($_POST['_height'])) update_post_meta($post_id, '_height', esc_html(stripslashes($_POST['_height'])));
if(isset($_POST['_stock_status'])) update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
if(isset($_POST['_visibility'])) update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) );
if(isset($_POST['_featured'])) update_post_meta( $post_id, '_featured', 'yes' ); else update_post_meta( $post_id, '_featured', 'no' );
if ($product->is_type('simple') || $product->is_type('external')) {
if(isset($_POST['_regular_price'])) update_post_meta( $post_id, '_regular_price', stripslashes( $_POST['_regular_price'] ) );
if(isset($_POST['_sale_price'])) update_post_meta( $post_id, '_sale_price', stripslashes( $_POST['_sale_price'] ) );
// Handle price - remove dates and set to lowest
$price_changed = false;
if(isset($_POST['_regular_price']) && stripslashes( $_POST['_regular_price'] )!=$product->regular_price) $price_changed = true;
if(isset($_POST['_sale_price']) && stripslashes( $_POST['_sale_price'] )!=$product->sale_price) $price_changed = true;
if ($price_changed) {
update_post_meta( $post_id, '_sale_price_dates_from', '');
update_post_meta( $post_id, '_sale_price_dates_to', '');
if ($_POST['_sale_price'] != '') {
update_post_meta( $post_id, '_price', stripslashes($_POST['_sale_price']) );
} else {
update_post_meta( $post_id, '_price', stripslashes($_POST['_regular_price']) );
}
}
}
// Handle stock
if (!$product->is_type('grouped')) {
if (isset($_POST['_manage_stock'])) {
update_post_meta( $post_id, '_manage_stock', 'yes' );
update_post_meta( $post_id, '_stock', (int) $_POST['_stock'] );
} else {
update_post_meta( $post_id, '_manage_stock', 'no' );
update_post_meta( $post_id, '_stock', '0' );
}
}
// Clear transient
$woocommerce->clear_product_transients( $post_id );
}

View File

@ -9,6 +9,11 @@
* @package WooCommerce
*/
include_once('writepanel-product_data.php');
include_once('writepanel-coupon_data.php');
include_once('writepanel-order_data.php');
include_once('writepanel-order_notes.php');
/**
* Init the meta boxes
*

View File

@ -82,30 +82,51 @@ function woocommerce_admin_notices_styles() {
}
}
/**
* Admin Includes - loaded conditionally
*/
add_action('admin_init', 'woocommerce_admin_init');
function woocommerce_admin_init() {
global $pagenow;
global $pagenow, $typenow;
ob_start();
if ( $pagenow=='index.php' ) :
include_once( 'woocommerce-admin-dashboard.php' );
elseif ( $pagenow=='admin.php' && isset($_GET['import']) ) :
include_once( 'woocommerce-admin-import.php' );
elseif ( $pagenow=='post-new.php' || $pagenow=='post.php' || $pagenow=='edit.php' ) :
include_once( 'post-types/post-types-init.php' );
elseif ( $pagenow=='edit-tags.php' ) :
include_once( 'woocommerce-admin-taxonomies.php' );
elseif ( $pagenow=='users.php' || $pagenow=='user-edit.php' || $pagenow=='profile.php' ) :
include_once( 'woocommerce-admin-users.php' );
if ($typenow=='post' && isset($_GET['post']) && !empty($_GET['post'])) :
$typenow = $post->post_type;
elseif (empty($typenow) && !empty($_GET['post'])) :
$post = get_post($_GET['post']);
$typenow = $post->post_type;
endif;
if ( $pagenow=='index.php' ) {
include_once( 'woocommerce-admin-dashboard.php' );
} elseif ( $pagenow=='admin.php' && isset($_GET['import']) ) {
include_once( 'woocommerce-admin-import.php' );
} elseif ( $pagenow=='post-new.php' || $pagenow=='post.php' || $pagenow=='edit.php' ) {
include_once( 'post-types/writepanels/writepanels-init.php' );
if (in_array($typenow, array('product', 'shop_coupon', 'shop_order'))) add_action('admin_print_styles', 'woocommerce_admin_help_tab');
} elseif ( $pagenow=='edit-tags.php' ) {
include_once( 'woocommerce-admin-taxonomies.php' );
} elseif ( $pagenow=='users.php' || $pagenow=='user-edit.php' || $pagenow=='profile.php' ) {
include_once( 'woocommerce-admin-users.php' );
}
}
include_once( 'post-types/product.php' );
include_once( 'post-types/shop_coupon.php' );
include_once( 'post-types/shop_order.php' );
include_once( 'woocommerce-admin-hooks.php' );
include_once( 'woocommerce-admin-functions.php' );

View File

@ -11,6 +11,12 @@
.icon32-woocommerce-reports{background-position:-591px -6px !important;}
.wrap.woocommerce div.updated,.wrap.woocommerce div.error{margin-top:10px;}
mark.amount{background:transparent none;color:inherit;}
.inline-edit-product .inline-edit-col-center,.inline-edit-product .inline-edit-col-right{float:right !important;}
#woocommerce-fields.inline-edit-col{clear:left;}#woocommerce-fields.inline-edit-col label.featured,#woocommerce-fields.inline-edit-col label.manage_stock{margin-left:10px;}
#woocommerce-fields.inline-edit-col .dimensions div{display:block;margin:.2em 0;}#woocommerce-fields.inline-edit-col .dimensions div span.title{display:block;float:left;width:5em;}
#woocommerce-fields.inline-edit-col .dimensions div span.input-text-wrap{display:block;margin-left:5em;}
#woocommerce-fields.inline-edit-col .text{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:99%;float:left;margin:1px 1% 1px 1px;}
#woocommerce-fields.inline-edit-col .length,#woocommerce-fields.inline-edit-col .width,#woocommerce-fields.inline-edit-col .height{width:32.33%;}
#order_data{padding:0 10px 9px;}#order_data .order_data_left{width:48%;float:left;}#order_data .order_data_left h2{margin-top:11px;margin-bottom:0;}
#order_data .order_data_left p{padding:0 !important;}
#order_data .order_data_left .form-field{float:left;width:50%;padding:0;margin:9px 0 0 0;}#order_data .order_data_left .form-field label{display:block;padding:0 0 3px;}

View File

@ -65,6 +65,46 @@ mark.amount {
color: inherit;
}
/* Bulk/Quick edit */
.inline-edit-product {
.inline-edit-col-center, .inline-edit-col-right {
float: right !important;
}
}
#woocommerce-fields.inline-edit-col {
clear: left;
label.featured, label.manage_stock {
margin-left: 10px;
}
.dimensions {
div {
display: block;
margin: .2em 0;
span.title {
display: block;
float: left;
width: 5em;
}
span.input-text-wrap {
display: block;
margin-left: 5em;
}
}
}
.text {
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
width: 99%;
float: left;
margin: 1px 1% 1px 1px;
}
.length, .width, .height {
width: 32.33%;
}
}
/* Orders */
#order_data {
padding: 0 10px 9px;

View File

@ -0,0 +1,85 @@
jQuery(document).ready(function(){
jQuery('#the-list').on('click', '.editinline', function(){
inlineEditPost.revert();
var post_id = jQuery(this).closest('tr').attr('id');
post_id = post_id.replace("post-", "");
var $wc_inline_data = jQuery('#woocommerce_inline_' + post_id );
var sku = $wc_inline_data.find('.sku').text();
var regular_price = $wc_inline_data.find('.regular_price').text();
var sale_price = $wc_inline_data.find('.sale_price').text();
var weight = $wc_inline_data.find('.weight').text();
var length = $wc_inline_data.find('.length').text();
var width = $wc_inline_data.find('.width').text();
var height = $wc_inline_data.find('.height').text();
var visibility = $wc_inline_data.find('.visibility').text();
var stock_status = $wc_inline_data.find('.stock_status').text();
var stock = $wc_inline_data.find('.stock').text();
var featured = $wc_inline_data.find('.featured').text();
var manage_stock = $wc_inline_data.find('.manage_stock').text();
jQuery('input[name="_sku"]', '.inline-edit-row').val(sku);
jQuery('input[name="_regular_price"]', '.inline-edit-row').val(regular_price);
jQuery('input[name="_sale_price"]', '.inline-edit-row').val(sale_price);
jQuery('input[name="_weight"]', '.inline-edit-row').val(weight);
jQuery('input[name="_length"]', '.inline-edit-row').val(length);
jQuery('input[name="_width"]', '.inline-edit-row').val(width);
jQuery('input[name="_height"]', '.inline-edit-row').val(height);
jQuery('input[name="_stock"]', '.inline-edit-row').val(stock);
jQuery('select[name="_visibility"] option, select[name="_stock_status"] option').removeAttr('selected');
jQuery('select[name="_visibility"] option[value="' + visibility + '"]', '.inline-edit-row').attr('selected', 'selected');
jQuery('select[name="_stock_status"] option[value="' + stock_status + '"]', '.inline-edit-row').attr('selected', 'selected');
if (featured=='yes') {
jQuery('input[name="_featured"]', '.inline-edit-row').attr('checked', 'checked');
} else {
jQuery('input[name="_featured"]', '.inline-edit-row').removeAttr('checked');
}
if (manage_stock=='yes') {
jQuery('.stock_qty_field', '.inline-edit-row').show().removeAttr('style');
jQuery('input[name="_manage_stock"]', '.inline-edit-row').attr('checked', 'checked');
} else {
jQuery('.stock_qty_field', '.inline-edit-row').hide();
jQuery('input[name="_manage_stock"]', '.inline-edit-row').removeAttr('checked');
}
// Conditional display
var product_type = $wc_inline_data.find('.product_type').text();
var product_is_virtual = $wc_inline_data.find('.product_is_virtual').text();
if (product_type=='simple' || product_type=='external') {
jQuery('.price_fields', '.inline-edit-row').show().removeAttr('style');
} else {
jQuery('.price_fields', '.inline-edit-row').hide();
}
if (product_is_virtual=='yes') {
jQuery('.dimension_fields', '.inline-edit-row').hide();
} else {
jQuery('.dimension_fields', '.inline-edit-row').show().removeAttr('style');
}
if (product_type=='grouped') {
jQuery('.stock_fields', '.inline-edit-row').hide();
} else {
jQuery('.stock_fields', '.inline-edit-row').show().removeAttr('style');
}
});
jQuery('#the-list').on('change', '.inline-edit-row input[name="_manage_stock"]', function(){
if (jQuery(this).is(':checked')) {
jQuery('.stock_qty_field', '.inline-edit-row').show().removeAttr('style');
} else {
jQuery('.stock_qty_field', '.inline-edit-row').hide();
}
});
});

View File

@ -141,7 +141,9 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
== Changelog ==
= 1.4.5 =
* Quick edit products!
* Added basic API for payment gateways to hook into (for IPN etc)
* Added Bulgarian translation
= 1.4.4 - 18/02/2012 =
* Fix for remove coupon links after ajax update of shipping

View File

@ -146,7 +146,7 @@ class Woocommerce {
* Include required core files
**/
function includes() {
if (is_admin() && !defined('DOING_AJAX')) $this->admin_includes();
if (is_admin()) $this->admin_includes();
if (defined('DOING_AJAX')) $this->ajax_includes();
if (!is_admin() || defined('DOING_AJAX')) $this->frontend_includes();