"enabled" column

This commit is contained in:
Mike Jolley 2015-12-16 16:24:58 +00:00
parent 9aa34330ac
commit 8ebba9cc68
10 changed files with 33 additions and 203 deletions

File diff suppressed because one or more lines are too long

View File

@ -2227,6 +2227,15 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods {
line-height: 30px; line-height: 30px;
} }
} }
.wc-shipping-zone-method-enabled {
text-align: center;
.status-enabled {
display: inline-block;
&:before {
line-height: inherit;
}
}
}
.wc-shipping-zone-name, .wc-shipping-zone-name,
.wc-shipping-zone-methods { .wc-shipping-zone-methods {
width: 25%; width: 25%;

View File

@ -108,6 +108,12 @@
// Populate $tbody with the current methods // Populate $tbody with the current methods
$.each( methods, function( id, rowData ) { $.each( methods, function( id, rowData ) {
if ( 'yes' === rowData.enabled ) {
rowData.enabled_icon = '<span class="status-enabled tips" data-tip="' + data.strings.yes + '">' + data.strings.yes + '</span>';
} else {
rowData.enabled_icon = '&ndash;';
}
view.$el.append( view.rowTemplate( rowData ) ); view.$el.append( view.rowTemplate( rowData ) );
} ); } );

View File

@ -1 +1 @@
!function(a,b,c,d){a(function(){var e=a(".wc-shipping-zone-methods"),f=a(".wc-shipping-zone-method-rows"),g=a(".wc-shipping-zone-method-save"),h=c.template("wc-shipping-zone-method-row"),i=c.template("wc-shipping-zone-method-row-blank"),j=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{instance_id:c},a)}),this.changes=b,this.trigger("change:methods")},save:function(){_.size(this.changes)?a.post(d+"?action=woocommerce_shipping_zone_methods_save_changes",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,changes:this.changes,zone_id:b.zone_id},this.onSaveResponse,"json"):l.trigger("saved:methods")},addMethod:function(){_.size(this.changes)&&this.save(),a.post(d+"?action=woocommerce_shipping_zone_add_method",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,method_id:a('select[name="add_method_id"]').val(),zone_id:b.zone_id},this.onAddResponse,"json")},onSaveResponse:function(a,c){"success"===c&&(a.success?(l.set("methods",a.data.methods),l.trigger("change:methods"),l.changes={},l.trigger("saved:methods")):window.alert(b.strings.save_failed))},onAddResponse:function(a,c){"success"===c&&(a.success&&a.data.instance_id?(l.set("methods",a.data.methods),l.trigger("change:methods"),l.changes={},l.trigger("saved:methods")):window.alert(b.strings.add_method_failed))}}),k=Backbone.View.extend({rowTemplate:h,initialize:function(){this.listenTo(this.model,"change:methods",this.setUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.render),f.on("change",{view:this},this.updateModelOnChange),f.on("sortupdate",{view:this},this.updateModelOnSort),a(window).on("beforeunload",{view:this},this.unloadConfirmation),g.on("click",{view:this},this.onSubmit),a(".wc-shipping-zone-add-method").on("click",{view:this},this.onAdd)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var b=_.indexBy(this.model.get("methods"),"instance_id"),c=this;this.$el.empty(),this.unblock(),_.size(b)?(b=_.sortBy(b,function(a){return parseInt(a.method_order,10)}),a.each(b,function(a,b){c.$el.append(c.rowTemplate(b))}),this.$el.find(".wc-shipping-zone-method-delete").on("click",{view:this},this.onDeleteRow)):c.$el.append(i),this.initTooltips()},initTooltips:function(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAdd:function(a){a.data.view.block(),a.data.view.model.addMethod(),a.preventDefault()},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("methods"),"instance_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f[g]=_.extend(f[g]||{},{deleted:"deleted"}),d.set("methods",e),d.logChanges(f),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("methods"),"instance_id"),i={};h[e][f]!==g&&(i[e]={},i[e][f]=g,h[e][f]=g),c.logChanges(i)},updateModelOnSort:function(a){var b=a.data.view,c=b.model,d=_.indexBy(c.get("methods"),"instance_id"),f={};_.each(d,function(a){var b=parseInt(a.method_order,10),c=parseInt(e.find('tr[data-id="'+a.instance_id+'"]').index()+1,10);b!==c&&(f[a.instance_id]=_.extend(f[a.instance_id]||{},{method_order:c}))}),_.size(f)&&c.logChanges(f)}}),l=new j({methods:b.methods}),m=new k({model:l,el:f});m.render(),f.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-method-sort",scrollSensitivity:40})})}(jQuery,shippingZoneMethodsLocalizeScript,wp,ajaxurl); !function(a,b,c,d){a(function(){var e=a(".wc-shipping-zone-methods"),f=a(".wc-shipping-zone-method-rows"),g=a(".wc-shipping-zone-method-save"),h=c.template("wc-shipping-zone-method-row"),i=c.template("wc-shipping-zone-method-row-blank"),j=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{instance_id:c},a)}),this.changes=b,this.trigger("change:methods")},save:function(){_.size(this.changes)?a.post(d+"?action=woocommerce_shipping_zone_methods_save_changes",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,changes:this.changes,zone_id:b.zone_id},this.onSaveResponse,"json"):l.trigger("saved:methods")},addMethod:function(){_.size(this.changes)&&this.save(),a.post(d+"?action=woocommerce_shipping_zone_add_method",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,method_id:a('select[name="add_method_id"]').val(),zone_id:b.zone_id},this.onAddResponse,"json")},onSaveResponse:function(a,c){"success"===c&&(a.success?(l.set("methods",a.data.methods),l.trigger("change:methods"),l.changes={},l.trigger("saved:methods")):window.alert(b.strings.save_failed))},onAddResponse:function(a,c){"success"===c&&(a.success&&a.data.instance_id?(l.set("methods",a.data.methods),l.trigger("change:methods"),l.changes={},l.trigger("saved:methods")):window.alert(b.strings.add_method_failed))}}),k=Backbone.View.extend({rowTemplate:h,initialize:function(){this.listenTo(this.model,"change:methods",this.setUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.render),f.on("change",{view:this},this.updateModelOnChange),f.on("sortupdate",{view:this},this.updateModelOnSort),a(window).on("beforeunload",{view:this},this.unloadConfirmation),g.on("click",{view:this},this.onSubmit),a(".wc-shipping-zone-add-method").on("click",{view:this},this.onAdd)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var c=_.indexBy(this.model.get("methods"),"instance_id"),d=this;this.$el.empty(),this.unblock(),_.size(c)?(c=_.sortBy(c,function(a){return parseInt(a.method_order,10)}),a.each(c,function(a,c){"yes"===c.enabled?c.enabled_icon='<span class="status-enabled tips" data-tip="'+b.strings.yes+'">'+b.strings.yes+"</span>":c.enabled_icon="&ndash;",d.$el.append(d.rowTemplate(c))}),this.$el.find(".wc-shipping-zone-method-delete").on("click",{view:this},this.onDeleteRow)):d.$el.append(i),this.initTooltips()},initTooltips:function(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAdd:function(a){a.data.view.block(),a.data.view.model.addMethod(),a.preventDefault()},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("methods"),"instance_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f[g]=_.extend(f[g]||{},{deleted:"deleted"}),d.set("methods",e),d.logChanges(f),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("methods"),"instance_id"),i={};h[e][f]!==g&&(i[e]={},i[e][f]=g,h[e][f]=g),c.logChanges(i)},updateModelOnSort:function(a){var b=a.data.view,c=b.model,d=_.indexBy(c.get("methods"),"instance_id"),f={};_.each(d,function(a){var b=parseInt(a.method_order,10),c=parseInt(e.find('tr[data-id="'+a.instance_id+'"]').index()+1,10);b!==c&&(f[a.instance_id]=_.extend(f[a.instance_id]||{},{method_order:c}))}),_.size(f)&&c.logChanges(f)}}),l=new j({methods:b.methods}),m=new k({model:l,el:f});m.render(),f.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-method-sort",scrollSensitivity:40})})}(jQuery,shippingZoneMethodsLocalizeScript,wp,ajaxurl);

View File

@ -46,7 +46,8 @@ class WC_Admin_Shipping_Zones {
'strings' => array( 'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ), 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ), 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
'add_method_failed' => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ) 'add_method_failed' => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ),
'yes' => __( 'Yes', 'woocommerce' ),
), ),
) ); ) );
wp_enqueue_script( 'wc-shipping-zone-methods' ); wp_enqueue_script( 'wc-shipping-zone-methods' );

View File

@ -7,13 +7,14 @@
<th class="wc-shipping-zone-method-sort">&nbsp;</th> <th class="wc-shipping-zone-method-sort">&nbsp;</th>
<th class="wc-shipping-zone-method-title"><?php esc_html_e( 'Title', 'woocommerce' ); ?></th> <th class="wc-shipping-zone-method-title"><?php esc_html_e( 'Title', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-type"><?php esc_html_e( 'Type', 'woocommerce' ); ?></th> <th class="wc-shipping-zone-method-type"><?php esc_html_e( 'Type', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-enabled"><?php esc_html_e( 'Enabled', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th> <th class="wc-shipping-zone-method-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-actions">&nbsp;</th> <th class="wc-shipping-zone-method-actions">&nbsp;</th>
</tr> </tr>
</thead> </thead>
<tfoot> <tfoot>
<tr> <tr>
<td colspan="5"> <td colspan="6">
<div class="wc-shipping-zone-method-selector"> <div class="wc-shipping-zone-method-selector">
<select name="add_method_id"> <select name="add_method_id">
<?php <?php
@ -37,7 +38,7 @@
<script type="text/html" id="tmpl-wc-shipping-zone-method-row-blank"> <script type="text/html" id="tmpl-wc-shipping-zone-method-row-blank">
<tr> <tr>
<td class="wc-shipping-zone-method-blank-state" colspan="5"> <td class="wc-shipping-zone-method-blank-state" colspan="6">
<p class="main"><?php _e( 'Add shipping methods to this zone', 'woocommerce' ); ?></p> <p class="main"><?php _e( 'Add shipping methods to this zone', 'woocommerce' ); ?></p>
<p><?php _e( 'You can add multiple shipping methods within this zone. Only customers within the zone will see them.', 'woocommerce' ); ?></p> <p><?php _e( 'You can add multiple shipping methods within this zone. Only customers within the zone will see them.', 'woocommerce' ); ?></p>
<p><?php _e( 'Choose a method from the dropdown below and click "add shipping method" to get started.', 'woocommerce' ); ?></p> <p><?php _e( 'Choose a method from the dropdown below and click "add shipping method" to get started.', 'woocommerce' ); ?></p>
@ -50,6 +51,7 @@
<td width="1%" class="wc-shipping-zone-method-sort"></td> <td width="1%" class="wc-shipping-zone-method-sort"></td>
<td class="wc-shipping-zone-method-title"><a href="admin.php?page=wc-shipping&amp;instance_id={{ data.instance_id }}">{{ data.title }}</a></td> <td class="wc-shipping-zone-method-title"><a href="admin.php?page=wc-shipping&amp;instance_id={{ data.instance_id }}">{{ data.title }}</a></td>
<td class="wc-shipping-zone-method-type">{{ data.method_title }}</td> <td class="wc-shipping-zone-method-type">{{ data.method_title }}</td>
<td class="wc-shipping-zone-method-enabled">{{{ data.enabled_icon }}}</td>
<td class="wc-shipping-zone-method-description">{{ data.method_description }}</td> <td class="wc-shipping-zone-method-description">{{ data.method_description }}</td>
<td class="wc-shipping-zone-method-actions"> <td class="wc-shipping-zone-method-actions">
<a class="wc-shipping-zone-method-delete tips" data-tip="<?php esc_attr_e( 'Delete', 'woocommerce' ); ?>" href="#"><?php _e( 'Delete', 'woocommerce' ); ?></a><a class="wc-shipping-zone-method-settings tips" data-tip="<?php esc_attr_e( 'Settings', 'woocommerce' ); ?>" href="admin.php?page=wc-shipping&amp;instance_id={{ data.instance_id }}"><?php _e( 'Settings', 'woocommerce' ); ?></a> <a class="wc-shipping-zone-method-delete tips" data-tip="<?php esc_attr_e( 'Delete', 'woocommerce' ); ?>" href="#"><?php _e( 'Delete', 'woocommerce' ); ?></a><a class="wc-shipping-zone-method-settings tips" data-tip="<?php esc_attr_e( 'Settings', 'woocommerce' ); ?>" href="admin.php?page=wc-shipping&amp;instance_id={{ data.instance_id }}"><?php _e( 'Settings', 'woocommerce' ); ?></a>

View File

@ -144,9 +144,11 @@ class WC_Shipping_Zone {
foreach ( $raw_methods as $raw_method ) { foreach ( $raw_methods as $raw_method ) {
if ( in_array( $raw_method->method_id, array_keys( $allowed_classes ) ) ) { if ( in_array( $raw_method->method_id, array_keys( $allowed_classes ) ) ) {
$class_name = $allowed_classes[ $raw_method->method_id ]; $class_name = $allowed_classes[ $raw_method->method_id ];
$methods[ $raw_method->instance_id ] = new $class_name( $raw_method->instance_id ); if ( class_exists( $class_name ) ) {
$methods[ $raw_method->instance_id ]->method_order = absint( $raw_method->method_order ); $methods[ $raw_method->instance_id ] = new $class_name( $raw_method->instance_id );
$methods[ $raw_method->instance_id ]->method_order = absint( $raw_method->method_order );
}
} }
} }

View File

@ -105,8 +105,8 @@ class WC_Shipping {
return apply_filters( 'woocommerce_shipping_methods', array( return apply_filters( 'woocommerce_shipping_methods', array(
'flat_rate' => 'WC_Shipping_Flat_Rate', 'flat_rate' => 'WC_Shipping_Flat_Rate',
'free_shipping' => 'WC_Shipping_Free_Shipping', 'free_shipping' => 'WC_Shipping_Free_Shipping',
'international_delivery' => 'WC_Shipping_International_Delivery', //'international_delivery' => 'WC_Shipping_International_Delivery',
'local_delivery' => 'WC_Shipping_Local_Delivery', //'local_delivery' => 'WC_Shipping_Local_Delivery',
'local_pickup' => 'WC_Shipping_Local_Pickup' 'local_pickup' => 'WC_Shipping_Local_Pickup'
) ); ) );
} }
@ -147,6 +147,9 @@ class WC_Shipping {
*/ */
public function register_shipping_method( $method ) { public function register_shipping_method( $method ) {
if ( ! is_object( $method ) ) { if ( ! is_object( $method ) ) {
if ( ! class_exists( $method ) ) {
return false;
}
$method = new $method(); $method = new $method();
} }
$this->shipping_methods[ $method->id ] = $method; $this->shipping_methods[ $method->id ] = $method;

View File

@ -1,67 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* International Delivery - Based on the Flat Rate Shipping Method.
*
* @class WC_Shipping_Flat_Rate
* @version 2.4.0
* @package WooCommerce/Classes/Shipping
* @author WooThemes
*/
class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'international_delivery';
$this->method_title = __( 'International Flat Rate', 'woocommerce' );
$this->method_description = __( 'International Flat Rate Shipping lets you charge a fixed rate for shipping.', 'woocommerce' );
$this->init();
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
parent::init_form_fields();
$this->form_fields['availability'] = array(
'title' => __( 'Availability', 'woocommerce' ),
'type' => 'select',
'class' => 'wc-enhanced-select',
'description' => '',
'default' => 'including',
'options' => array(
'including' => __( 'Selected countries', 'woocommerce' ),
'excluding' => __( 'Excluding selected countries', 'woocommerce' ),
)
);
}
/**
* is_available function.
*
* @param array $package
* @return bool
*/
public function is_available( $package ) {
if ( "no" === $this->enabled ) {
return false;
}
if ( 'including' === $this->availability ) {
if ( is_array( $this->countries ) && ! in_array( $package['destination']['country'], $this->countries ) ) {
return false;
}
} else {
if ( is_array( $this->countries ) && ( in_array( $package['destination']['country'], $this->countries ) || ! $package['destination']['country'] ) ) {
return false;
}
}
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true, $package );
}
}

View File

@ -1,126 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Local Delivery Shipping Method.
*
* A simple shipping method allowing local delivery as a shipping method.
*
* @class WC_Shipping_Local_Delivery
* @version 2.6.0
* @package WooCommerce/Classes/Shipping
* @author WooThemes
*/
class WC_Shipping_Local_Delivery extends WC_Shipping_Local_Pickup {
/**
* Constructor.
*/
public function __construct( $instance_id = 0 ) {
$this->id = 'local_delivery';
$this->instance_id = absint( $instance_id );
$this->method_title = __( 'Local Delivery', 'woocommerce' );
$this->method_description = __( 'Local delivery is a simple shipping method for delivering orders locally.', 'woocommerce' );
$this->supports = array(
'shipping-zones',
'instance-settings'
);
$this->init();
}
/**
* init function.
*/
public function init() {
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option( 'title' );
$this->type = $this->get_option( 'type' );
$this->fee = $this->get_option( 'fee' );
$this->type = $this->get_option( 'type' );
$this->codes = $this->get_option( 'codes' );
$this->availability = $this->get_option( 'availability' );
$this->countries = $this->get_option( 'countries' );
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* calculate_shipping function.
*
* @param array $package (default: array())
*/
public function calculate_shipping( $package = array() ) {
$shipping_total = 0;
switch ( $this->type ) {
case 'fixed' :
$shipping_total = $this->fee;
break;
case 'percent' :
$shipping_total = $package['contents_cost'] * ( $this->fee / 100 );
break;
case 'product' :
foreach ( $package['contents'] as $item_id => $values ) {
if ( $values['quantity'] > 0 && $values['data']->needs_shipping() ) {
$shipping_total += $this->fee * $values['quantity'];
}
}
break;
}
$this->add_rate( array(
'id' => $this->id . $this->instance_id,
'label' => $this->title,
'cost' => $shipping_total
) );
}
/**
* Init form fields.
*/
public function init_form_fields() {
$this->instance_form_fields = array(
'enabled' => array(
'title' => __( 'Enable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable local delivery', 'woocommerce' ),
'default' => 'no'
),
'title' => array(
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
'default' => __( 'Local Delivery', 'woocommerce' ),
'desc_tip' => true,
),
'type' => array(
'title' => __( 'Fee Type', 'woocommerce' ),
'type' => 'select',
'class' => 'wc-enhanced-select',
'description' => __( 'How to calculate delivery charges', 'woocommerce' ),
'default' => 'fixed',
'options' => array(
'fixed' => __( 'Fixed amount', 'woocommerce' ),
'percent' => __( 'Percentage of cart total', 'woocommerce' ),
'product' => __( 'Fixed amount per product', 'woocommerce' ),
),
'desc_tip' => true,
),
'fee' => array(
'title' => __( 'Delivery Fee', 'woocommerce' ),
'type' => 'price',
'description' => __( 'What fee do you want to charge for local delivery, disregarded if you choose free. Leave blank to disable.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => wc_format_localized_price( 0 )
)
);
}
}