Plugin Directory

Changeset 3370271


Ignore:
Timestamp:
09/30/2025 09:20:28 AM (6 months ago)
Author:
baselinker
Message:

fixed filtering rules

Location:
baselinker-woo/tags/1.0.27
Files:
2 added
4 copied

Legend:

Unmodified
Added
Removed
  • baselinker-woo/tags/1.0.27/baselinker.php

    r3307067 r3370271  
    22/**
    33 * @package BaseLinker
    4  * @version 1.0.26
     4 * @version 1.0.27
    55 */
    66/*
     
    1111Domain Path: /languages
    1212Author: BaseLinker
    13 Version: 1.0.26
     13Version: 1.0.27
    1414Author URI: http://baselinker.com/
    1515License: GPLv3 or later
     
    2323function baselinker_version($data)
    2424{
    25     return '1.0.26';
     25    return '1.0.27';
    2626}
    2727
     
    7575    $shipments = get_children($q);
    7676
    77     if (count($shipments))
     77    if (!empty($shipments))
    7878    {
    7979        $shipment = array_shift($shipments);
     
    125125function baselinker_query_by_order_number($args, $request)
    126126{
    127     if (isset($request['order_number']) and (intval($request['order_number']) or $request['order_number'] == '%'))
     127    if (isset($request['order_number']) and (!empty(intval($request['order_number'])) or $request['order_number'] == '%'))
    128128    {
    129129        $args['meta_key'] = isset($request['order_number_meta']) ? $request['order_number_meta'] : '_order_number';
     
    196196    {
    197197        $cutoff_limit = (int)$data['limit'];
     198
     199        if ($cutoff_limit < $args['limit'])
     200        {
     201            $args['limit'] = $cutoff_limit;
     202        }
     203    }
     204
     205    if (!empty($data['cutoff']))
     206    {
     207        $cutoff_limit = (int)$data['cutoff'];
     208    }
     209
     210    if (isset($data['order']) and preg_match('/^(asc|desc)$/i', $data['order']))
     211    {
     212        $args['order'] = strtoupper($data['order']);
     213    }
     214
     215    if (isset($data['orderby']) and preg_match('/^(ID|name|none|date|modified)$/', $data['orderby']))
     216    {
     217        $args['orderby'] = $data['orderby'];
     218    }
     219    else
     220    {
     221        $args['orderby'] = 'ID';
     222        $args['order'] = 'desc';
    198223    }
    199224
    200225    if (isset($data['offset']))
    201226    {
    202         $page = ceil(($data['offset']+1)/100);
     227        $page = ceil(((int)$data['offset']+1)/$args['limit']);
    203228        unset($data['offset']);
    204229    }
    205230
    206     if (isset($data['lang']))
     231    if (isset($data['lang']) and preg_match('/^\w+/', $data['lang']))
    207232    {
    208233        $args['lang'] = $data['lang'];
    209234    }
    210235
    211     if (isset($data['exclude']))
    212     {
    213         $args['exclude'] = $data['exclude'];
    214     }
    215 
    216     if (isset($data['include']))
    217     {
    218         $args['include'] = $data['include'];
    219     }
    220 
    221     if (isset($data['type']))
     236    if (isset($data['exclude']) and preg_match('/^\d[\d,]*$/', $data['exclude']))
     237    {
     238        $args['exclude'] = explode(',', $data['exclude']);
     239    }
     240
     241    if (isset($data['include']) and preg_match('/^\d[\d,]*$/', $data['include']))
     242    {
     243        $args['include'] = explode(',', $data['include']);
     244    }
     245
     246    if (isset($data['type']) and in_array($data['type'], ['external', 'grouped', 'simple', 'variable']))
    222247    {
    223248        $args['type'] = $data['type'];
     
    226251    if (isset($data['parent']))
    227252    {
    228         $args['parent'] = $data['parent'];
     253        $args['parent'] = (int)$data['parent'];
    229254    }
    230255
    231256    if (isset($data['status']))
    232257    {
    233         $args['status'] = $data['status'];
     258        $args['status'] = preg_replace('/[^\w\s]/', '', $data['status']);
    234259    }
    235260
     
    239264    }
    240265
    241     if (isset($data['category_id']) and (int)$data['category_id'])
     266    if (isset($data['category_id']) and (int)$data['category_id'] > 0)
    242267    {
    243268        foreach (baselinker_category_list($data) as $cat)
     
    249274            }
    250275        }
     276    }
     277
     278    if (!empty($data['min_stock']))
     279    {
     280        $args['min_stock'] = $data['min_stock'];
     281    }
     282
     283    if (!empty($data['max_stock']))
     284    {
     285        $args['max_stock'] = $data['max_stock'];
     286    }
     287
     288    if (!empty($data['min_price']))
     289    {
     290        $args['min_price'] = $data['min_price'];
     291    }
     292
     293    if (!empty($data['max_price']))
     294    {
     295        $args['max_price'] = $data['max_price'];
    251296    }
    252297
     
    263308    do {
    264309        $args['page'] = $page;
    265 
    266310        $res = wc_get_products($args);
    267311
     
    357401                        while ($variations_subset = array_splice($variation_ids, 0, 100))
    358402                        {
    359                             $prod_variations = baselinker_product_list(array('include' => $variations_subset, 'type' => 'variation', 'limit' => 100));
     403                            $prod_variations = baselinker_product_list(array('include' => implode(',', $variations_subset), 'type' => 'variation', 'limit' => $args['limit']));
    360404
    361405                            foreach ($prod_variations as $vid => $v)
     
    445489                $dimensions = array();
    446490
    447                 if ($dim = (int)$variation->get_width())
     491                if (($dim = (int)$variation->get_width()) > 0)
    448492                {
    449493                    $dimensions['width'] = $dim;
    450494                }
    451495
    452                 if ($dim = (int)$variation->get_length())
     496                if (($dim = (int)$variation->get_length()) > 0)
    453497                {
    454498                    $dimensions['length'] = $dim;
    455499                }
    456500
    457                 if ($dim = (int)$variation->get_height())
     501                if (($dim = (int)$variation->get_height()) > 0)
    458502                {
    459503                    $dimensions['height'] = $dim;
     
    539583    }
    540584
    541     // quantity brackets
    542     $min_stock = $request->get_param('min_stock');
    543     $max_stock = $request->get_param('max_stock');
    544 
    545     if (isset($min_stock) or isset($max_stock))
    546     {
    547         $args['post_type'] = array('product', 'product_variation');
    548         $args['meta_query'][] = array(
    549             'key' => '_stock',
    550             'value' => array(isset($min_stock) ? (int)$min_stock : 0, isset($max_stock) ? (int)$max_stock : 99999999),
    551             'compare' => 'BETWEEN',
    552             'type' => 'numeric',
    553         );
    554        
    555     }
    556 
    557585    // categories excluded in baselinker
    558586    if ($cats_exclude = $request->get_param('categories_exclude'))
     
    579607}
    580608
     609function baselinker_custom_query_vars($query, $query_vars)
     610{
     611    // quantity brackets
     612    if (!empty($query_vars['min_stock']) or !empty($query_vars['max_stock']))
     613    {
     614        $min_stock = $query_vars['min_stock'] ?? null;
     615        $max_stock = $query_vars['max_stock'] ?? null;
     616
     617        $query['meta_query'][] = [
     618            'key' => '_stock',
     619            'value' => [isset($min_stock) ? (int)$min_stock : 0, isset($max_stock) ? (int)$max_stock : 99999999],
     620            'compare' => 'BETWEEN',
     621            'type' => 'numeric',
     622        ];
     623    }
     624
     625    // price brackets
     626    if (!empty($query_vars['min_price']) or !empty($query_vars['max_price']))
     627    {
     628        $min_price = $query_vars['min_price'] ?? null;
     629        $max_price = $query_vars['max_price'] ?? null;
     630
     631        $query['meta_query'][] = [
     632            'key' => '_price',
     633            'value' => [isset($min_price) ? (float)$min_price : 0, isset($max_price) ? (float)$max_price : 99999999],
     634            'compare' => 'BETWEEN',
     635            'type' => 'numeric',
     636        ];
     637    }
     638
     639    return $query;
     640}
     641
    581642
    582643// defining additional REST API endpoints
    583644add_action('rest_api_init', function() {
    584 
    585645    register_rest_route('bl/v2', '/shipping_methods/', array('methods' => 'GET', 'callback' => 'baselinker_shipping_methods', 'permission_callback' => '__return_true'));
    586646    register_rest_route('wc-bl/v2', '/product_list/', array('methods' => 'GET', 'callback' => 'baselinker_product_list', 'permission_callback' => 'baselinker_authenticate'));
     
    592652
    593653add_action('before_woocommerce_init', function() {
    594 
    595654    if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class))
    596655    {
     
    600659
    601660add_action('plugins_loaded', function() {
    602 
    603661    load_plugin_textdomain('baselinker-woo', FALSE, basename(dirname(__FILE__)) . '/languages/');
    604662});
     
    609667add_filter('woocommerce_rest_prepare_product_object', 'baselinker_prepare_product', 20, 3);
    610668add_filter('woocommerce_rest_product_object_query', 'baselinker_product_object_query', 10, 2);
     669add_filter('woocommerce_product_data_store_cpt_get_products_query', 'baselinker_custom_query_vars', 10, 2 );
    611670?>
  • baselinker-woo/tags/1.0.27/readme.txt

    r3306762 r3370271  
    22Plugin Name: Base (formerly BaseLinker) - 300+ marketplaces, 150+ carriers & PIM & OMS & WMS in one
    33Contributors: baselinker
    4 Stable tag: 1.0.26
    5 Tested up to: 6.8.1
     4Stable tag: 1.0.27
     5Tested up to: 6.8.2
    66Requires at least: 4.5.0
    77Requires Plugins: woocommerce
Note: See TracChangeset for help on using the changeset viewer.