Plugin Directory

Changeset 3345551


Ignore:
Timestamp:
08/16/2025 12:27:21 PM (8 months ago)
Author:
buildecomteam
Message:

latest release

Location:
buildecom/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • buildecom/trunk/api.php

    r3316130 r3345551  
    5353function buildecom_api_routes()
    5454{
     55    init_buildecom_api();
     56   
    5557    /*** ROUTES WHERE AUTH CHECK IS NOT MANDATORY */
    5658    register_rest_route(BUILDECOM_API_V1, 'get-settings', [
     
    211213    ]);
    212214}
     215
     216
     217/** modify routes */
     218function init_buildecom_api() {
     219    add_filter('buildecom_rest_prepare_product_object', 'buildecom_custom_change_product_response', 20, 3);
     220    add_filter('buildecom_rest_prepare_product_cat', 'buildecom_custom_product_category', 20, 3);
     221    add_filter('buildecom_rest_product_cat_collection_params', 'buildecom_customize_rest_api_params', 10, 1);
     222    add_filter('buildecom_rest_prepare_shop_order_object', 'custom_add_order_status_color', 10, 3);
     223}
     224
     225function buildecom_custom_change_product_response($response, $object, $request)
     226{
     227    // Will load the product variations if this request is for a specific product
     228    // product by ID
     229    $is_detail_api = isset($request->get_params()['id']);
     230
     231    // The `is_all_data` can be String, Boolean or null. So it can be wrong if
     232    // check 'false' == true
     233    if (filter_var($request['is_all_data'], FILTER_VALIDATE_BOOLEAN)) {
     234        $is_detail_api = true;
     235    }
     236
     237    $product = wc_get_product($response->data['id']);
     238
     239    /* Update price for product variant */
     240    if ($product && $product->is_type('variable')) {
     241        $prices = $product->get_variation_prices();
     242        if (!empty($prices['price'])) {
     243            $response->data['price'] = current($prices['price']);
     244            $response->data['regular_price'] = current($prices['regular_price']);
     245            $response->data['sale_price'] = current($prices['sale_price']);
     246            $response->data['min_price'] = wc_get_price_to_display(  $product, array( 'price' => $product->get_variation_price() ) );
     247            $response->data['max_price'] = wc_get_price_to_display(  $product, array( 'price' => $product->get_variation_price('max') ) );
     248           
     249            if(!$response->data['min_price']){
     250                $response->data['min_price'] = '0';
     251            }
     252            if(!$response->data['max_price']){
     253                $response->data['max_price'] = '0';
     254            }
     255            //convert to string
     256            $response->data['min_price'] = strval($response->data['min_price']);
     257            $response->data['max_price'] = strval($response->data['max_price']);
     258
     259            if($is_detail_api){
     260                $variations = $response->data['variations'];
     261                $controller = new \WC_REST_Product_Variations_V2_Controller();
     262                $variation_arr = array();
     263                foreach($variations as $variation_id){
     264                    $variation = new \WC_Product_Variation($variation_id);
     265                    $variation_data = $controller->prepare_object_for_response($variation, $request)->get_data();
     266                    $variation_arr[] = $variation_data;
     267                }
     268                $response->data['variation_lists'] = $variation_arr;
     269            }
     270           
     271        }
     272    }
     273
     274    if($product) {
     275        $attributes = $product->get_attributes();
     276        $attributesData = [];
     277        foreach ($attributes as $key => $attr) {
     278            if(!is_string($attr)){
     279                $check = $attr->is_taxonomy();
     280                if ($check) {
     281                    $taxonomy = $attr->get_taxonomy_object();
     282                    $label = $taxonomy->attribute_label;
     283                } else {
     284                    $label = $attr->get_name();
     285                }
     286                $attrOptions = wc_get_product_terms($response->data['id'], $attr["name"]);
     287                $attrOptions = empty($attrOptions) ? array_map(function ($v){
     288                    return ['name'=>$v, 'slug' => $v];
     289                },$attr["options"]) : $attrOptions;
     290                $attributesData[] = array_merge($attr->get_data(), ["label" => $label, "name" => urldecode($key)], ['options' =>$attrOptions]);
     291            }
     292        }
     293        $response->data['attributes_lists'] = $attributesData;
     294    }
     295
     296    return $response;
     297
     298}
     299
     300function buildecom_custom_product_category($response, $object, $request) {
     301    $id = $response->data['id'];
     302    $children = get_term_children($id, 'product_cat');
     303
     304    if (empty($children)) {
     305        $response->data['has_children_category'] = false;
     306        $response->data['child_categories'] = array();
     307    } else {
     308        $response->data['has_children_category'] = true;
     309        $response->data['child_categories'] = get_child_categories_recursive($children);
     310    }
     311
     312    return $response;
     313}
     314
     315function get_child_categories_recursive($children) {
     316    $child_categories = array();
     317
     318    foreach ($children as $child_id) {
     319        $child_term = get_term($child_id, 'product_cat');
     320        if (!is_wp_error($child_term)) {
     321            $child_term_data = array(
     322                'id' => $child_term->term_id,
     323                'name' => $child_term->name,
     324                'slug' => $child_term->slug,
     325                'description' => $child_term->description,
     326                'count' => $child_term->count,
     327                'parent' => $child_term->parent,
     328                'child_categories' => array()
     329            );
     330
     331            $grandchildren = get_term_children($child_id, 'product_cat');
     332            if (!empty($grandchildren)) {
     333                $child_term_data['child_categories'] = get_child_categories_recursive($grandchildren);
     334            }
     335
     336            $child_categories[] = $child_term_data;
     337        }
     338    }
     339
     340    return $child_categories;
     341}
     342
     343function buildecom_customize_rest_api_params($params) {
     344    $params['per_page']['maximum'] = 500; // Increase the maximum limit to 500
     345    return $params;
     346}
     347
     348function custom_add_order_status_color($response, $object, $request) {
     349    global $wpdb;
     350
     351    $order_id = $object->get_id();
     352    $order    = wc_get_order($order_id);
     353
     354    // Fetch rows directly from your custom table
     355    $statuses = $wpdb->get_results(
     356        "SELECT * FROM {$wpdb->prefix}buildecom_order_statuses WHERE status = 1 ORDER BY id DESC"
     357    );
     358
     359    $custom_status_colors = array(
     360        'pending'         => '#ffcc00',
     361        'pending-payment' => '#ffcc00',
     362        'processing'      => '#fadd85',
     363        'completed'       => '#0000ff',
     364        'on-hold'         => '#ff6600',
     365        'cancelled'       => '#cc0000',
     366        'refunded'        => '#009999',
     367        'failed'          => '#990000',
     368        'draft'           => '#000000',
     369    );
     370
     371    foreach ($statuses as $status) {
     372        $slug = buildecom_make_slug($status->status_label);
     373        $custom_status_colors[$slug] = $status->status_color;
     374    }
     375
     376    $status = $order->get_status();
     377
     378    if (isset($custom_status_colors[$status])) {
     379        $status_color = $custom_status_colors[$status];
     380    }
     381
     382    $response->data['status_color'] = $status_color;
     383
     384    return $response;
     385}
  • buildecom/trunk/buildecom.php

    r3344671 r3345551  
    77 * Plugin URI: https://buildecom.app/wp-plugin/
    88 * Description: The official WordPress plugin for BuildEcom. Build eCommerce mobile application through woocommerce and wordpress
    9  * Version: 1.0.11
     9 * Version: 1.0.12
    1010 * Author: BuildEcom
    1111 * Author URI: https://buildecom.app
     
    539539});
    540540
     541add_filter('wc_order_statuses', function ($order_statuses) {
     542    global $wpdb;
     543
     544    $custom_statuses = $wpdb->get_results(
     545        "SELECT status_slug, status_label
     546        FROM {$wpdb->prefix}buildecom_order_statuses
     547        WHERE status = 1"
     548    );
     549
     550    if ($custom_statuses) {
     551        foreach ($custom_statuses as $status) {
     552            $order_statuses[$status->status_slug] = $status->status_label;
     553        }
     554    }
     555
     556    return $order_statuses;
     557});
     558
    541559Buildecom::get_instance();
  • buildecom/trunk/inc/api/class-api-auth.php

    r3344671 r3345551  
    114114
    115115        // this option is excluded from admin setting
    116         $isEnableEmailVerification = true;
     116        $isEnableEmailVerification = false;
    117117
    118118        if (!$isEnableEmailVerification) {
  • buildecom/trunk/inc/helpers.php

    r3344313 r3345551  
    445445    }
    446446}
     447
     448if(!function_exists('buildecom_make_slug')){
     449    function buildecom_make_slug($str){
     450        $str = strtolower($str);
     451
     452        $str = str_replace(' ', '-', $str);
     453
     454        $str = preg_replace('/[^a-z0-9-]/', '', $str);
     455
     456        $str = preg_replace('/-+/', '-', $str);
     457
     458        $str = trim($str, '-');
     459
     460        return $str;
     461    }
     462}
  • buildecom/trunk/readme.txt

    r3344671 r3345551  
    44Requires at least: 4.7
    55Tested up to: 6.8
    6 Stable tag: 1.0.11
     6Stable tag: 1.0.12
    77License: GPL-2.0+
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.