Plugin Directory

Changeset 3148999


Ignore:
Timestamp:
09/10/2024 06:09:58 AM (18 months ago)
Author:
bsecuretech
Message:

Updated to version 1.7.9

Location:
bsecure
Files:
59 added
3 edited

Legend:

Unmodified
Added
Removed
  • bsecure/trunk/bsecure.php

    r3016297 r3148999  
    2121 * @since    1.0.0
    2222 */
    23 
    24    
    2523
    2624    function wc_besecure_run() {       
  • bsecure/trunk/includes/class-bsecure-checkout.php

    r3016297 r3148999  
    28352835    }
    28362836
    2837 
     2837    // dubug by sk old code
    28382838    // Hook to the product api response build process and add variations objects.   
    2839     public function custom_product_api_response($response, $post, $request){
    2840 
     2839        // public function custom_product_api_response($response, $post, $request){
     2840
     2841        //  $params = $request->get_params();
     2842        //  // check request is for bsecure portal or not
     2843        //  if(is_wp_error( $response )  || !isset($params['bsecure']) ) {
     2844
     2845        //      return $response;
     2846        //  }
     2847               
     2848        //  WC()->api->includes();
     2849        //  WC()->api->register_resources( new WC_API_Server( '/' ) );
     2850           
     2851        //  $wc_webhook = new WC_Webhook();
     2852        //  $variations_objs = [];
     2853
     2854        //  $productKeys = ["id","name","short_description","slug","tags","sku","price","weight","categories","images","attributes","variations"];
     2855        //  $variationKeys = ["id","title","price","sku","description","image","attributes","manage_stock","stock_quantity"];
     2856        //  $new_response = [];
     2857
     2858        //  // Filter product data as per provided keys
     2859        //  /*foreach($productKeys as $productKey){
     2860        //      // Temprorary Commented from Asim 1.6.1
     2861        //      if(in_array($productKey, $response->data)){
     2862        //          //$new_response[$productKey] = $response->data[$productKey];
     2863        //      }
     2864
     2865        //  }*/
     2866
     2867
     2868
     2869        //     // Store variation data in new variable
     2870        //     if(isset($response->data["type"])){
     2871        //      if ( 'variable' === $response->data["type"] ) {
     2872        //         if(!empty($response->data["variations"])){
     2873        //          foreach( $response->data["variations"] as $variation ) {
     2874                           
     2875        //                  $product_objs = WC()->api->WC_API_Products->get_product( $variation );
     2876        //                  $variations_objs[] = !empty($product_objs['product']) ? $product_objs['product'] : [];
     2877        //              }
     2878        //            }
     2879        //      }
     2880        //  }
     2881
     2882        //     // Filter variation data as per provided keys
     2883        //     if(!empty($variations_objs)){
     2884        //      $new_response["variations"] = [];
     2885        //      foreach($variations_objs as $key => $variations_obj){
     2886
     2887        //          foreach($variationKeys as $variationKey){
     2888
     2889        //                  if(in_array($variationKey, $variations_obj)){
     2890        //                      //$new_response["variations"][$key][$variationKey] = $variations_obj[$variationKey];
     2891        //                  }
     2892        //              }
     2893        //      }
     2894        //     }       
     2895        //     $response->data["variations"] = $variations_objs;
     2896        //     return $response;
     2897        // }
     2898
     2899
     2900    // new code by sk
     2901    public function custom_product_api_response($response, $post, $request) {
    28412902        $params = $request->get_params();
    2842         // check request is for bsecure portal or not
    2843         if(is_wp_error( $response )  || !isset($params['bsecure']) ) {
    2844 
     2903        // Check if request is for bsecure portal or not
     2904        if (is_wp_error($response) || !isset($params['bsecure'])) {
    28452905            return $response;
    28462906        }
    2847            
    2848         WC()->api->includes();
    2849         WC()->api->register_resources( new WC_API_Server( '/' ) );
    2850        
     2907        // Identify WooCommerce version
     2908        $wc_version = WC()->version;
     2909   
     2910        // Check and include relevant API classes based on WooCommerce version
     2911        if (version_compare($wc_version, '3.6.0', '>=')) {
     2912            // WooCommerce 3.6.0+
     2913            include_once WC_ABSPATH . 'includes/api/class-wc-rest-system-status-controller.php';
     2914        } else {
     2915            // WooCommerce pre-3.6.0
     2916            WC()->api->includes();
     2917            WC()->api->register_resources(new WC_API_Server('/'));
     2918        }
     2919   
    28512920        $wc_webhook = new WC_Webhook();
    28522921        $variations_objs = [];
    28532922
    2854         $productKeys = ["id","name","short_description","slug","tags","sku","price","weight","categories","images","attributes","variations"];
    2855         $variationKeys = ["id","title","price","sku","description","image","attributes","manage_stock","stock_quantity"];
     2923        // $productKeys = ["id", "name", "short_description", "slug", "tags", "sku", "price", "weight", "categories", "images", "attributes", "variations"];
     2924        $variationKeys = ["id", "title", "price", "sku", "description", "image", "attributes", "manage_stock", "stock_quantity"];
    28562925        $new_response = [];
    28572926
    28582927        // Filter product data as per provided keys
    2859         /*foreach($productKeys as $productKey){
    2860             // Temprorary Commented from Asim 1.6.1
    2861             if(in_array($productKey, $response->data)){
    2862                 //$new_response[$productKey] = $response->data[$productKey];
    2863             }
    2864 
    2865         }*/
    2866 
    2867 
    2868 
    2869         // Store variation data in new variable
    2870         if(isset($response->data["type"])){
    2871             if ( 'variable' === $response->data["type"] ) {
    2872                if(!empty($response->data["variations"])){
    2873                 foreach( $response->data["variations"] as $variation ) {
    2874                        
    2875                         $product_objs = WC()->api->WC_API_Products->get_product( $variation );
    2876                         $variations_objs[] = !empty($product_objs['product']) ? $product_objs['product'] : [];
    2877                     }
    2878                   }
    2879             }
    2880         }
    2881 
    2882         // Filter variation data as per provided keys
    2883         if(!empty($variations_objs)){
    2884             $new_response["variations"] = [];
    2885             foreach($variations_objs as $key => $variations_obj){
    2886 
    2887                 foreach($variationKeys as $variationKey){
    2888 
    2889                         if(in_array($variationKey, $variations_obj)){
    2890                             //$new_response["variations"][$key][$variationKey] = $variations_obj[$variationKey];
    2891                         }
     2928        // foreach($productKeys as $productKey){
     2929        //  // Temprorary Commented from Asim 1.6.1
     2930        //  if(in_array($productKey, $response->data)){
     2931        //      //$new_response[$productKey] = $response->data[$productKey];
     2932        //  }
     2933
     2934        // }
     2935
     2936        // Store variation data in new variable
     2937        if (isset($response->data["type"]) && 'variable' === $response->data["type"]) {
     2938            // write_log('Product is of type variable.');
     2939            if (!empty($response->data["variations"])) {
     2940                // write_log('Variations found: ' . print_r($response->data["variations"], true));
     2941                foreach ($response->data["variations"] as $variation) {
     2942                    // Get product variation using wc_get_product
     2943                    $product = wc_get_product($variation);
     2944                    if ($product) {
     2945                        $product_data = $product->get_data();
     2946                        $variations_objs[] = $product_data;
     2947                    } else {
     2948                        // write_log('Failed to get product for variation ID: ' . $variation);
    28922949                    }
    2893             }
    2894         }       
    2895         $response->data["variations"] = $variations_objs;
    2896         return $response;
    2897     }
     2950                }
     2951            } else {
     2952                // write_log('No variations found.');
     2953            }
     2954        } else {
     2955            // write_log('Product is not of type variable or type is not set.');
     2956        }
     2957   
     2958        // Filter variation data as per provided keys
     2959        if (!empty($variations_objs)) {
     2960            $new_response["variations"] = [];
     2961            foreach ($variations_objs as $key => $variations_obj) {
     2962                foreach ($variationKeys as $variationKey) {
     2963                    if (array_key_exists($variationKey, $variations_obj)) {
     2964                        // $new_response["variations"][$key][$variationKey] = $variations_obj[$variationKey];
     2965                    }
     2966                }
     2967            }
     2968        }
     2969   
     2970        $response->data["variations"] = $variations_objs;
     2971   
     2972        // write_log('Final Response Data: ' . print_r($response->data, true));
     2973   
     2974        return $response;
     2975    }
     2976   
     2977
     2978    // new code by sk
    28982979
    28992980    /**
  • bsecure/trunk/readme.txt

    r3016297 r3148999  
    55Tested up to: 6.4
    66Requires PHP: 5.6.20 or above
    7 Stable tag: 1.7.8
     7Stable tag: 1.7.9
    88License: GNU General Public License v3.0
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    182182* 1.7.8 Released with General Update and Bug Fixes
    183183
     184= 1.7.9 September 09, 2024 =
     185* 1.7.9 Released with General Update and Bug Fixes
     186
    184187== Screenshots ==
Note: See TracChangeset for help on using the changeset viewer.