postcode saving

This commit is contained in:
Mike Jolley 2015-12-10 18:33:59 +00:00
parent 4893db3afe
commit 66d4065ae4
6 changed files with 60 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -2131,7 +2131,7 @@ table.wc_shipping_zones {
background: #f9f9f9;
}
}
ul {
ul, p {
margin: 0;
}
td.wc-shipping-zone-sort {
@ -2177,9 +2177,25 @@ table.wc_shipping_zones {
}
.wc-shipping-zone-name,
.wc-shipping-zone-region {
input, select {
input, select, textarea {
width: 100%;
}
.wc-shipping-zone-postcodes-toggle {
float: right;
margin: 0;
font-size: 0.9em;
color: #999;
}
.wc-shipping-zone-postcodes {
display:none;
textarea {
margin-top: 1em;
}
.description {
font-size: 0.9em;
color: #999;
}
}
}
.wc-shipping-zone-actions {
width: 3em;

View File

@ -62,8 +62,7 @@
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
$save_button.on( 'click', { view: this }, this.onSubmit );
$save_button.attr( 'disabled','disabled' );
$table.find( '.wc-shipping-zone-add' ).on( 'click', { view: this }, this.onAddNewRow );
$( '.wc-shipping-zone-add' ).on( 'click', { view: this }, this.onAddNewRow );
},
render: function() {
var zones = _.indexBy( this.model.get( 'zones' ), 'zone_id' ),
@ -86,7 +85,19 @@
// Select values in region select
_.each( rowData.zone_locations, function( location ) {
$tr.find( 'option[value="' + location.type + ':' + location.code + '"]' ).prop( 'selected', true );
if ( 'postcode' === location.type ) {
var postcode_field = $tr.find( '.wc-shipping-zone-postcodes :input' );
if ( postcode_field.val() ) {
postcode_field.val( postcode_field.val() + "\n" + location.code );
} else {
postcode_field.val( location.code );
}
$tr.find( '.wc-shipping-zone-postcodes' ).show();
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
} else {
$tr.find( 'option[value="' + location.type + ':' + location.code + '"]' ).prop( 'selected', true );
}
} );
// Editing?
@ -100,6 +111,7 @@
this.$el.find('.edit').hide();
this.$el.find( '.wc-shipping-zone-edit' ).on( 'click', { view: this }, this.onEditRow );
this.$el.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow );
this.$el.find( '.wc-shipping-zone-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes );
this.$el.find('.editing .wc-shipping-zone-edit').trigger('click');
// Stripe
@ -115,6 +127,8 @@
event.preventDefault();
},
onAddNewRow: function( event ) {
event.preventDefault();
var view = event.data.view,
model = view.model,
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
@ -140,8 +154,12 @@
model.logChanges( changes );
view.render();
return false;
},
onTogglePostcodes: function( event ) {
event.preventDefault();
var $tr = $( this ).closest( 'tr');
$tr.find( '.wc-shipping-zone-postcodes' ).show();
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
},
onEditRow: function( event ) {
event.preventDefault();

View File

@ -68,7 +68,11 @@
}
?>
</select>
<a class="wc-shipping-zone-postcodes" href="#"><?php _e( 'Limit to specific ZIP/postcodes', 'woocommerce' ); ?></a>
<a class="wc-shipping-zone-postcodes-toggle" href="#"><?php _e( 'Limit to specific ZIP/postcodes', 'woocommerce' ); ?></a>
<div class="wc-shipping-zone-postcodes">
<textarea name="zone_postcodes[{{ data.zone_id }}]" data-attribute="zone_postcodes" placeholder="<?php esc_attr_e( 'List 1 postcode per line', 'woocommerce' ); ?>" class="input-text large-text" cols="25" rows="5"></textarea>
<span class="description"><?php _e( 'Wildcards and numerical ranges are supported too, for example, 90210-99000 and CB23*', 'woocommerce' ) ?></span>
</div>
</div>
</td>
<td class="wc-shipping-zone-methods"><a class="wc-shipping-zone-add-method button" href="#"><?php esc_html_e( 'Add a shipping method', 'woocommerce' ); ?></a></td>

View File

@ -3057,7 +3057,8 @@ class WC_AJAX {
'zone_id' => 1,
'zone_name' => 1,
'zone_order' => 1,
'zone_locations' => 1
'zone_locations' => 1,
'zone_postcodes' => 1
) );
if ( isset( $zone_data['zone_id'] ) ) {
@ -3091,6 +3092,13 @@ class WC_AJAX {
}
}
if ( isset( $zone_data['zone_postcodes'] ) ) {
$postcodes = array_filter( array_map( 'strtoupper', array_map( 'wc_clean', explode( "\n", $zone_data['zone_postcodes'] ) ) ) );
foreach ( $postcodes as $postcode ) {
$zone->add_location( $postcode, 'postcode' );
}
}
$zone->save();
}
}

View File

@ -115,6 +115,10 @@ class WC_Shipping_Zone {
$location_parts[] = $all_states[ $location_codes[ 0 ] ][ $location_codes[ 1 ] ];
}
foreach ( $postcodes as $location ) {
$location_parts[] = $location->code;
}
if ( sizeof( $location_parts ) > $max ) {
$remaining = sizeof( $location_parts ) - $max;
return sprintf( _n( '%s and %d other region', '%s and %d other regions', $remaining, 'woocommerce' ), implode( ', ', array_splice( $location_parts, 0, $max ) ), $remaining );