Plugin Directory

Changeset 3086463


Ignore:
Timestamp:
05/14/2024 11:09:58 AM (23 months ago)
Author:
inspireui
Message:

+ update new version 14.4

Location:
mstore-api/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • mstore-api/trunk/composer.json

    r3076227 r3086463  
    44  "authors": [
    55    {
    6       "name": "InspireUI",
    7       "email": "hi@inspireui.com"
     6      "name": "FluxBuilder",
     7      "email": "hi@fluxbuilder.com"
    88    }
    99  ],
  • mstore-api/trunk/controllers/flutter-woo.php

    r3080638 r3086463  
    255255                'methods' => "GET",
    256256                'callback' => array($this, 'get_min_max_prices'),
     257                'permission_callback' => function () {
     258                    return parent::checkApiPermission();
     259                }
     260            ),
     261        ));
     262
     263        register_rest_route($this->namespace, '/products/size-guide' . '/(?P<id>[\d]+)', array(
     264            'args' => array(
     265                'id' => array(
     266                    'description' => __('Unique identifier for the resource.', 'woocommerce'),
     267                    'type' => 'integer',
     268                ),
     269            ),
     270            array(
     271                'methods' => "GET",
     272                'callback' => array($this, 'size_guide'),
    257273                'permission_callback' => function () {
    258274                    return parent::checkApiPermission();
     
    14041420        }
    14051421    }
     1422
     1423    function size_guide($request)
     1424    {
     1425        $params = $request->get_url_params();
     1426        $product_id = sanitize_text_field($params['id']);
     1427
     1428        if (function_exists('woodmart_sguide_display')) {
     1429            // Support WoodMart - Multipurpose WooCommerce Theme
     1430            ob_start();
     1431
     1432            // We can clone and customize this function if needed instead of
     1433            // using `ob_get_contents`
     1434            woodmart_sguide_display($product_id);
     1435
     1436            $result = ob_get_contents();
     1437            ob_end_clean();
     1438        } else if (class_exists('PSCW_PRODUCT_SIZE_CHART_F_WOO_Front_end')) {
     1439            // Support Product Size Chart For WooCommerce Plugin:
     1440            // https://wordpress.org/plugins/product-size-chart-for-woo/
     1441            $result = $this->custom_product_tabs_content($product_id);
     1442        }
     1443
     1444        if (!isset($result) || empty($result)) {
     1445            return parent::sendError("invalid_data", "Not found", 400);
     1446        } else {
     1447            return array(
     1448                'data' => $result
     1449            );
     1450        }
     1451    }
     1452
     1453    /// Clone from function `custom_product_tabs_content` of `PSCW_PRODUCT_SIZE_CHART_F_WOO_Front_end`
     1454    private function custom_product_tabs_content($post_id)
     1455    {
     1456        $html = '';
     1457
     1458        // Initialize controller manually
     1459        $controller = new PSCW_PRODUCT_SIZE_CHART_F_WOO_Front_end();
     1460        $controller->option        = get_option('woo_sc_setting');
     1461        $controller->option['position'] = 'product_tabs';
     1462
     1463        $product_id           = $post_id;
     1464        $sizechart_id         = $controller->woo_sc_function->get_posts_id();
     1465        $sizechart_posts_data = [];
     1466        if (!empty($sizechart_id) && is_array($sizechart_id)) {
     1467            //rsort array size chart post id by DESC
     1468            rsort($sizechart_id);
     1469            foreach ($sizechart_id as $sizechart_post_id) {
     1470                $sizechart_posts_data[$sizechart_post_id] = get_post_meta($sizechart_post_id, 'woo_sc_size_chart_data', true);
     1471            }
     1472            foreach ($sizechart_posts_data as $sc_id => $val) {
     1473
     1474                $assign_product               = !empty($val['search_product']) ? $val['search_product'] : [];
     1475                $assign_cate                  = !empty($val['categories']) ? $val['categories'] : [];
     1476                $all_pro_id_in_assign_cate    = $controller->woo_sc_function->get_products_in_cate($assign_cate);
     1477                $all_product_ids_in_sizechart = array_merge($all_pro_id_in_assign_cate, $assign_product);
     1478                if (!empty($all_product_ids_in_sizechart) && is_array($all_product_ids_in_sizechart)) {
     1479                    $unique_product_id = array_unique($all_product_ids_in_sizechart);
     1480                }
     1481                if (!empty($unique_product_id) && is_array($unique_product_id)) {
     1482                    if (in_array($product_id, $unique_product_id)) {
     1483                        $get_meta_box_data = $controller->get_meta_box_data($sc_id);
     1484                        if (isset($get_meta_box_data['hide']) && $get_meta_box_data['hide'] !== 'hide_all') {
     1485                            $html .=  wp_kses_post($controller->woo_sc_function->content_data($sc_id));
     1486                        }
     1487                        if ($controller->option['multi_sc'] == "0") {
     1488                            break;
     1489                        }
     1490                    }
     1491                }
     1492            }
     1493        }
     1494        return $html;
     1495    }
    14061496}
    14071497
  • mstore-api/trunk/functions/index.php

    r3076227 r3086463  
    562562
    563563/// Clone from wp-content/plugins/woocommerce-brands/includes/widgets/class-wc-widget-brand-nav.php
    564 function get_filtered_term_product_counts($request, $taxonomy, $term_ids = [])
     564function get_filtered_term_product_counts($request, $taxonomy, $term_ids = [], $hide_empty = true)
    565565{
    566566    global $wpdb;
     
    569569        $term_ids = wp_list_pluck(get_terms(array(
    570570            'taxonomy'   => $taxonomy,
    571             'hide_empty' => true,
     571            'hide_empty' => $hide_empty,
    572572        )), 'term_id');
    573573    }
     
    628628    $query             = implode(' ', $query);
    629629
    630     return $wpdb->get_results($query, ARRAY_A);
     630    $term_counts = $wpdb->get_results($query, ARRAY_A);
     631
     632    $exist_terms_ids = array_column($term_counts, 'term_count_id');
     633
     634    // In some cases, the `term_counts` result may be missing some terms contained in `$term_ids`.
     635    $missing_term_ids = array_diff($term_ids, $exist_terms_ids);
     636
     637    // Add missing terms to result with term_count = 0
     638    $result = $term_counts;
     639    foreach ($missing_term_ids as $id) {
     640        $result[] = [
     641            'term_count' => 0,
     642            'term_count_id' => $id
     643        ];
     644    }
     645
     646    return $result;
    631647}
    632648
  • mstore-api/trunk/mstore-api.php

    r3086373 r3086463  
    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.13.7
     6 * Version: 4.14.0
    77 * Author: FluxBuilder
    8  * Author URI: https://www.fluxbuilder.com
     8 * Author URI: https://fluxbuilder.com
    99 *
    1010 * Text Domain: MStore-Api
     
    474474add_filter('woocommerce_rest_prepare_product_brand', 'flutter_custom_change_product_taxonomy', 20, 3);
    475475add_filter('woocommerce_rest_product_object_query', 'flutter_custom_rest_product_object_query', 10, 2);
     476add_filter('woocommerce_rest_product_tag_query', 'flutter_custom_rest_product_tag_query', 10, 2);
     477add_filter('woocommerce_rest_product_brand_query', 'flutter_custom_rest_product_brand_query', 10, 2);
     478
     479function flutter_custom_rest_product_tag_query($args, $request)
     480{
     481    return flutter_custom_rest_product_taxomomy_query($args, $request, 'product_tag');
     482}
     483
     484function flutter_custom_rest_product_brand_query($args, $request)
     485{
     486    return flutter_custom_rest_product_taxomomy_query($args, $request, 'product_brand');
     487}
     488
     489function flutter_custom_rest_product_taxomomy_query($args, $request, $taxonomy)
     490{
     491    $hide_empty = isset($args['hide_empty']) && $args['hide_empty'] == true;
     492
     493    // `include` parameter can be an array or comma separated string
     494    $include = wp_parse_id_list($args['include']);
     495
     496    // Get product count for all tags, brands related to the requested params (based on category, brand, etc.)
     497    $terms = get_filtered_term_product_counts($request, $taxonomy, [], $hide_empty);
     498
     499    // Trick: Use the `include` parameter to fix the API problem below
     500    // The page = 1 has no visible items (count = 0), the app does not show
     501    // anything (include loadmore button). If the page = 2 has visible items,
     502    // cannot do anything in app because it do not show load more button
     503    foreach ($terms as $key => $term) {
     504        if ($hide_empty) {
     505            if ($term['term_count'] > 0) {
     506                $include[] = $term['term_count_id'];
     507            }
     508        } else {
     509            $include[] = $term['term_count_id'];
     510        }
     511    }
     512
     513    $args['include'] = implode(',', wp_parse_id_list($include));
     514    return $args;
     515}
    476516
    477517function flutter_custom_rest_product_object_query($args, $request)
  • mstore-api/trunk/readme.txt

    r3086436 r3086463  
    44Requires at least: 4.4
    55Tested up to:      6.5.3
    6 Stable tag:        4.13.7
     6Stable tag:        4.14.0
    77License:           GPL-2.0
    88License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51= 4.14.0 =
     52  * Upgrade Filter function
     53  * Add size guide feature
     54
    5155= 4.13.7 =
    5256  * Update plugin description
Note: See TracChangeset for help on using the changeset viewer.