Plugin Directory

Changeset 2322821


Ignore:
Timestamp:
06/12/2020 07:22:43 AM (6 years ago)
Author:
rnlab
Message:

version 1.0.1

Location:
mobile-builder/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • mobile-builder/trunk/api/class-mobile-builder-cart.php

    r2311294 r2322821  
    6060        register_rest_route( $this->namespace, 'cart', array(
    6161            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' ),
    6464                'permission_callback' => array( $this, 'user_permissions_check' ),
    6565            ),
    6666            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' ),
    6969                'permission_callback' => array( $this, 'user_permissions_check' ),
    7070            )
     
    7272
    7373        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' ),
    7676            'permission_callback' => array( $this, 'user_permissions_check' ),
    7777        ) );
    7878
    7979        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' ),
    8282            'permission_callback' => array( $this, 'user_permissions_check' ),
    8383        ) );
    8484
    8585        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' ),
    8888            'permission_callback' => array( $this, 'user_permissions_check' ),
    8989        ) );
    9090
    9191        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' ),
    9494            'permission_callback' => array( $this, 'user_permissions_check' ),
    9595        ) );
    9696
    9797        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' ),
    100100            'permission_callback' => array( $this, 'user_permissions_check' ),
    101101        ) );
    102102
    103103        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' ),
    106106            'permission_callback' => array( $this, 'user_permissions_check' ),
    107107        ) );
    108108
    109109        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' ),
    112112            'permission_callback' => array( $this, 'user_permissions_check' ),
    113113        ) );
    114114
    115115        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' ),
    118118            'permission_callback' => array( $this, 'user_permissions_check' ),
    119119        ) );
    120120
    121121        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' ),
    124124            'permission_callback' => array( $this, 'user_permissions_check' ),
    125125        ) );
     
    642642     * @param $request
    643643     *
     644     * @return bool
    644645     * @since 1.0.0
    645      * @return bool
    646646     */
    647647    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;
    649655    }
    650656}
  • mobile-builder/trunk/api/class-mobile-builder-vendor.php

    r2311294 r2322821  
    8585            'methods'  => WP_REST_Server::READABLE,
    8686            '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' ),
    8792        ) );
    8893
     
    397402        return json_decode( mobile_builder_request( 'GET', $url ) );
    398403    }
     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    }
    399486}
  • mobile-builder/trunk/helpers/mobile-builder-functions.php

    r2304807 r2322821  
    5757 * @return mixed
    5858 */
    59 function mobile_builder_distance_matrix($origin_string, $destinations_string, $key, $units = 'metric') {
     59function mobile_builder_distance_matrix( $origin_string, $destinations_string, $key, $units = 'metric' ) {
    6060    $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
    6263    return json_decode( mobile_builder_request( 'GET', $url ) )->rows;
    6364}
     65
     66/**
     67 *
     68 * Send Notification
     69 *
     70 * @param $fields
     71 * @param $api_key
     72 *
     73 * @return bool|string
     74 */
     75function 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  
    219219        $this->loader->add_filter( 'posts_clauses', $plugin_api, 'mbd_product_list_by_vendor', 501, 2 );
    220220        $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 );
    221223
    222224    }
  • mobile-builder/trunk/mobile-builder.php

    r2303204 r2322821  
    1111 * Plugin URI:        https://doc-oreo.rnlab.io
    1212 * Description:       The most advanced drag & drop app builder. Create multi templates and app controls.
    13  * Version:           1.0.0
     13 * Version:           1.0.1
    1414 * Author:            Rnlab.io
    1515 * Author URI:        https://rnlab.io
Note: See TracChangeset for help on using the changeset viewer.