Skip to content

Commit

Permalink
Variations -downloadable and virtual options
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Nov 9, 2011
1 parent 4e2c1e1 commit 8b125d1
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 64 deletions.
5 changes: 4 additions & 1 deletion admin/admin-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function woocommerce_admin_scripts() {
// Product/Coupon/Orders
if (in_array( $screen->id, array( 'shop_coupon', 'shop_order', 'product' ))) :

global $post;

wp_enqueue_script( 'woocommerce_writepanel' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'media-upload' );
Expand All @@ -102,7 +104,8 @@ function woocommerce_admin_scripts() {
'ajax_url' => admin_url('admin-ajax.php'),
'add_order_item_nonce' => wp_create_nonce("add-order-item"),
'upsell_crosssell_search_products_nonce' => wp_create_nonce("search-products"),
'calendar_image' => $woocommerce->plugin_url().'/assets/images/calendar.png'
'calendar_image' => $woocommerce->plugin_url().'/assets/images/calendar.png',
'post_id' => $post->ID
);

wp_localize_script( 'woocommerce_writepanel', 'woocommerce_writepanel_params', $woocommerce_witepanel_params );
Expand Down
107 changes: 100 additions & 7 deletions admin/writepanels/writepanel-product-type-variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function variable_product_type_options() {
}
?>
<div id="variable_product_options" class="panel">
<p class="bulk_edit"><strong><?php _e('Bulk edit:', 'woothemes'); ?></strong> <a class="button set_all_prices" href="#"><?php _e('Set all prices', 'woothemes'); ?></a> <a class="button set_all_sale_prices" href="#"><?php _e('Set all sale prices', 'woothemes'); ?></a> <a class="button set_all_stock" href="#"><?php _e('Set all stock', 'woothemes'); ?></a></p>
<p class="bulk_edit"><strong><?php _e('Bulk edit:', 'woothemes'); ?></strong> <a class="button set set_all_prices" href="#"><?php _e('Prices', 'woothemes'); ?></a> <a class="button set set_all_sale_prices" href="#"><?php _e('Sale prices', 'woothemes'); ?></a> <a class="button set set_all_stock" href="#"><?php _e('Stock', 'woothemes'); ?></a> <a class="button toggle toggle_downloadable" href="#"><?php _e('Downloadable', 'woothemes'); ?></a> <a class="button toggle toggle_virtual" href="#"><?php _e('Virtual', 'woothemes'); ?></a> <a class="button toggle toggle_enabled" href="#"><?php _e('Enabled', 'woothemes'); ?></a> <a class="button set set_all_paths" href="#"><?php _e('File paths', 'woothemes'); ?></a> <a class="button set set_all_limits" href="#"><?php _e('Download limits', 'woothemes'); ?></a></p>

<div class="woocommerce_variations">
<?php
Expand Down Expand Up @@ -107,7 +107,7 @@ function variable_product_type_options() {
<table cellpadding="0" cellspacing="0" class="woocommerce_variable_attributes">
<tbody>
<tr>
<td class="upload_image"><a href="#" class="upload_image_button <?php if ($image_id>0) echo 'remove'; ?>" rel="<?php echo $variation->ID; ?>"><img src="<?php echo $image ?>" width="60px" height="60px" /><input type="hidden" name="upload_image_id[<?php echo $loop; ?>]" class="upload_image_id" value="<?php echo $image_id; ?>" /><span class="overlay"></span></a></td>
<td class="upload_image" rowspan="2"><a href="#" class="upload_image_button <?php if ($image_id>0) echo 'remove'; ?>" rel="<?php echo $variation->ID; ?>"><img src="<?php echo $image ?>" width="60px" height="60px" /><input type="hidden" name="upload_image_id[<?php echo $loop; ?>]" class="upload_image_id" value="<?php echo $image_id; ?>" /><span class="overlay"></span></a></td>

<td><label><?php _e('SKU:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enter a SKU for this variation or leave blank to use the parent product SKU.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_sku[<?php echo $loop; ?>]" value="<?php if (isset($variation_data['sku'][0])) echo $variation_data['sku'][0]; ?>" placeholder="<?php if ($sku = get_post_meta($post->ID, 'sku', true)) echo $sku; else echo $post->ID; ?>" /></td>

Expand All @@ -119,8 +119,28 @@ function variable_product_type_options() {

<td><label><?php _e('Sale Price:', 'woothemes'); ?></label><input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if (isset($variation_data['sale_price'][0])) echo $variation_data['sale_price'][0]; ?>" /></td>

</tr>
<tr>

<td><label><?php _e('Downloadable', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enable this option if access is given to a downloadable file upon purchase of a product.', 'woothemes'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[<?php echo $loop; ?>]" <?php checked($variation_data['downloadable'][0], 'yes'); ?> /></td>

<td><label><?php _e('Virtual', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enable this option if a product is not shipped or there is no shipping cost.', 'woothemes'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox" name="variable_is_virtual[<?php echo $loop; ?>]" <?php checked($variation_data['virtual'][0], 'yes'); ?> /></td>

<td><label><?php _e('Enabled', 'woothemes'); ?></label><input type="checkbox" class="checkbox" name="variable_enabled[<?php echo $loop; ?>]" <?php checked($variation->post_status, 'publish'); ?> /></td>
</tr>

<td>
<div class="show_if_variation_downloadable file_path_field">
<label><?php _e('File path:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enter a File Path to make this variation a downloadable product, or leave blank.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" class="file_path" name="variable_file_path[<?php echo $loop; ?>]" value="<?php if (isset($variation_data['file_path'][0])) echo $variation_data['file_path'][0]; ?>" placeholder="<?php _e('File path/URL', 'woothemes'); ?>" /> <input type="button" class="upload_file_button button" value="<?php _e('&uarr;', 'woothemes'); ?>" />
</div>
</td>

<td>
<div class="show_if_variation_downloadable">
<label><?php _e('Download Limit:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Leave blank for unlimited re-downloads.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_download_limit[<?php echo $loop; ?>]" value="<?php if (isset($variation_data['download_limit'][0])) echo $variation_data['download_limit'][0]; ?>" placeholder="<?php _e('Unlimited', 'woothemes'); ?>" />
</div>
</td>

</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -250,18 +270,32 @@ function variable_product_write_panel_js() {
<table cellpadding="0" cellspacing="0" class="woocommerce_variable_attributes">\
<tbody>\
<tr>\
<td class="upload_image"><img src="<?php echo $woocommerce->plugin_url().'/assets/images/placeholder.png' ?>" width="60px" height="60px" /><input type="hidden" name="upload_image_id[' + loop + ']" class="upload_image_id" /><input type="button" class="upload_image_button button" rel="" value="<?php _e('Product Image', 'woothemes'); ?>" /></td>\
<td class="upload_image" rowspan="2"><a href="#" class="upload_image_button" rel="' + variation_id + '"><img src="<?php echo $woocommerce->plugin_url().'/assets/images/placeholder.png' ?>" width="60px" height="60px" /><input type="hidden" name="upload_image_id[' + loop + ']" class="upload_image_id" /><span class="overlay"></span></a></td>\
\
<td><label><?php _e('SKU:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enter a SKU for this variation or leave blank to use the parent product SKU.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_sku[' + loop + ']" placeholder="<?php if ($sku = get_post_meta($post->ID, 'sku', true)) echo $sku; else echo $post->ID; ?>" /></td>\
\
<td><label><?php _e('Weight', 'woothemes').' ('.get_option('woocommerce_weight_unit').'):'; ?> <a class="tips" tip="<?php _e('Enter a weight for this variation or leave blank to use the parent products weight.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_weight[' + loop + ']" placeholder="<?php if ($value = get_post_meta($post->ID, 'weight', true)) echo $value; else echo '0.00'; ?>" /></td>\
<td><label><?php _e('Weight', 'woothemes').' ('.get_option('woocommerce_weight_unit').'):'; ?> <a class="tips" tip="<?php _e('Enter a weight for this variation or leave blank to use the parent product weight.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_weight[' + loop + ']" placeholder="<?php if ($value = get_post_meta($post->ID, 'weight', true)) echo $value; else echo '0.00'; ?>" /></td>\
\
<td><label><?php _e('Stock Qty:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enter a quantity to manage stock for this variation, or leave blank to use the parent product stock options.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_stock[' + loop + ']" /></td>\
<td><label><?php _e('Stock Qty:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enter a quantity to manage stock for this variation, or leave blank to use the variable product stock options.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_stock[' + loop + ']" /></td>\
\
<td><label><?php _e('Price:', 'woothemes'); ?></label><input type="text" size="5" name="variable_price[' + loop + ']" /></td>\
\
<td><label><?php _e('Sale Price:', 'woothemes'); ?></label><input type="text" size="5" name="variable_sale_price[' + loop + ']" /></td>\
<td><label><?php _e('Enabled', 'woothemes'); ?></label><input type="checkbox" class="checkbox" name="variable_enabled[' + loop + ']" checked="checked" /></td>\
</tr>\
<tr>\
<td><label><?php _e('Downloadable', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enable this option if access is given to a downloadable file upon purchase of a product.', 'woothemes'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[' + loop + ']" /></td>\
\
<td><label><?php _e('Virtual', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enable this option if a product is not shipped or there is no shipping cost.', 'woothemes'); ?>" href="#">[?]</a></label><input type="checkbox" class="checkbox" name="variable_is_virtual[' + loop + ']" /></td>\
\
<td><label><?php _e('Enabled', 'woothemes'); ?></label><input type="checkbox" class="checkbox" name="variable_enabled[' + loop + ']" /></td>\
\
<td>\
<div class="show_if_variation_downloadable file_path_field"><label><?php _e('File path:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Enter a File Path to make this variation a downloadable product, or leave blank.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" class="file_path" name="variable_file_path[' + loop + ']" placeholder="<?php _e('File path/URL', 'woothemes'); ?>" /> <input type="button" class="upload_file_button button" value="<?php _e('&uarr;', 'woothemes'); ?>" /></div>\
</td>\
\
<td>\
<div class="show_if_variation_downloadable"><label><?php _e('Download Limit:', 'woothemes'); ?> <a class="tips" tip="<?php _e('Leave blank for unlimited re-downloads.', 'woothemes'); ?>" href="#">[?]</a></label><input type="text" size="5" name="variable_download_limit[' + loop + ']" placeholder="<?php _e('Unlimited', 'woothemes'); ?>" /></div>\
</td>\
</tr>\
</tbody>\
</table>\
Expand Down Expand Up @@ -356,6 +390,47 @@ function variable_product_write_panel_js() {
return false;
});

jQuery('a.toggle_virtual').click(function(){
var checkbox = jQuery('input[name^="variable_is_virtual"]');
checkbox.attr('checked', !checkbox.attr('checked'));
return false;
});

jQuery('a.toggle_downloadable').click(function(){
var checkbox = jQuery('input[name^="variable_is_downloadable"]');
checkbox.attr('checked', !checkbox.attr('checked'));
jQuery('input.variable_is_downloadable').change();
return false;
});

jQuery('a.toggle_enabled').click(function(){
var checkbox = jQuery('input[name^="variable_enabled"]');
checkbox.attr('checked', !checkbox.attr('checked'));
return false;
});

jQuery('a.set_all_paths').click(function(){
var value = prompt("<?php _e('Enter a file path/URL', 'woothemes'); ?>");
jQuery('input[name^="variable_file_path"]').val( value );
return false;
});

jQuery('a.set_all_limits').click(function(){
var value = prompt("<?php _e('Enter a download limit', 'woothemes'); ?>");
jQuery('input[name^="variable_download_limit"]').val( value );
return false;
});

jQuery('input.variable_is_downloadable').change(function(){

jQuery(this).parent().parent().find('.show_if_variation_downloadable').hide();

if (jQuery(this).is(':checked')) {
jQuery(this).parent().parent().find('.show_if_variation_downloadable').show();
}

}).change();

<?php endif; ?>

var current_field_wrapper;
Expand Down Expand Up @@ -630,6 +705,10 @@ function process_product_meta_variable( $post_id ) {
$variable_sale_price= $_POST['variable_sale_price'];
$upload_image_id = $_POST['upload_image_id'];
if (isset($_POST['variable_enabled'])) $variable_enabled = $_POST['variable_enabled'];
if (isset($_POST['variable_is_virtual'])) $variable_is_virtual = $_POST['variable_is_virtual'];
if (isset($_POST['variable_is_downloadable'])) $variable_is_downloadable = $_POST['variable_is_downloadable'];
$variable_file_path = $_POST['variable_file_path'];
$variable_download_limit = $_POST['variable_download_limit'];

$attributes = (array) maybe_unserialize( get_post_meta($post_id, 'product_attributes', true) );

Expand Down Expand Up @@ -683,6 +762,20 @@ function process_product_meta_variable( $post_id ) {
update_post_meta( $variation_id, 'stock', $variable_stock[$i] );
update_post_meta( $variation_id, '_thumbnail_id', $upload_image_id[$i] );

if (isset($variable_is_virtual[$i])) $is_virtual = 'yes'; else $is_virtual = 'no';
if (isset($variable_is_downloadable[$i])) $is_downloadable = 'yes'; else $is_downloadable = 'no';

update_post_meta( $variation_id, 'virtual', $is_virtual );
update_post_meta( $variation_id, 'downloadable', $is_downloadable );

if ($is_downloadable=='yes') :
update_post_meta( $variation_id, 'download_limit', $variable_download_limit[$i] );
update_post_meta( $variation_id, 'file_path', $variable_file_path[$i] );
else :
update_post_meta( $variation_id, 'download_limit', '' );
update_post_meta( $variation_id, 'file_path', '' );
endif;

// Remove old taxnomies attributes so data is kept up to date
$variation_custom_fields = get_post_custom( $variation_id );

Expand Down
48 changes: 5 additions & 43 deletions admin/writepanels/writepanel-product_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ function woocommerce_product_data_box() {
$file_path = get_post_meta($post->ID, 'file_path', true);
$field = array( 'id' => 'file_path', 'label' => __('File path', 'woothemes') );
echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].':</label>
<input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$file_path.'" placeholder="'.__('File path/URL', 'woothemes').'" />
<input type="text" class="short file_path" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$file_path.'" placeholder="'.__('File path/URL', 'woothemes').'" />
<input type="button" class="upload_file_button button" value="'.__('Upload a file', 'woothemes').'" />
</p>';

Expand All @@ -398,7 +398,7 @@ function woocommerce_product_data_box() {
$field = array( 'id' => 'download_limit', 'label' => __('Download Limit', 'woothemes') );
echo '<p class="form-field">
<label for="'.$field['id'].'">'.$field['label'].':</label>
<input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$download_limit.'" /> <span class="description">' . __('Leave blank for unlimited re-downloads.', 'woothemes') . '</span></p>';
<input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$download_limit.'" placeholder="'.__('Unlimited', 'woothemes').'" /> <span class="description">' . __('Leave blank for unlimited re-downloads.', 'woothemes') . '</span></p>';

?>
</div>
Expand Down Expand Up @@ -749,9 +749,9 @@ function woocommerce_product_type_box() {
'hidden' => __('Hidden', 'woothemes')
) ) );

woocommerce_wp_checkbox( array( 'id' => 'virtual', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Virtual', 'woothemes'), 'description' => __('Enable this option if a product is not shipped or there is no shipping cost', 'woothemes') ) );
woocommerce_wp_checkbox( array( 'id' => 'virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woothemes'), 'description' => __('Enable this option if a product is not shipped or there is no shipping cost', 'woothemes') ) );

woocommerce_wp_checkbox( array( 'id' => 'downloadable', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Downloadable', 'woothemes'), 'description' => __('Enable this option if access is given to a downloadable file upon purchase of a product', 'woothemes') ) );
woocommerce_wp_checkbox( array( 'id' => 'downloadable', 'wrapper_class' => 'show_if_simple', 'label' => __('Downloadable', 'woothemes'), 'description' => __('Enable this option if access is given to a downloadable file upon purchase of a product', 'woothemes') ) );

// Featured
woocommerce_wp_checkbox( array( 'id' => 'featured', 'label' => __('Featured', 'woothemes'), 'description' => __('Enable this option to feature this product', 'woothemes') ) );
Expand All @@ -761,46 +761,8 @@ function woocommerce_product_type_box() {
}

/**
* Product Type Javascript
*
* Javascript for the downloadable product type
* Change label for insert buttons
*/
add_action('woocommerce_product_write_panel_js', 'downloadable_product_write_panel_js');

function downloadable_product_write_panel_js() {
global $post;
?>
jQuery(function(){

window.send_to_editor_default = window.send_to_editor;

jQuery('.upload_file_button').live('click', function(){

var post_id = <?php echo $post->ID; ?>;

formfield = jQuery('#file_path').attr('name');

window.send_to_editor = window.send_to_download_url;

tb_show('', 'media-upload.php?post_id=' + post_id + '&amp;type=file&amp;from=wc01&amp;TB_iframe=true');
return false;
});

window.send_to_download_url = function(html) {

file_url = jQuery(html).attr('href');
if (file_url) {
jQuery('#file_path').val(file_url);
}
tb_remove();
window.send_to_editor = window.send_to_editor_default;

}

});
<?php
}

add_filter( 'gettext', 'woocommerce_change_insert_into_post', null, 2 );

function woocommerce_change_insert_into_post( $translation, $original ) {
Expand Down
Loading

0 comments on commit 8b125d1

Please sign in to comment.