Changeset 2322821
- Timestamp:
- 06/12/2020 07:22:43 AM (6 years ago)
- Location:
- mobile-builder/trunk
- Files:
-
- 5 edited
-
api/class-mobile-builder-cart.php (modified) (3 diffs)
-
api/class-mobile-builder-vendor.php (modified) (2 diffs)
-
helpers/mobile-builder-functions.php (modified) (1 diff)
-
includes/class-mobile-builder.php (modified) (1 diff)
-
mobile-builder.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mobile-builder/trunk/api/class-mobile-builder-cart.php
r2311294 r2322821 60 60 register_rest_route( $this->namespace, 'cart', array( 61 61 array( 62 'methods' => WP_REST_Server::READABLE,63 'callback' => array( $this, 'get_cart' ),62 'methods' => WP_REST_Server::READABLE, 63 'callback' => array( $this, 'get_cart' ), 64 64 'permission_callback' => array( $this, 'user_permissions_check' ), 65 65 ), 66 66 array( 67 'methods' => WP_REST_Server::CREATABLE,68 'callback' => array( $this, 'add_to_cart' ),67 'methods' => WP_REST_Server::CREATABLE, 68 'callback' => array( $this, 'add_to_cart' ), 69 69 'permission_callback' => array( $this, 'user_permissions_check' ), 70 70 ) … … 72 72 73 73 register_rest_route( $this->namespace, 'update-shipping', array( 74 'methods' => WP_REST_Server::CREATABLE,75 'callback' => array( $this, 'update_shipping' ),74 'methods' => WP_REST_Server::CREATABLE, 75 'callback' => array( $this, 'update_shipping' ), 76 76 'permission_callback' => array( $this, 'user_permissions_check' ), 77 77 ) ); 78 78 79 79 register_rest_route( $this->namespace, 'update-order-review', array( 80 'methods' => WP_REST_Server::CREATABLE,81 'callback' => array( $this, 'mobile_builder_update_order_review' ),80 'methods' => WP_REST_Server::CREATABLE, 81 'callback' => array( $this, 'mobile_builder_update_order_review' ), 82 82 'permission_callback' => array( $this, 'user_permissions_check' ), 83 83 ) ); 84 84 85 85 register_rest_route( $this->namespace, 'checkout', array( 86 'methods' => WP_REST_Server::CREATABLE,87 'callback' => array( $this, 'checkout' ),86 'methods' => WP_REST_Server::CREATABLE, 87 'callback' => array( $this, 'checkout' ), 88 88 'permission_callback' => array( $this, 'user_permissions_check' ), 89 89 ) ); 90 90 91 91 register_rest_route( $this->namespace, 'cart-total', array( 92 'methods' => WP_REST_Server::READABLE,93 'callback' => array( $this, 'get_total' ),92 'methods' => WP_REST_Server::READABLE, 93 'callback' => array( $this, 'get_total' ), 94 94 'permission_callback' => array( $this, 'user_permissions_check' ), 95 95 ) ); 96 96 97 97 register_rest_route( $this->namespace, 'shipping-methods', array( 98 'methods' => WP_REST_Server::READABLE,99 'callback' => array( $this, 'shipping_methods' ),98 'methods' => WP_REST_Server::READABLE, 99 'callback' => array( $this, 'shipping_methods' ), 100 100 'permission_callback' => array( $this, 'user_permissions_check' ), 101 101 ) ); 102 102 103 103 register_rest_route( $this->namespace, 'set-quantity', array( 104 'methods' => WP_REST_Server::CREATABLE,105 'callback' => array( $this, 'set_quantity' ),104 'methods' => WP_REST_Server::CREATABLE, 105 'callback' => array( $this, 'set_quantity' ), 106 106 'permission_callback' => array( $this, 'user_permissions_check' ), 107 107 ) ); 108 108 109 109 register_rest_route( $this->namespace, 'remove-cart-item', array( 110 'methods' => WP_REST_Server::CREATABLE,111 'callback' => array( $this, 'remove_cart_item' ),110 'methods' => WP_REST_Server::CREATABLE, 111 'callback' => array( $this, 'remove_cart_item' ), 112 112 'permission_callback' => array( $this, 'user_permissions_check' ), 113 113 ) ); 114 114 115 115 register_rest_route( $this->namespace, 'add-discount', array( 116 'methods' => WP_REST_Server::CREATABLE,117 'callback' => array( $this, 'add_discount' ),116 'methods' => WP_REST_Server::CREATABLE, 117 'callback' => array( $this, 'add_discount' ), 118 118 'permission_callback' => array( $this, 'user_permissions_check' ), 119 119 ) ); 120 120 121 121 register_rest_route( $this->namespace, 'remove-coupon', array( 122 'methods' => WP_REST_Server::CREATABLE,123 'callback' => array( $this, 'remove_coupon' ),122 'methods' => WP_REST_Server::CREATABLE, 123 'callback' => array( $this, 'remove_coupon' ), 124 124 'permission_callback' => array( $this, 'user_permissions_check' ), 125 125 ) ); … … 642 642 * @param $request 643 643 * 644 * @return bool 644 645 * @since 1.0.0 645 * @return bool646 646 */ 647 647 public function user_permissions_check( $request ) { 648 return is_user_logged_in(); 648 $isLogin = is_user_logged_in(); 649 650 if ( ! $isLogin ) { 651 return new WP_Error( 'mobile_builder_can_not_add_to_cart', __( 'Sorry, you need login to add to cart.', 'mobile_builder' ) ); 652 } 653 654 return true; 649 655 } 650 656 } -
mobile-builder/trunk/api/class-mobile-builder-vendor.php
r2311294 r2322821 85 85 'methods' => WP_REST_Server::READABLE, 86 86 'callback' => array( $this, 'vendor' ), 87 ) ); 88 89 register_rest_route( $namespace, 'delivery-boy-delivery-stat', array( 90 'methods' => WP_REST_Server::READABLE, 91 'callback' => array( $this, 'delivery_boy_delivery_stat' ), 87 92 ) ); 88 93 … … 397 402 return json_decode( mobile_builder_request( 'GET', $url ) ); 398 403 } 404 405 /** 406 * 407 * Get delivery boy delivery stat 408 * 409 * @param $request 410 * 411 * @return array 412 */ 413 public function delivery_boy_delivery_stat( $request ) { 414 $delivery_boy_id = $request->get_param( 'delivery_boy_id' ); 415 416 return array( 417 "delivered" => function_exists( 'wcfm_get_delivery_boy_delivery_stat' ) ? wcfm_get_delivery_boy_delivery_stat( $delivery_boy_id, 'delivered' ) : 0, 418 "pending" => function_exists( 'wcfm_get_delivery_boy_delivery_stat' ) ? wcfm_get_delivery_boy_delivery_stat( $delivery_boy_id, 'pending' ) : 0, 419 ); 420 } 421 422 /** 423 * 424 * Send notification for user 425 * 426 * @param $order_id 427 * @param $order_item_id 428 * @param $wcfm_tracking_data 429 * @param $product_id 430 * @param $wcfm_delivery_boy 431 * @param $wcfm_messages 432 */ 433 public function delivery_boy_assigned_notification( $order_id, $order_item_id, $wcfm_tracking_data, $product_id, $wcfm_delivery_boy, $wcfm_messages ) { 434 $content = array( 435 "en" => strip_tags( $wcfm_messages ) 436 ); 437 438 $fields = array( 439 'app_id' => MOBILE_BUILDER_ONESIGNAL_APP_ID_DELIVERY_APP, 440 'filters' => array( 441 array( 442 "field" => "tag", 443 "key" => "user_id", 444 "relation" => "=", 445 "value" => $wcfm_delivery_boy 446 ) 447 ), 448 'data' => array( "user_id" => $wcfm_delivery_boy ), 449 'contents' => $content 450 ); 451 452 mobile_builder_send_notification( $fields, MOBILE_BUILDER_ONESIGNAL_API_KEY_DELIVERY_APP ); 453 } 454 455 /** 456 * Send a Notification event when an order status is changed. 457 * 458 * @param int $id Order id. 459 * @param string $previous_status the old WooCommerce order status. 460 * @param string $next_status the new WooCommerce order status. 461 */ 462 public function notification_order_status_changed( $id, $previous_status, $next_status ) { 463 464 $order = wc_get_order( $id ); 465 466 $content = array( 467 "en" => sprintf( __( 'Order %s changed to %s' ), $order->get_order_number(), $next_status ), 468 ); 469 470 $fields = array( 471 'app_id' => MOBILE_BUILDER_ONESIGNAL_APP_ID, 472 'filters' => array( 473 array( 474 "field" => "tag", 475 "key" => "user_id", 476 "relation" => "=", 477 "value" => $order->get_user_id(), 478 ) 479 ), 480 'data' => array( "user_id" => $order->get_user_id() ), 481 'contents' => $content 482 ); 483 484 mobile_builder_send_notification( $fields, MOBILE_BUILDER_ONESIGNAL_API_KEY ); 485 } 399 486 } -
mobile-builder/trunk/helpers/mobile-builder-functions.php
r2304807 r2322821 57 57 * @return mixed 58 58 */ 59 function mobile_builder_distance_matrix( $origin_string, $destinations_string, $key, $units = 'metric') {59 function mobile_builder_distance_matrix( $origin_string, $destinations_string, $key, $units = 'metric' ) { 60 60 $google_map_api = 'https://maps.googleapis.com/maps/api'; 61 $url = "$google_map_api/distancematrix/json?units=$units&origins=$origin_string&destinations=$destinations_string&key=$key"; 61 $url = "$google_map_api/distancematrix/json?units=$units&origins=$origin_string&destinations=$destinations_string&key=$key"; 62 62 63 return json_decode( mobile_builder_request( 'GET', $url ) )->rows; 63 64 } 65 66 /** 67 * 68 * Send Notification 69 * 70 * @param $fields 71 * @param $api_key 72 * 73 * @return bool|string 74 */ 75 function mobile_builder_send_notification( $fields, $api_key ) { 76 $fields = json_encode( $fields ); 77 78 $ch = curl_init(); 79 curl_setopt( $ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications" ); 80 curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 81 'Content-Type: application/json; charset=utf-8', 82 'Authorization: Basic ' . $api_key, 83 ) ); 84 85 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 86 curl_setopt( $ch, CURLOPT_HEADER, false ); 87 curl_setopt( $ch, CURLOPT_POST, true ); 88 curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields ); 89 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); 90 91 $result = curl_exec( $ch ); 92 curl_close( $ch ); 93 94 return $result; 95 } -
mobile-builder/trunk/includes/class-mobile-builder.php
r2309299 r2322821 219 219 $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_list_by_vendor', 501, 2 ); 220 220 $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_distance', 501, 2 ); 221 $this->loader->add_action( 'wcfmd_after_delivery_boy_assigned', $plugin_api, 'delivery_boy_assigned_notification', 10, 6 ); 222 $this->loader->add_action( 'woocommerce_order_status_changed', $plugin_api, 'notification_order_status_changed', 10, 3 ); 221 223 222 224 } -
mobile-builder/trunk/mobile-builder.php
r2303204 r2322821 11 11 * Plugin URI: https://doc-oreo.rnlab.io 12 12 * Description: The most advanced drag & drop app builder. Create multi templates and app controls. 13 * Version: 1.0. 013 * Version: 1.0.1 14 14 * Author: Rnlab.io 15 15 * Author URI: https://rnlab.io
Note: See TracChangeset
for help on using the changeset viewer.