Plugin Directory

Changeset 3211961


Ignore:
Timestamp:
12/23/2024 03:49:55 AM (15 months ago)
Author:
inspireui
Message:

version 4.16.6

Location:
mstore-api
Files:
492 added
6 edited

Legend:

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

    r3166875 r3211961  
    133133    {
    134134        $lang = sanitize_text_field($request["lang"]);
    135         $homeCache  =  FlutterUtils::get_home_cache_path($lang);
    136         if($request["reset"]  == "false" && file_exists($homeCache)){
     135        $reset = isset($request["reset"]) ? sanitize_text_field($request["reset"]) : "true";
     136       
     137        $homeCache = FlutterUtils::get_home_cache_path($lang);
     138       
     139        if($reset !== "true" && file_exists($homeCache) && filesize($homeCache) > 0) {
    137140            $fileContent = file_get_contents($homeCache);
    138             return  json_decode($fileContent, true);
     141            $cachedData = json_decode($fileContent, true);
     142            if (json_last_error() === JSON_ERROR_NONE) {
     143                return $cachedData;
     144            }
    139145        }
    140146
     
    146152        if (file_exists($path)) {
    147153            $fileContent = file_get_contents($path);
    148             $array = json_decode($fileContent, true);
    149 
    150             //get products for horizontal layout
    151             $array['HorizonLayout'] = $this->getProductsForHorizonLayout($array["HorizonLayout"], $api, $request);
    152 
    153             //get products for dynamic layout
    154             $tabBar = $array['TabBar'];
     154
     155            // Decode json data to object
     156            $array = json_decode($fileContent);
     157            if (json_last_error() !== JSON_ERROR_NONE) {
     158                return new WP_Error(
     159                    "invalid_json",
     160                    "Config file contains invalid JSON: " . json_last_error_msg(),
     161                    array('status' => 400)
     162                );
     163            }
     164
     165            // Get products for horizontal layout
     166            $horizonLayoutWithProducts = $this->getProductsForHorizonLayout($array->HorizonLayout, $api, $request);
     167            $array->HorizonLayout = json_decode(json_encode($horizonLayoutWithProducts));
     168
     169            // Get products for dynamic layout in tabBar
     170            $tabBar = $array->TabBar;
    155171            $results = [];
    156172            foreach ($tabBar as $tabBarItem) {
    157                 if($tabBarItem['layout'] == 'dynamic' && isset($tabBarItem['configs']) && is_array($tabBarItem['configs']) && isset($tabBarItem['configs']['HorizonLayout'])){
    158                     $tabBarItem['configs']['HorizonLayout'] = $this->getProductsForHorizonLayout($tabBarItem['configs']['HorizonLayout'], $api, $request);
     173                $layout = $tabBarItem->layout;
     174                $configs = $tabBarItem->configs;
     175               
     176                if($layout == 'dynamic' && isset($configs) && is_array($configs)){
     177                    $horizonLayout = $configs->HorizonLayout;
     178
     179                    if(isset($horizonLayout) && is_array($horizonLayout)){
     180                        $horizonLayoutWithProducts = $this->getProductsForHorizonLayout($horizonLayout, $api, $request);
     181                        $tabBarItem->configs->HorizonLayout = json_decode(json_encode($horizonLayoutWithProducts));
     182                    }
    159183                }
    160184                $results[] = $tabBarItem;
    161185            }
    162             $array['TabBar'] = $results;
    163 
    164             //get products for vertical layout
    165             if (isset($array["VerticalLayout"])) {
    166                 $layout = $array["VerticalLayout"];
    167                 if (!in_array($layout['layout'], $this->unSupportedVerticalLayouts)) {
    168                     if($countDataLayout <  4){
    169                         $layout["data"] = $this->getProductsByLayout($layout, $api, $request);
     186            $array->TabBar = $results;
     187
     188            // Get products for vertical layout
     189            $countDataLayout = 0;
     190            $results = [];
     191            if (isset($array->VerticalLayout)) {
     192                $layout = $array->VerticalLayout;
     193                if (!in_array($layout->layout, $this->unSupportedVerticalLayouts)) {
     194                    if ($countDataLayout <  4) {
     195                        $layout->data = $this->getProductsByLayout(json_decode(json_encode($layout), true), $api, $request);
    170196                        $countDataLayout += 1;
    171197                    }
    172                     $array['VerticalLayout'] = $layout;
    173                 }
    174             }
    175 
    176             //save data to  cache file
    177             file_put_contents($homeCache, json_encode($array));
     198                    $array->VerticalLayout = $layout;
     199                }
     200            }
     201
     202            // Save data to a cache file
     203            // But do not have a way to clear cache
     204            $cacheResult = file_put_contents($homeCache, json_encode($array));
     205            if ($cacheResult === false) {
     206                // Continue even if cache write fails, but maybe log it
     207                error_log("Failed to write home cache file: " . $homeCache);
     208            }
    178209
    179210            return $array;
     
    183214    }
    184215
    185     function getProductsForHorizonLayout($horizonLayout, $api, $request){
     216    function getProductsForHorizonLayout($horizonLayout, $api, $request)
     217    {
    186218        $countDataLayout = 0;
    187219        $results = [];
     220
    188221        foreach ($horizonLayout as $layout) {
    189             if (in_array($layout['layout'], $this->supportedLayouts)) {
    190                 if($countDataLayout <  4){
    191                     $layout["data"] = $this->getProductsByLayout($layout, $api, $request);
     222            if (in_array($layout->layout, $this->supportedLayouts)) {
     223                if ($countDataLayout <  4) {
     224                    $layout->data = $this->getProductsByLayout(json_decode(json_encode($layout), true), $api, $request);
    192225                    $countDataLayout += 1;
    193226                }
    194227                $results[] = $layout;
    195228            } else {
    196                 if (isset($layout["items"]) && count($layout["items"]) > 0) {
     229                if (isset($layout->items) && count($layout->items) > 0) {
    197230                    $items = [];
    198                     foreach ($layout["items"] as $item) {
    199                         if($countDataLayout <  4 && array_key_exists('layout', $item) && in_array($item['layout'], $this->supportedLayouts)){
     231                    $itemArr = json_decode(json_encode($layout->items), true);
     232                    foreach ($itemArr as $item) {
     233                        if ($countDataLayout <  4 && array_key_exists('layout', $item) && in_array($item['layout'], $this->supportedLayouts)) {
    200234                            $item["data"] = $this->getProductsByLayout($item, $api, $request);
    201235                            $countDataLayout += 1;
    202236                        }
     237
    203238                        $items[] = $item;
    204239                    }
    205                     $layout["items"] = $items;
     240                    $layout->items = $items;
    206241                }
    207242                $results[] = $layout;
  • mstore-api/trunk/controllers/flutter-iyzico.php

    r3194626 r3211961  
    6363        $options = $this->createOptions();
    6464        $req = new \Iyzipay\Request\RetrieveCheckoutFormRequest();
    65         $req->setLocale( 'en' );
     65        $req->setLocale( $this->getLanguageSetting() );
    6666        $req->setToken( $request['token'] );
    6767        $req->setConversationId( $request['order_id'] );
     
    132132        $callback_url = $order->get_checkout_order_received_url();
    133133        $request = new \Iyzipay\Request\CreateCheckoutFormInitializeRequest();
    134         $request->setLocale('en');
     134        $request->setLocale($this->getLanguageSetting());
    135135        $request->setConversationId($order_id);
    136136        $request->setPrice(round( $order->get_total(), 2 ));
     
    197197        return $settings['order_status'];
    198198    }
     199
     200    private function getLanguageSetting(){
     201        $checkoutSettings   = new \Iyzico\IyzipayWoocommerce\Checkout\CheckoutSettings();
     202        $settings = $checkoutSettings->getSettings();
     203
     204        return $settings['form_language'] || 'en';
     205    }
    199206}
    200207
  • mstore-api/trunk/functions/index.php

    r3205338 r3211961  
    66// migrate for old versions
    77function verifyPurchaseCodeAuto(){
    8     $is_verified = (get_option('mstore_purchase_code') ==  true || get_option('mstore_purchase_code') ==  "1") && !empty(get_option('mstore_purchase_code_key'))  && empty(get_option('mstore_active_hash_code'));
    9     if($is_verified){
    10         verifyPurchaseCode(get_option('mstore_purchase_code_key'));
    11     }
     8    // $is_verified = (get_option('mstore_purchase_code') ==  true || get_option('mstore_purchase_code') ==  "1") && !empty(get_option('mstore_purchase_code_key'))  && empty(get_option('mstore_active_hash_code'));
     9    // if($is_verified){
     10    //     verifyPurchaseCode(get_option('mstore_purchase_code_key'));
     11    // }
    1212}
    1313
  • mstore-api/trunk/mstore-api.php

    r3205338 r3211961  
    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.16.5
     6 * Version: 4.16.6
    77 * Author: FluxBuilder
    88 * Author URI: https://fluxbuilder.com
     
    5353include_once plugin_dir_path(__FILE__) . "controllers/flutter-iyzico.php";
    5454include_once plugin_dir_path(__FILE__) . "controllers/flutter-phonepe.php";
     55include_once plugin_dir_path(__FILE__) . "controllers/flutter-points-offline-store.php";
    5556
    5657if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
     
    6061class MstoreCheckOut
    6162{
    62     public $version = '4.16.5';
     63    public $version = '4.16.6';
    6364
    6465    public function __construct()
     
    7778        //include_once(ABSPATH . 'wp-includes/pluggable.php');
    7879
    79         //migrate old versions to re-verify purchase code automatically
    80         verifyPurchaseCodeAuto();
     80        // //migrate old versions to re-verify purchase code automatically
     81        // verifyPurchaseCodeAuto();
    8182
    8283        add_filter( 'get_avatar_url', array( $this, 'filter_avatar' ), 10, 3 );
     
    229230    }
    230231
    231     public function filter_avatar( $url, $id_or_email, $args ) {
    232         $finder = false;
    233         $is_id  = is_numeric( $id_or_email );
    234 
    235         if ( $is_id ) {
    236             $finder = absint( $id_or_email );
    237         } elseif ( is_string( $id_or_email ) ) {
    238             $finder = $id_or_email;
    239         } elseif ( $id_or_email instanceof \WP_User ) {
    240             // User Object.
    241             $finder = $id_or_email->ID;
    242         } elseif ( $id_or_email instanceof \WP_Post ) {
    243             // Post Object.
    244             $finder = (int) $id_or_email->post_author;
    245         } elseif ( $id_or_email instanceof \WP_Comment ) {
    246             return $url;
    247         }
    248 
    249         if ( ! $finder ) {
    250             return $url;
    251         }
    252 
    253         $user = get_user_by( $is_id ? 'ID' : 'email', $finder );
    254 
    255         if ( $user ) {
    256             $avatar = get_user_meta( $user->ID, 'user_avatar', true );
    257             if (isset($avatar) && $avatar !== "" && !is_bool($avatar)) {
    258                 $url = $avatar[0];
    259             }
    260         }
    261         return $url;
    262     }
     232    public function filter_avatar($url, $id_or_email, $args)
     233    {
     234        $finder = false;
     235        $user = false;
     236
     237        // Early return if id_or_email is empty
     238        if (empty($id_or_email)) {
     239            return $url;
     240        }
     241
     242        if (is_numeric($id_or_email)) {
     243            $user = get_user_by('id', absint($id_or_email));
     244        } elseif (is_string($id_or_email) && is_email($id_or_email)) {
     245            $user = get_user_by('email', $id_or_email);
     246        } elseif ($id_or_email instanceof WP_User) {
     247            $user = $id_or_email;
     248        } elseif ($id_or_email instanceof WP_Post) {
     249            $user = get_user_by('id', (int)$id_or_email->post_author);
     250        } elseif ($id_or_email instanceof WP_Comment) {
     251            if (!empty($id_or_email->user_id)) {
     252                $user = get_user_by('id', (int)$id_or_email->user_id);
     253            }
     254        }
     255
     256        if ($user && !is_wp_error($user)) {
     257            $avatar = get_user_meta($user->ID, 'user_avatar', true);
     258            if (isset($avatar) && $avatar !== "" && !is_bool($avatar) && !empty($avatar[0])) {
     259                return $avatar[0];
     260            }
     261        }
     262
     263        return $url;
     264    }
    263265
    264266    function mstore_delete_json_file(){
     
    619621    $taxonomy = wc_attribute_taxonomy_name($item->attribute_name);
    620622
    621     // Get list attribute terms based on attribute.
     623    // Combine all attribute terms into the return result when getting
     624    // attributes. Reduce api calls to get sub-attributes from the app
     625    $options = get_terms([
     626        'taxonomy' => $taxonomy,
     627        'hide_empty' => false,
     628    ]);
     629
     630    $response->data['terms'] = $options;
     631
     632    // Get list count of attribute terms based on attribute.
    622633    $terms = get_filtered_term_product_counts($request, $taxonomy);
    623634
     
    11031114    $response->data['line_items'] = $line_items;
    11041115
    1105     // Get the value
    1106     $bacs_info = get_option( 'woocommerce_bacs_accounts');
    1107     $response->data['bacs_info'] = $bacs_info;
    1108    
     1116    // Get payment method
     1117    $payment_method = $response->data['payment_method'];
     1118    $payment_method_title = $response->data['payment_method_title'];
     1119    $order_id = $response->data['id'];
     1120
     1121    // Get default Bank transfer info
     1122    if ($payment_method == 'bacs' && class_exists('WC_Gateway_BACS')) {
     1123        $bacs = new WC_Gateway_BACS();
     1124        $bacs_accounts = apply_filters('woocommerce_bacs_accounts', $bacs->account_details, $order_id);
     1125        $response->data['bacs_info'] = $bacs_accounts;
     1126    }
     1127
     1128    // Get other Bank transfer info
     1129    if (strpos($payment_method, 'bank_transfer') !== false && is_plugin_active('fr-multi-bank-transfer-payment-gateways-for-woocommerce/fr-multi-bank-transfer-gateways-for-woocommerce.php')) {
     1130        require_once ABSPATH . 'wp-content/plugins/fr-multi-bank-transfer-payment-gateways-for-woocommerce/includes/gateways/class-fr-multi-bank-transfer-gateways-for-woocommerce-bank-transfer.php';
     1131
     1132        $bacs = new Fr_Multi_Bank_Transfer_Gateways_For_Woocommerce_Bank_Transfer([
     1133            'id' => $payment_method,
     1134            'method_title' => $payment_method_title,
     1135        ]);
     1136        $bacs_accounts = apply_filters('woocommerce_bacs_accounts', $bacs->account_details, $order_id);
     1137        $response->data['bacs_info'] = $bacs_accounts;
     1138    }
     1139
    11091140    return $response;
    11101141}
  • mstore-api/trunk/readme.txt

    r3205338 r3211961  
    44Requires at least: 4.4
    55Tested up to:      6.5.3
    6 Stable tag:        4.16.5
     6Stable tag:        4.16.6
    77License:           GPL-2.0
    88License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51= 4.16.6 =
     52  * Support points offline store api
     53
    5154= 4.16.5 =
    5255  * Fix to check file type when upload avatar
  • mstore-api/trunk/templates/admin/mstore-api-admin-dashboard.php

    r3181851 r3211961  
    304304
    305305        <button type="submit" class="mstore-button-class" name='but_submit'>Save</button>
    306         <button type="submit" class="mstore-button-class bg-red-700" name='but_deactive'
     306        <!-- <button type="submit" class="mstore-button-class bg-red-700" name='but_deactive'
    307307                onclick="return confirm('Are you sure to deactivate the license on this domain?');">Deactivate License
    308         </button>
     308        </button> -->
    309309    </form>
    310310    <?php
Note: See TracChangeset for help on using the changeset viewer.