Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id check with pickup points #193

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions assets/js/admin-order-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
post_form.find('#postnl-field-container').append('<input type="hidden" name="postnl_default_shipping_options_be" value="' + tb_window.find('#postnl_default_shipping_options_be').val() + '">');
post_form.find('#postnl-field-container').append('<input type="hidden" name="postnl_default_shipping_options_eu" value="' + tb_window.find('#postnl_default_shipping_options_eu').val() + '">');
post_form.find('#postnl-field-container').append('<input type="hidden" name="postnl_default_shipping_options_row" value="' + tb_window.find('#postnl_default_shipping_options_row').val() + '">');
post_form.find('#postnl-field-container').append('<input type="hidden" name="postnl_default_shipping_options_pickup" value="' + tb_window.find('#postnl_default_shipping_options_pickup').val() + '">');
jQuery( this ).prop( 'disabled', true );
post_form.submit();
} );
Expand Down
16 changes: 16 additions & 0 deletions assets/js/admin-order-single.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,21 @@

postnl_order_single.init();

if ( $( 'div.pickup-points-info' ).length ) {
$( '#postnl_id_check, #postnl_insured_shipping' ).on( 'change', function() {
// Get the ID of the current checkbox
var currentId = $(this).attr( 'id' );

// Uncheck the other checkbox
if ( $(this).is( ':checked' ) ) {
if ( currentId === 'postnl_id_check' ) {
$( '#postnl_insured_shipping' ).prop( 'checked', false );
} else {
$( '#postnl_id_check' ).prop( 'checked', false );
}
}
});
}

window.postnl_order_single_refresh = postnl_order_single.refresh_items;
} )( jQuery );
24 changes: 24 additions & 0 deletions src/Helper/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public static function products_data() {
),
),
),
array(
'combination' => array( 'id_check', 'insured_shipping' ),
'code' => '3443',
'options' => array(
array(
'characteristic' => '002',
'option' => '014',
),
),
),
),
'pickup_points' => array(
array(
Expand All @@ -147,6 +157,16 @@ public static function products_data() {
'code' => '3534',
'options' => array(),
),
array(
'combination' => array( 'id_check' ),
'code' => '3571',
'options' => array(
array(
'characteristic' => '002',
'option' => '014',
),
),
),
)
),
'BE' => array(
Expand Down Expand Up @@ -639,6 +659,8 @@ public static function shipping_return_labels_options() {
'3089',
'3533',
'3534',
'3443',
'3571',
),
'options' => array(
array(
Expand All @@ -662,6 +684,8 @@ public static function shipping_return_labels_options() {
'3089',
'3533',
'3534',
'3443',
'3571',
),
'options' => array(
array(
Expand Down
6 changes: 6 additions & 0 deletions src/Order/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public function get_shipping_options( $order ) {

// Get from the plugin settings
$delivery_zone = $this->get_shipping_zone( $order );
$frontend_data = $this->get_frontend_data( $order->get_id() );

if ( ! empty( $frontend_data['dropoff_points'] ) ) {
$delivery_zone = 'PICKUP';
}

if ( 'NL' === $delivery_zone && Utils::is_eligible_auto_letterbox( $order ) ) {
return array( 'letterbox' => 'yes' );
}
Expand Down
73 changes: 44 additions & 29 deletions src/Order/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ public function bulk_action_create_label( $redirect, $doaction, $object_ids ) {
* @return string
*/
public function bulk_action_change_shipping_options( $redirect, $doaction, $object_ids ) {

if ( 'postnl-change-shipping-options' !== $doaction ) {
if ( 'postnl-change-shipping-options' !== $doaction || empty( $object_ids ) ) {
return $redirect;
}

Expand All @@ -142,32 +141,38 @@ public function bulk_action_change_shipping_options( $redirect, $doaction, $obje
$selected_shipping_options = $this->prepare_default_options( $_REQUEST );
$zone = strtoupper( sanitize_text_field( $_REQUEST['postnl_shipping_zone'] ) );

if ( ! empty( $object_ids ) ) {
foreach ( $object_ids as $order_id ) {
$order = wc_get_order( $order_id );
$have_label_file = $this->have_label_file( $order );
$match_shipping_zones = $zone === $this->get_shipping_zone( $order );

if ( $have_label_file ) {
$array_messages[] = array(
'message' => sprintf( esc_html__( 'Order #%1$d already has a label.', 'postnl-for-woocommerce' ), $order_id ),
'type' => 'error',
);
}
foreach ( $object_ids as $order_id ) {
$order = wc_get_order( $order_id );
$have_label_file = $this->have_label_file( $order );
$match_shipping_zones = $zone === $this->get_shipping_zone( $order );
$match_pickup_zone = 'PICKUP' === $zone && 'NL' === $this->get_shipping_zone( $order );
if ( $have_label_file ) {
$array_messages[] = array(
'message' => sprintf( esc_html__( 'Order #%1$d already has a label.', 'postnl-for-woocommerce' ), $order_id ),
'type' => 'error',
);

continue;
}

if ( ! $match_shipping_zones ) {
$array_messages[] = array(
'message' => sprintf( esc_html__( 'Order #%1$d is from another shipping zone.', 'postnl-for-woocommerce' ), $order_id ),
'type' => 'error',
);
}
if ( ! $match_shipping_zones && ! $match_pickup_zone ) {
$array_messages[] = array(
'message' => sprintf( esc_html__( 'Order #%1$d is from another shipping zone.', 'postnl-for-woocommerce' ), $order_id ),
'type' => 'error',
);

if ( ! $have_label_file && $match_shipping_zones ) {
$order->delete_meta_data( $this->meta_name );
$order->update_meta_data( $this->meta_name, array( 'backend' => $selected_shipping_options ) );
$order->save();
}
continue;
}

$meta = $order->get_meta( $this->meta_name );

if ( ! is_array( $meta ) ) {
$meta = array();
}

$meta['backend'] = $selected_shipping_options;
$order->update_meta_data( $this->meta_name, $meta );
$order->save();
}

update_option( $this->bulk_option_text_name, $array_messages );
Expand Down Expand Up @@ -487,10 +492,11 @@ protected function change_shipping_options_fields() {
'value' => 'nl',
'container' => true,
'options' => array(
'nl' => __( 'Domestic', 'postnl-for-woocommerce' ),
'be' => __( 'Belgium', 'postnl-for-woocommerce' ),
'eu' => __( 'EU Parcel', 'postnl-for-woocommerce' ),
'row' => __( 'Non-EU Shipment', 'postnl-for-woocommerce' ),
'nl' => __( 'Domestic', 'postnl-for-woocommerce' ),
'be' => __( 'Belgium', 'postnl-for-woocommerce' ),
'eu' => __( 'EU Parcel', 'postnl-for-woocommerce' ),
'row' => __( 'Non-EU Shipment', 'postnl-for-woocommerce' ),
'pickup' => __( 'Pick-up at PostNL', 'postnl-for-woocommerce' ),
),
),
array(
Expand Down Expand Up @@ -529,6 +535,15 @@ protected function change_shipping_options_fields() {
'value' => $this->settings->get_country_option( 'default_shipping_options_' . 'row' ),
'options' => $this->get_available_shipping_options_per_zone( 'row' ),
),
array(
'id' => $this->prefix . 'default_shipping_options_pickup',
'type' => 'select',
'label' => __( 'Shipping options for Pick-up at PostNL', 'postnl-for-woocommerce' ),
'wrapper_class' => 'conditional pickup',
'container' => true,
'value' => $this->settings->get_country_option( 'default_shipping_options_' . 'pickup' ),
'options' => $this->get_available_shipping_options_per_zone( 'pickup' ),
),
);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Shipping_Method/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ public function get_setting_fields() {
'options' => array(
'standard_shipment' => __( 'Standard shipment', 'postnl-for-woocommerce' ),
'id_check' => __( 'ID Check', 'postnl-for-woocommerce' ),
'id_check|insured_shipping' => __( 'ID Check + Insured Shipping', 'postnl-for-woocommerce' ),
// 'insured_shipping' => __( 'Insured Shipping', 'postnl-for-woocommerce' ),
'return_no_answer' => __( 'Return if no answer', 'postnl-for-woocommerce' ),
'signature_on_delivery' => __( 'Signature on Delivery', 'postnl-for-woocommerce' ),
Expand Down Expand Up @@ -606,6 +607,17 @@ public function get_setting_fields() {
'packets|track_and_trace|insured_shipping' => __( 'Packets + Track & Trace + Insured', 'postnl-for-woocommerce' ),
),
),
'default_shipping_options_pickup' => array(
'title' => __( 'Default Shipping Pickup', 'postnl-for-woocommerce' ),
'type' => 'select',
'description' => __( 'Shipping options Pickup.', 'postnl-for-woocommerce' ),
'default' => 'id_check',
'for_country' => array( 'NL' ),
'options' => array(
'id_check' => __( 'ID Check', 'postnl-for-woocommerce' ),
'insured_shipping' => __( 'Insured Shipping', 'postnl-for-woocommerce' ),
),
),
'auto_complete_order' => array(
'title' => esc_html__( 'Automatically change order status to Completed', 'postnl-for-woocommerce' ),
'type' => 'checkbox',
Expand Down