diff --git a/admin/post-types/product.php b/admin/post-types/product.php index 383eb2fce04..d2b04785070 100644 --- a/admin/post-types/product.php +++ b/admin/post-types/product.php @@ -155,6 +155,26 @@ function woocommerce_custom_product_columns( $column ) { get_inline_data( $post ); + /* Custom inline data for woocommerce */ + echo ' + + '; + break; case "sku" : if ($product->get_sku()) echo $product->get_sku(); else echo ''; @@ -414,4 +434,203 @@ function woocommerce_admin_product_search_label($query) { } return $query; -} \ No newline at end of file +} + +/** + * 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; + ?> +
+
+ +

+ + + + +
+ + + +
+ +
+ +
+
+ +
+ +
+
+
+ + + + + + +
+
+
+ + + +
+ +

+ + +
+ + + +
+ + + +
+ + +
+
+ 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 ); +} + diff --git a/admin/post-types/writepanels/writepanels-init.php b/admin/post-types/writepanels/writepanels-init.php index 6542171bf59..b55047b43de 100644 --- a/admin/post-types/writepanels/writepanels-init.php +++ b/admin/post-types/writepanels/writepanels-init.php @@ -8,6 +8,11 @@ * @category Admin Write Panels * @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 diff --git a/admin/woocommerce-admin-init.php b/admin/woocommerce-admin-init.php index 46f4579573d..300405b8737 100644 --- a/admin/woocommerce-admin-init.php +++ b/admin/woocommerce-admin-init.php @@ -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' ); diff --git a/assets/css/admin.css b/assets/css/admin.css index 9d55392fe1b..5e15333cd0f 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -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;} diff --git a/assets/css/admin.less b/assets/css/admin.less index 239ac3217e5..f1a720ccad7 100644 --- a/assets/css/admin.less +++ b/assets/css/admin.less @@ -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; diff --git a/assets/js/admin/quick-edit.js b/assets/js/admin/quick-edit.js new file mode 100644 index 00000000000..49d2f87586f --- /dev/null +++ b/assets/js/admin/quick-edit.js @@ -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(); + } + + }); +}); \ No newline at end of file diff --git a/readme.txt b/readme.txt index 8ba0dd720b0..c7846f03c9b 100644 --- a/readme.txt +++ b/readme.txt @@ -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 diff --git a/woocommerce.php b/woocommerce.php index 418388e948a..e1f5c0dc804 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -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();