Plugin Directory

Changeset 3372272


Ignore:
Timestamp:
10/03/2025 10:04:40 AM (6 months ago)
Author:
inspireui
Message:

version 4.18.2

Location:
mstore-api
Files:
498 added
12 edited

Legend:

Unmodified
Added
Removed
  • mstore-api/trunk/controllers/flutter-checkout.php

    r3338834 r3372272  
    6262    }
    6363
    64     private function array_omit(array $source, array $fields): array {
    65         $result = array_map(function($item) use ($fields) {
     64    private function array_omit(string $field_type, array $source, array $fields): array {
     65        $keys = array_keys($source);
     66        $result = array_map(function($key) use ($fields, $source, $field_type) {
     67            $item = $source[$key];
     68            if(!isset($item['key'])){
     69                if(strpos($key, $field_type . '_') === false){
     70                    $item['key'] = $field_type . '_' . $key;
     71                }else{
     72                    $item['key'] = $key;
     73                }
     74            }
     75            if(!isset($item['name'])){
     76                $item['name'] = str_replace($field_type . '_', '', $key);
     77            }
    6678            return array_diff_key($item, array_flip($fields));
    67         }, $source);
     79        }, $keys);
    6880        return $result;
    6981    }
     
    7890
    7991        return  [
    80             'billing' => $this->array_omit(array_values($billing_fields), $omit_fields),
    81             'shipping' => $this->array_omit(array_values($shipping_fields), $omit_fields),
    82             'additional' => $this->array_omit(array_values($additional_fields), $omit_fields),
     92            'billing' => $this->array_omit('billing', $billing_fields, $omit_fields),
     93            'shipping' => $this->array_omit('shipping',$shipping_fields, $omit_fields),
     94            'additional' => $this->array_omit('additional',$additional_fields, $omit_fields),
    8395        ];
    8496    }
     
    139151
    140152            return [
    141                 'billing' => $billing_data,
    142                 'shipping' => $shipping_data,
    143                 'additional' => $additional_data
     153                'billing' => empty($billing_data) ? (object)[] : $billing_data,
     154                'shipping' => empty($shipping_data) ? (object)[] : $shipping_data,
     155                'additional' => empty($additional_data) ? (object)[] : $additional_data
    144156            ];
    145157        } else {
  • mstore-api/trunk/controllers/flutter-home.php

    r3264257 r3372272  
    273273        } else if ($include != null && is_string($include)) {
    274274            $params['include'] = explode(',', $include);
     275        } else if ($include != null && is_array($include)) {
     276            $params['include'] = $include;
    275277        }
    276278        $limit = get_option("mstore_limit_product");
  • mstore-api/trunk/controllers/flutter-order.php

    r3246917 r3372272  
    205205        // Same process from the function WC_AJAX()->update_order_review in the
    206206        // file wp-content/plugins/woocommerce/includes/class-wc-ajax.php
     207        // Or WC_Checkout()->process_customer in the file
     208        // wp-content/plugins/woocommerce/includes/class-wc-checkout.php
    207209        $billing = isset($params['billing']) ? $params['billing'] : NULL;
    208210        $shipping = isset($params['shipping']) ? $params['shipping'] : $billing;
  • mstore-api/trunk/controllers/flutter-vendor.php

    r3199468 r3372272  
    663663    {
    664664        $data = $response->get_data();
    665         $author_id = get_post_field('post_author', $data['id']);
     665        $product_id = $data['id'];
    666666        if (is_plugin_active('dokan-lite/dokan.php')) {
    667             $store = dokan()->vendor->get($author_id);
    668             $dataStore = $store->to_array();
    669             $dataStore = array_merge($dataStore, apply_filters('dokan_rest_store_additional_fields', [], $store, $request));
    670             $data['store'] = $dataStore;
     667            $author_id = get_post_field('post_author', $product_id);
     668            if ($author_id) {
     669                $store = dokan()->vendor->get($author_id);
     670                $dataStore = $store->to_array();
     671                $dataStore = array_merge($dataStore, apply_filters('dokan_rest_store_additional_fields', [], $store, $request));
     672                $data['store'] = $dataStore;
     673            }
    671674        }
    672675        if (is_plugin_active('wc-multivendor-marketplace/wc-multivendor-marketplace.php')) {
    673             $helper = new FlutterWCFMHelper();
    674             $data['store'] = $helper->flutter_get_wcfm_stores_by_id($author_id)->get_data();
     676            if (function_exists('wcfm_get_vendor_id_by_post')) {
     677                $vendor_id = wcfm_get_vendor_id_by_post($product_id);
     678                if ($vendor_id) {
     679                    $helper = new FlutterWCFMHelper();
     680                    $data['store'] = $helper->flutter_get_wcfm_stores_by_id($vendor_id)->get_data();
     681                }
     682            }
    675683        }
    676684
  • mstore-api/trunk/controllers/flutter-woo.php

    r3333934 r3372272  
    116116                'methods' => "POST",
    117117                'callback' => array($this, 'get_taxes'),
     118                'permission_callback' => function () {
     119                    return parent::checkApiPermission();
     120                }
     121            ),
     122        ));
     123
     124        register_rest_route($this->namespace, '/fees', array(
     125            array(
     126                'methods' => "POST",
     127                'callback' => array($this, 'get_fees'),
    118128                'permission_callback' => function () {
    119129                    return parent::checkApiPermission();
     
    11651175    }
    11661176
     1177    public function get_fees($request)
     1178    {
     1179        $json = file_get_contents('php://input');
     1180        $body = json_decode($json, TRUE);
     1181
     1182        $check = $this->check_prerequisites($request, $body);
     1183        if (is_wp_error($check)) {
     1184            return $check;
     1185        }
     1186
     1187        // Shipping info
     1188        if (isset($body["shipping"])) {
     1189            $shipping = $body["shipping"];
     1190            WC()->customer->set_shipping_first_name($shipping["first_name"]);
     1191            WC()->customer->set_shipping_last_name($shipping["last_name"]);
     1192            WC()->customer->set_shipping_company($shipping["company"]);
     1193            WC()->customer->set_shipping_address_1($shipping["address_1"]);
     1194            WC()->customer->set_shipping_address_2($shipping["address_2"]);
     1195            WC()->customer->set_shipping_city($shipping["city"]);
     1196            WC()->customer->set_shipping_state($shipping["state"]);
     1197            WC()->customer->set_shipping_postcode($shipping["postcode"]);
     1198            WC()->customer->set_shipping_country($shipping["country"]);
     1199        }
     1200
     1201        // Billing info
     1202        if (isset($body["billing"])) {
     1203            $billing = $body["billing"];
     1204            WC()->customer->set_billing_first_name($billing["first_name"]);
     1205            WC()->customer->set_billing_last_name($billing["last_name"]);
     1206            WC()->customer->set_billing_company($billing["company"]);
     1207            WC()->customer->set_billing_address_1($billing["address_1"]);
     1208            WC()->customer->set_billing_address_2($billing["address_2"]);
     1209            WC()->customer->set_billing_city($billing["city"]);
     1210            WC()->customer->set_billing_state($billing["state"]);
     1211            WC()->customer->set_billing_postcode($billing["postcode"]);
     1212            WC()->customer->set_billing_country($billing["country"]);
     1213            WC()->customer->set_billing_email($billing["email"]);
     1214            WC()->customer->set_billing_phone($billing["phone"]);
     1215        }
     1216
     1217        // Add products
     1218        $error = $this->add_items_to_cart($body['line_items']);
     1219        if (is_string($error)) {
     1220            return parent::sendError("invalid_item", $error, 400);
     1221        }
     1222
     1223        // Apply coupon if exists
     1224        if (isset($body['coupon_lines']) && is_array($body['coupon_lines']) && count($body['coupon_lines']) > 0) {
     1225            WC()->cart->apply_coupon($body['coupon_lines'][0]['code']);
     1226        }
     1227
     1228        // Set shipping method if exists
     1229        if (isset($body["shipping_lines"]) && !empty($body["shipping_lines"])) {
     1230            $shippings = [];
     1231            foreach ($body["shipping_lines"] as $shipping_line) {
     1232                $shippings[] = $shipping_line["method_id"];
     1233            }
     1234            WC()->session->set('chosen_shipping_methods', $shippings);
     1235        }
     1236
     1237        // Calculate totals to apply shipping, taxes, coupons, etc in cart
     1238        // before getting fees data
     1239        WC()->cart->calculate_totals();
     1240
     1241        return array_values(WC()->cart->get_fees());
     1242    }
     1243
    11671244    public function get_points($request)
    11681245    {
  • mstore-api/trunk/controllers/helpers/vendor-admin-dokan-helper.php

    r3333934 r3372272  
    329329    public function flutter_get_orders($request, $user_id)
    330330    {
    331         $api = new WC_REST_Orders_V1_Controller();
     331        $api = new WC_REST_Orders_V2_Controller();
    332332        $page = 1;
    333333        $per_page = 10;
     
    377377                    continue;
    378378                }
    379                 $response = $api->prepare_item_for_response($order, $request);
     379                $response = $api->prepare_object_for_response($order, $request);
    380380                $order = $response->get_data();
    381381                $count = count($order['line_items']);
     
    473473        $week_5_orders = dokan()->order->all($this->add_date_filter($args, 'month'));
    474474        $all_orders = dokan()->order->all($args);
    475      
     475
    476476        $sales_stats['gross_sales']['last_month'] = $this->get_gross_sales_orders($last_month_orders);
    477477        $sales_stats['gross_sales']['month'] = $this->get_gross_sales_orders($month_orders);
  • mstore-api/trunk/controllers/helpers/vendor-admin-wcfm-helper.php

    r3333934 r3372272  
    294294            $sql = $wpdb->prepare($sql, $vendor_id, $limit, $page);
    295295        }
    296        
     296
    297297        $item = $wpdb->get_results($sql);
    298298
     
    308308                }
    309309            }
    310            
    311            
     310
     311
    312312
    313313            $image = wp_get_attachment_image_src($p["image_id"], "full");
     
    427427    {
    428428        $profile_pic = [];
    429         $api = new WC_REST_Orders_V1_Controller();
     429        $api = new WC_REST_Orders_V2_Controller();
    430430        $results = [];
    431431        if (
     
    487487            }
    488488            $sql .= " GROUP BY $table_name.`order_id` ORDER BY $table_name.`order_id` DESC LIMIT %d OFFSET %d";
    489            
     489
    490490            $args = [$user_id];
    491491            if (isset($request["status"])) {
     
    506506                }
    507507
    508                 $response = $api->prepare_item_for_response($order, $request);
     508                $response = $api->prepare_object_for_response($order, $request);
    509509                $order = $response->get_data();
    510510                $count = count($order["line_items"]);
     
    526526                    $commission_data = get_post_meta($product_id, '_wcfmmp_commission', true);
    527527                    if(!empty($commission_data)){
    528                         $order["line_items"][$i]['commission'] = $commission_data; 
     528                        $order["line_items"][$i]['commission'] = $commission_data;
    529529                    }
    530530                    $image = wp_get_attachment_image_src(
     
    19511951        $categories = sanitize_text_field($request['categories']);
    19521952        $productAttributes = sanitize_text_field($request['productAttributes']);
    1953         $variations = sanitize_text_field($request['variations']);     
    1954         $inventory_delta = sanitize_text_field($request['inventory_delta']);     
     1953        $variations = sanitize_text_field($request['variations']);
     1954        $inventory_delta = sanitize_text_field($request['inventory_delta']);
    19551955
    19561956        $count = 1;
     
    23472347        $categories = sanitize_text_field($request['categories']);
    23482348        $productAttributes = sanitize_text_field($request['productAttributes']);
    2349         $variations = sanitize_text_field($request['variations']);     
    2350         $inventory_delta = sanitize_text_field($request['inventory_delta']);     
    2351         $status = sanitize_text_field($request['status']);     
     2349        $variations = sanitize_text_field($request['variations']);
     2350        $inventory_delta = sanitize_text_field($request['inventory_delta']);
     2351        $status = sanitize_text_field($request['status']);
    23522352        $count = 1;
    23532353
     
    23682368        }
    23692369
    2370    
     2370
    23712371
    23722372        if (isset($featured_image)) {
     
    28672867
    28682868            $sql = $wpdb->prepare(
    2869                 "INSERT INTO `{$wpdb->prefix}wcfm_delivery_orders` 
     2869                "INSERT INTO `{$wpdb->prefix}wcfm_delivery_orders`
    28702870                                  ( vendor_id
    28712871                                  , order_id
     
    29252925                $wpdb->query(
    29262926                    $wpdb->prepare(
    2927                         "INSERT INTO `{$wpdb->prefix}wcfm_delivery_orders_meta` 
     2927                        "INSERT INTO `{$wpdb->prefix}wcfm_delivery_orders_meta`
    29282928                                    ( order_delivery_id
    29292929                                    , `key`
     
    29982998
    29992999            // Deivery Boy Notification
    3000          
     3000
    30013001            if (apply_filters("wcfm_is_allow_itemwise_notification", true)) {
    30023002                $wcfm_messages = sprintf(
  • mstore-api/trunk/controllers/helpers/vendor-admin-woo-helper.php

    r3333934 r3372272  
    207207    {
    208208        global $wpdb;
    209         $api = new WC_REST_Orders_V1_Controller();
     209        $api = new WC_REST_Orders_V2_Controller();
    210210        $results = [];
    211211        $page = 1;
     
    236236        }
    237237        $sql .= " GROUP BY $table_name.`ID` ORDER BY $table_name.`ID` DESC LIMIT %d OFFSET %d";
    238  
     238
    239239        $args = array();
    240240        if (isset($request['status'])) {
     
    254254                continue;
    255255            }
    256             $response = $api->prepare_item_for_response($order, $request);
     256            $response = $api->prepare_object_for_response($order, $request);
    257257            $order = $response->get_data();
    258258            $count = count($order['line_items']);
     
    336336        $order = wc_get_order($order_id);
    337337        $order->update_status($order_status, '', true);
    338        
     338
    339339        $note = sanitize_text_field($request['customer_note']);
    340340        if (!empty($note)) {
     
    623623        $user = get_userdata($user_id);
    624624        $isSeller = in_array("editor", $user->roles) || in_array("administrator", $user->roles);
    625        
     625
    626626        $requestStatus = "draft";
    627627        if ($request["status"] != null) {
     
    649649        $categories = sanitize_text_field($request['categories']);
    650650        $productAttributes = sanitize_text_field($request['productAttributes']);
    651         $variations = sanitize_text_field($request['variations']);     
    652         $inventory_delta = sanitize_text_field($request['inventory_delta']);     
     651        $variations = sanitize_text_field($request['variations']);
     652        $inventory_delta = sanitize_text_field($request['inventory_delta']);
    653653
    654654        $count = 1;
     
    10221022        $categories = sanitize_text_field($request['categories']);
    10231023        $productAttributes = sanitize_text_field($request['productAttributes']);
    1024         $variations = sanitize_text_field($request['variations']);     
    1025         $inventory_delta = sanitize_text_field($request['inventory_delta']);     
    1026         $status = sanitize_text_field($request['status']);     
     1024        $variations = sanitize_text_field($request['variations']);
     1025        $inventory_delta = sanitize_text_field($request['inventory_delta']);
     1026        $status = sanitize_text_field($request['status']);
    10271027        $count = 1;
    10281028
  • mstore-api/trunk/controllers/listing-rest-api/class.api.fields.php

    r3333934 r3372272  
    349349                $this,
    350350                'get_cost_for_booking'
     351            ) ,
     352            'schema' => null,
     353        ));
     354
     355        register_rest_field($this->_customPostType, 'pure_taxonomies', array(
     356            'get_callback' => array(
     357                $this,
     358                'get_pure_taxonomies'
    351359            ) ,
    352360            'schema' => null,
     
    20832091            }
    20842092
    2085             $data['pure_taxonomies'] = $this->get_pure_taxonomies();
    20862093            $data['listing_data'] = $this->get_post_meta_for_api($data);
    20872094            if (!empty($schema['properties']['slug']))
     
    23292336        }
    23302337
    2331         public function get_pure_taxonomies()
    2332         {
    2333             $return = array();
    2334             // Get categories
    2335             $post_categories = wp_get_post_categories($object['id']);
    2336             foreach ($post_categories as $category)
    2337             {
    2338                 $return['categories'][] = get_category($category);
    2339             }
    2340             // Get tags
    2341             $post_tags = wp_get_post_tags($object['id']);
    2342             if (!empty($post_tags))
    2343             {
    2344                 $return['tags'] = $post_tags;
    2345             }
    2346             // Get taxonomies
    2347             $args = array(
    2348                 'public' => true,
    2349                 '_builtin' => false
    2350             );
    2351             $output = 'names'; // or objects
    2352             $operator = 'and'; // 'and' or 'or'
    2353             $taxonomies = get_taxonomies($args, $output, $operator);
    2354             foreach ($taxonomies as $key => $taxonomy_name)
    2355             {
    2356                 $post_taxonomies = get_the_terms($object['id'], $taxonomy_name);
    2357                 if (is_array($post_taxonomies))
    2358                 {
    2359                     foreach ($post_taxonomies as $key2 => $post_taxonomy)
    2360                     {
    2361                         $return[$taxonomy_name][] = get_term($post_taxonomy, $taxonomy_name);
    2362                     }
    2363                 }
    2364             }
    2365             return $return;
     2338        public function get_pure_taxonomies($object)
     2339        {
     2340            if (empty($object['id'])) {
     2341                return [];
     2342            }
     2343
     2344            $post_id = $object['id'];
     2345
     2346            if ($this->_isListeo) {
     2347                $taxonomies = ['listing_category', 'region', 'listing_feature'];
     2348            } elseif ($this->_isListingPro) {
     2349                $taxonomies = ['listing-category', 'location', 'list-tags'];
     2350            } elseif ($this->_isMyListing) {
     2351                $taxonomies = ['job_listing_category', 'region', 'case27_job_listing_tags'];
     2352            } else {
     2353                $taxonomies = ['listing_category', 'region', 'listing_feature'];
     2354            }
     2355
     2356            $result = [];
     2357
     2358            foreach ($taxonomies as $taxonomy) {
     2359                $terms = get_the_terms($post_id, $taxonomy);
     2360                $result[$taxonomy] = is_array($terms)
     2361                    ? array_map(function ($term) {
     2362                        return [
     2363                            'term_id'            => $term->term_id,
     2364                            'name'               => $term->name,
     2365                            'slug'               => $term->slug,
     2366                            'term_group'         => $term->term_group,
     2367                            'term_taxonomy_id'   => $term->term_taxonomy_id,
     2368                            'taxonomy'           => $term->taxonomy,
     2369                            'description'        => $term->description,
     2370                            'parent'             => $term->parent,
     2371                            'count'              => $term->count,
     2372                            'filter'             => 'raw',
     2373                        ];
     2374                    }, $terms)
     2375                    : [];
     2376            }
     2377
     2378            return $result;
    23662379        }
    23672380
  • mstore-api/trunk/functions/index.php

    r3333934 r3372272  
    568568                $check = $attr->is_taxonomy();
    569569                $is_image_type = false;
     570                $is_color_type = false;
    570571                if ($check) {
    571572                    $taxonomy = $attr->get_taxonomy_object();
    572573                    $label = $taxonomy->attribute_label;
    573574                    $is_image_type = $taxonomy->attribute_type == 'image';
     575                    $is_color_type = $taxonomy->attribute_type == 'color';
    574576                } else {
    575577                    $label = $attr->get_name();
     
    596598                }
    597599
    598                 $attributesData[] = array_merge($attr->get_data(), ["attribute_key" => $key, "label" => $label, "name" => urldecode($key), 'is_image_type' => $is_image_type], ['options' =>$attrOptions]);
     600                $is_color_type = $is_color_type == true && class_exists( 'Woo_Variation_Swatches_Frontend' );
     601                if ($is_color_type) {
     602                     $attrOptions = array_map(function ($item){
     603                        $term = $item->to_array();
     604                        $color_value = woo_variation_swatches()->get_frontend()->get_product_attribute_color( $item );
     605                        if ($color_value) {
     606                            $term['primary_color'] = $color_value;
     607                        }
     608                        return $term;
     609                    },$attrOptions);
     610                }
     611
     612                $attributesData[] = array_merge($attr->get_data(), ["attribute_key" => $key, "label" => $label, "name" => urldecode($key), "slug" => $key, 'is_image_type' => $is_image_type, 'is_color_type' => $is_color_type], ['options' =>$attrOptions]);
    599613            }
    600614        }
     
    872886        }
    873887    }
    874    
     888
    875889    $blackListKeys = ['yoast_head','yoast_head_json','_links'];
    876890    $response->data = array_diff_key($response->data,array_flip($blackListKeys));
     
    10621076        }
    10631077    }else if (is_plugin_active('wc-multivendor-marketplace/wc-multivendor-marketplace.php')) {
    1064         if (function_exists('wcfm_get_vendor_store_by_post')) {
     1078        if (function_exists('wcfm_get_vendor_id_by_post')) {
    10651079            $order = wc_get_order($order_id);
    10661080            if (is_a($order, 'WC_Order')) {
  • mstore-api/trunk/mstore-api.php

    r3338834 r3372272  
    44 * Plugin URI: https://github.com/inspireui/mstore-api
    55 * Description: The MStore API Plugin which is used for the FluxBuilder and FluxStore Mobile App
    6  * Version: 4.18.1
     6 * Version: 4.18.2
    77 * Author: FluxBuilder
    88 * Author URI: https://fluxbuilder.com
     
    5757include_once plugin_dir_path(__FILE__) . "controllers/flutter-discount-rules.php";
    5858include_once plugin_dir_path(__FILE__) . "controllers/flutter-checkout.php";
     59include_once plugin_dir_path(__FILE__) . "controllers/flutter-razorpay.php";
    5960
    6061if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
     
    6465class MstoreCheckOut
    6566{
    66     public $version = '4.18.1';
     67    public $version = '4.18.2';
    6768
    6869    public function __construct()
     
    989990            WC()->cart->empty_cart();
    990991
     992            if(class_exists('WC_Points_Rewards_Discount')){
     993                foreach ($data['fee_lines'] as $fee) {
     994                   if($fee['name'] == 'Cart Discount'){
     995                        list($points, $monetary_value) = explode(':', get_option('wc_points_rewards_redeem_points_ratio', ''));
     996                        $cart_price_rate = floatval($monetary_value);
     997                        $cart_points_rate = intval($points);
     998
     999                        WC()->session->set( 'wc_points_rewards_discount_amount', intval($fee['total']) * $cart_points_rate / $cart_price_rate * (-1) );
     1000                        // generate and set unique discount code
     1001                        $discount_code = WC_Points_Rewards_Discount::generate_discount_code();
     1002                        // apply the discount
     1003                        WC()->cart->add_discount( $discount_code );
     1004                   }
     1005                }
     1006            }
     1007           
    9911008            $products = $data['line_items'];
    9921009
  • mstore-api/trunk/readme.txt

    r3338834 r3372272  
    44Requires at least: 4.4
    55Tested up to:      6.8.1
    6 Stable tag:        4.18.1
     6Stable tag:        4.18.2
    77License:           GPL-2.0
    88License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51= 4.18.2 =
     52  * fix: wrong store data as product return author if not has store
     53  * feat: add get_fees api for woocommerce
     54  * Support Razorpay api payment
     55  * Fix to apply points for webview checkout
     56  * Update flutter_get_orders to use Orders V2 Controller
     57  * fix(Home): not load include products params
     58  *  Add primary_color & slug fields to product attributes
     59
    5160= 4.18.1 =
    5261  * Support checkout fields manager
Note: See TracChangeset for help on using the changeset viewer.