Skip to content

Commit

Permalink
feat: Add Cancel order
Browse files Browse the repository at this point in the history
  • Loading branch information
zarei-dev committed Aug 21, 2022
1 parent 9f85b79 commit 039e7cb
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
pod_ajax( data, _callback_pdf );
})

$('#pod-cancel-order, .pod-cancel-order').on('click', function(e) {
e.preventDefault();
var order_id = $(this).attr('data-order_id');

const data = {
'action': 'cancel_order',
security: wp_podro_ajax_object.security,
'order_id': order_id
};

pod_ajax( data, _callback_cancel_order );
})

function _callback_cancel_order( response ) {
location.reload();
}

function _callback_pdf( response ) {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
Expand Down
4 changes: 3 additions & 1 deletion assets/sass/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ select.pod-error {
}

#get_order_pdf,
.get_order_pdf {
.get_order_pdf,
#pod-cancel-order,
.pod-cancel-order {
cursor: pointer;
}
9 changes: 9 additions & 0 deletions inc/API/V1/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ public function get_order_pdf( $order_id ) {
}
return $response;
}

public function delete_order( $order_id ) {
$url = Routes::BuildRoute( Routes::ORDER_DELETE, array( 'order_id' => $order_id ) );
$response = Request_Podro::delete( $url, false );
if (is_wp_error($response) || !isset($response->body)) {
return false;
}
return $response;
}
}
23 changes: 23 additions & 0 deletions inc/MetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,27 @@ private function get_store_address() {
private function get_store_phone_number() {
return get_option('woocommerce_store_phone');
}

public function ajax_cancel_order() {
// checking for nonce
$this->validate_nonce( 'pod-options-nonce' );
// checking for required fields
if ( !isset($_POST['order_id']) ) {
wp_send_json_error( __('آیتم اشتباه شده است.', POD_TEXTDOMAIN), 400 );
wp_die();
}

$order_id = sanitize_text_field( $_POST['order_id'] );

$response = (new Orders)->delete_order( $order_id);

if ( !$response || is_wp_error($response) ) {
wp_send_json_error( $response['message'], 403 );
wp_die();
}


wp_send_json_success( $response );
wp_die();
}
}
19 changes: 11 additions & 8 deletions inc/Podro_Order_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public function prepare_items()
public function get_columns()
{
$columns = array(
'id' => 'ID',
'provider' => 'Provider',
'order_status' => 'Order Status',
'pickup_in' => 'Pickup in',
'pickup_to' => 'Pickup to',
'order' => 'Order',
'pdf' => 'PDF'
'id' => 'شناسه',
'provider' => 'پروایدر',
'order_status' => 'وضعیت',
'pickup_in' => 'پیکاپ در',
'pickup_to' => 'پیکاپ تا',
'order' => 'سفارش',
'pdf' => 'PDF',
'cancel' => 'لغو',
);

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

Expand All @@ -130,6 +132,7 @@ public function column_default( $item, $column_name )
case 'pickup_to':
case 'order':
case 'pdf':
case 'cancel':
return $item[ $column_name ];

default:
Expand Down
1 change: 1 addition & 0 deletions inc/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private function load_dependencies() {
$this->loader->add_action( 'wp_ajax_pod_delivery_step_3', $MetaBox, 'ajax_saving_options_step_3' );
$this->loader->add_action( 'wp_ajax_pod_delivery_step_4', $MetaBox, 'ajax_saving_options_step_4' );
$this->loader->add_action( 'wp_ajax_pod_token', $MetaBox, 'ajax_get_token' );
$this->loader->add_action( 'wp_ajax_cancel_order', $MetaBox, 'ajax_cancel_order' );

// Register shipping method
require_once( POD_PLUGIN_ROOT . 'WC/Shipping_Method.php' );
Expand Down

0 comments on commit 039e7cb

Please sign in to comment.