Skip to content

Commit 039e7cb

Browse files
committed
feat: Add Cancel order
1 parent 9f85b79 commit 039e7cb

File tree

7 files changed

+65
-10
lines changed

7 files changed

+65
-10
lines changed

assets/css/admin.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/admin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@
1717
pod_ajax( data, _callback_pdf );
1818
})
1919

20+
$('#pod-cancel-order, .pod-cancel-order').on('click', function(e) {
21+
e.preventDefault();
22+
var order_id = $(this).attr('data-order_id');
23+
24+
const data = {
25+
'action': 'cancel_order',
26+
security: wp_podro_ajax_object.security,
27+
'order_id': order_id
28+
};
29+
30+
pod_ajax( data, _callback_cancel_order );
31+
})
32+
33+
function _callback_cancel_order( response ) {
34+
location.reload();
35+
}
36+
2037
function _callback_pdf( response ) {
2138
var myHeaders = new Headers();
2239
myHeaders.append("Content-Type", "application/json");

assets/sass/admin.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ select.pod-error {
391391
}
392392

393393
#get_order_pdf,
394-
.get_order_pdf {
394+
.get_order_pdf,
395+
#pod-cancel-order,
396+
.pod-cancel-order {
395397
cursor: pointer;
396398
}

inc/API/V1/Orders.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ public function get_order_pdf( $order_id ) {
6565
}
6666
return $response;
6767
}
68+
69+
public function delete_order( $order_id ) {
70+
$url = Routes::BuildRoute( Routes::ORDER_DELETE, array( 'order_id' => $order_id ) );
71+
$response = Request_Podro::delete( $url, false );
72+
if (is_wp_error($response) || !isset($response->body)) {
73+
return false;
74+
}
75+
return $response;
76+
}
6877
}

inc/MetaBox.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,27 @@ private function get_store_address() {
447447
private function get_store_phone_number() {
448448
return get_option('woocommerce_store_phone');
449449
}
450+
451+
public function ajax_cancel_order() {
452+
// checking for nonce
453+
$this->validate_nonce( 'pod-options-nonce' );
454+
// checking for required fields
455+
if ( !isset($_POST['order_id']) ) {
456+
wp_send_json_error( __('آیتم اشتباه شده است.', POD_TEXTDOMAIN), 400 );
457+
wp_die();
458+
}
459+
460+
$order_id = sanitize_text_field( $_POST['order_id'] );
461+
462+
$response = (new Orders)->delete_order( $order_id);
463+
464+
if ( !$response || is_wp_error($response) ) {
465+
wp_send_json_error( $response['message'], 403 );
466+
wp_die();
467+
}
468+
469+
470+
wp_send_json_success( $response );
471+
wp_die();
472+
}
450473
}

inc/Podro_Order_Table.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ public function prepare_items()
4343
public function get_columns()
4444
{
4545
$columns = array(
46-
'id' => 'ID',
47-
'provider' => 'Provider',
48-
'order_status' => 'Order Status',
49-
'pickup_in' => 'Pickup in',
50-
'pickup_to' => 'Pickup to',
51-
'order' => 'Order',
52-
'pdf' => 'PDF'
46+
'id' => 'شناسه',
47+
'provider' => 'پروایدر',
48+
'order_status' => 'وضعیت',
49+
'pickup_in' => 'پیکاپ در',
50+
'pickup_to' => 'پیکاپ تا',
51+
'order' => 'سفارش',
52+
'pdf' => 'PDF',
53+
'cancel' => 'لغو',
5354
);
5455

5556
return $columns;
@@ -105,7 +106,8 @@ private function table_data()
105106
'pickup_in' => $details['pickup_time'],
106107
'pickup_to' => $details['pickup_to_time'],
107108
'order' => '<a href="'. get_edit_post_link( $order_id ) .'">'. $order->post_title .'</a>',
108-
'pdf' => '<a class="get_order_pdf" data-order_id="' . $details['id'] . '">دریافت بارنامه</a>'
109+
'pdf' => '<a class="get_order_pdf" data-order_id="' . $details['id'] . '">دریافت بارنامه</a>',
110+
'cancel' => '<a class="pod-cancel-order" data-order_id="' . $details['id'] . '">لغو ارسال</a>'
109111
);
110112
}
111113

@@ -130,6 +132,7 @@ public function column_default( $item, $column_name )
130132
case 'pickup_to':
131133
case 'order':
132134
case 'pdf':
135+
case 'cancel':
133136
return $item[ $column_name ];
134137

135138
default:

inc/Setup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private function load_dependencies() {
127127
$this->loader->add_action( 'wp_ajax_pod_delivery_step_3', $MetaBox, 'ajax_saving_options_step_3' );
128128
$this->loader->add_action( 'wp_ajax_pod_delivery_step_4', $MetaBox, 'ajax_saving_options_step_4' );
129129
$this->loader->add_action( 'wp_ajax_pod_token', $MetaBox, 'ajax_get_token' );
130+
$this->loader->add_action( 'wp_ajax_cancel_order', $MetaBox, 'ajax_cancel_order' );
130131

131132
// Register shipping method
132133
require_once( POD_PLUGIN_ROOT . 'WC/Shipping_Method.php' );

0 commit comments

Comments
 (0)