Plugin Directory

Changeset 2737858


Ignore:
Timestamp:
06/06/2022 06:40:50 AM (4 years ago)
Author:
codeclouds
Message:

Fix - Product mapping saving issue

Location:
unify/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • unify/trunk/Actions/Tools.php

    r2705107 r2737858  
    22
    33namespace CodeClouds\Unify\Actions;
     4
     5use CodeClouds\Unify\Model\Tools_model;
     6use \CodeClouds\Unify\Model\ConfigEncryption;
     7use \CodeClouds\Unify\Service\Helper;
     8use \CodeClouds\Unify\Service\Notice;
    49use \CodeClouds\Unify\Service\Request;
    5 use CodeClouds\Unify\Model\Tools_model;
    6 use \CodeClouds\Unify\Service\Notice;
    7 use \CodeClouds\Unify\Service\Helper;
    8 use \CodeClouds\Unify\Model\ConfigEncryption;
    910
    1011/**
     
    1415class Tools
    1516{
    16     /**
    17     * Setup tools page
    18      */
     17    /**
     18    * Setup tools page
     19     */
    1920    public static function tools_page()
    20     { 
    21         global $wpdb;
    22         $request = [];
    23            
    24         $sections = [
    25             'product-mapping',
    26             'shipping-mapping',
    27             'import-export',
    28            
    29         ];
    30             //******* Get setting for connection Starts ********
    31         $crm_meta = '';
    32         $crm_model_meta = '';
    33         $setting_option = \get_option('woocommerce_codeclouds_unify_settings');
    34        
    35         if (!empty($setting_option) && !empty($setting_option['connection']))
    36             {
     21    {
     22        global $wpdb;
     23        $request = [];
    3724
    38                 $meta_data = \get_post_meta($setting_option['connection'], 'unify_connection_crm');
     25        $sections = [
     26            'product-mapping',
     27            'shipping-mapping',
     28            'import-export',
    3929
    40                 $meta_data_salt = \get_post_meta($setting_option['connection'], 'unify_connection_crm_salt');
     30        ];
     31        //******* Get setting for connection Starts ********
     32        $crm_meta = '';
     33        $crm_model_meta = '';
     34        $setting_option = \get_option('woocommerce_codeclouds_unify_settings');
    4135
     36        if (!empty($setting_option) && !empty($setting_option['connection'])) {
    4237
    43                 if (!empty($meta_data))
    44                 {
    45                     $crm_meta = isset($meta_data_salt[0])?ConfigEncryption::metaDecryptSingle($meta_data[0],$meta_data_salt [0]):$meta_data[0];
    46                    
    47                     if($crm_meta == 'limelight'){
    48                         $meta_model_data = get_post_meta($setting_option['connection'], 'unify_connection_offer_model');
    49                         $crm_model_meta = (!empty($meta_model_data)) ? $meta_model_data[0] : '';
    50                         $shipping_price_settings_option = (!empty($setting_option['shipment_price_settings'])) ? $setting_option['shipment_price_settings'] : '';
    51                     }
    52                     if($crm_meta == 'sublytics'){
    53                         $meta_model_data = get_post_meta($setting_option['connection'], 'unify_connection_offer_model');
    54                         $crm_model_meta = (!empty($meta_model_data)) ? $meta_model_data[0] : '';
    55                         $shipping_price_settings_option = (!empty($setting_option['shipment_price_settings'])) ? $setting_option['shipment_price_settings'] : '';
    56                     }
     38            $meta_data = \get_post_meta($setting_option['connection'], 'unify_connection_crm');
    5739
    58                     if($crm_meta == 'response'){
    59                         $meta_model_data = \get_post_meta($setting_option['connection'], 'unify_response_crm_type_enable');
    60                         $crm_model_meta = (!empty($meta_model_data)) ? $meta_model_data[0] : '';
    61                     }
     40            $meta_data_salt = \get_post_meta($setting_option['connection'], 'unify_connection_crm_salt');
    6241
     42            if (!empty($meta_data)) {
     43                $crm_meta = isset($meta_data_salt[0]) ? ConfigEncryption::metaDecryptSingle($meta_data[0], $meta_data_salt[0]) : $meta_data[0];
    6344
    64                 }
    65             }
    66             //******* Get setting for connection Ends ********
    67            
    68         $request['paged'] = (empty($_GET['paged'])) ? 1 : sanitize_text_field(wp_unslash($_GET['paged']));
    69         $request['posts_per_page'] = (empty($_GET['posts_per_page'])) ? 10 : sanitize_text_field(wp_unslash($_GET['posts_per_page']));
    70            
    71         $request['orderby'] = (empty($_GET['orderby'])) ? 'post_title' : sanitize_text_field(wp_unslash($_GET['orderby']));
    72         $request['order'] = (empty($_GET['order'])) ? 'asc' : sanitize_text_field(wp_unslash($_GET['order']));
    73            
    74         $tools_model_object = new Tools_model();
    75         $data = $tools_model_object->get_products_with_meta($request);
     45                if ($crm_meta == 'limelight') {
     46                    $meta_model_data = get_post_meta($setting_option['connection'], 'unify_connection_offer_model');
     47                    $crm_model_meta = (!empty($meta_model_data)) ? $meta_model_data[0] : '';
     48                    $shipping_price_settings_option = (!empty($setting_option['shipment_price_settings'])) ? $setting_option['shipment_price_settings'] : '';
     49                }
     50                if ($crm_meta == 'sublytics') {
     51                    $meta_model_data = get_post_meta($setting_option['connection'], 'unify_connection_offer_model');
     52                    $crm_model_meta = (!empty($meta_model_data)) ? $meta_model_data[0] : '';
     53                    $shipping_price_settings_option = (!empty($setting_option['shipment_price_settings'])) ? $setting_option['shipment_price_settings'] : '';
     54                }
    7655
    77         if(!empty($data['list'])){
    78             foreach($data['list'] as $k => $prod_list){
    79                 $product = \wc_get_product( $prod_list['ID'] );
    80                 $data['list'][$k]['price'] = $product->get_price();
    81             }
    82         }
     56                if ($crm_meta == 'response') {
     57                    $meta_model_data = \get_post_meta($setting_option['connection'], 'unify_response_crm_type_enable');
     58                    $crm_model_meta = (!empty($meta_model_data)) ? $meta_model_data[0] : '';
     59                }
    8360
    84         $prev_dis = (($request['paged'] == 1)) ? true : false;
    85         $next_dis = (!empty($request['paged']) && $request['paged'] == $data['total']) ? true : false;
     61            }
     62        }
     63        //******* Get setting for connection Ends ********
     64
     65        $request['paged'] = (empty($_GET['paged'])) ? 1 : sanitize_text_field(wp_unslash($_GET['paged']));
     66        $request['posts_per_page'] = (empty($_GET['posts_per_page'])) ? 10 : sanitize_text_field(wp_unslash($_GET['posts_per_page']));
     67
     68        $request['orderby'] = (empty($_GET['orderby'])) ? 'post_title' : sanitize_text_field(wp_unslash($_GET['orderby']));
     69        $request['order'] = (empty($_GET['order'])) ? 'asc' : sanitize_text_field(wp_unslash($_GET['order']));
     70
     71        $tools_model_object = new Tools_model();
     72        $data = $tools_model_object->get_products_with_meta($request);
     73
     74        if (!empty($data['list'])) {
     75            foreach ($data['list'] as $k => $prod_list) {
     76                $product = \wc_get_product($prod_list['ID']);
     77                $data['list'][$k]['price'] = $product->get_price();
     78            }
     79        }
     80
     81        $prev_dis = (($request['paged'] == 1)) ? true : false;
     82        $next_dis = (!empty($request['paged']) && $request['paged'] == $data['total']) ? true : false;
    8683        include_once __DIR__ . '/../Templates/tools.php';
    8784    }
    88    
     85
    8986    public static function save_product()
    90     {
    91         $nonce = Request::post('_wpnonce');
    92         $messages = Helper::getDataFromFile('Messages');
    93         $param = '';
    94        
    95         if (wp_verify_nonce($nonce, 'unify-product') && Request::post('check_submit') == 'update_product')
    96         {
    97             $fields = ['codeclouds_unify_connection', 'codeclouds_unify_shipping', 'codeclouds_unify_offer_id', 'codeclouds_unify_billing_model_id', 'codeclouds_unify_group_id'];
    98            
    99             foreach (Request::post()['map'] as $post_id => $value)
    100             {
    101                 foreach ($value as $field_key => $field_val)
    102                 {
    103                     if (in_array($field_key, $fields))
    104                     {
    105            
    106                         if (
    107                             (gettype(\get_post_meta($post_id, $field_key, true))=='array' && count(\get_post_meta($post_id, $field_key, true)) > 0) ||
    108                             (gettype(\get_post_meta($post_id, $field_key, true))=='string' && !empty(\get_post_meta($post_id, $field_key, true)))
    109                             )
    110                         {
    111                             if (!empty($field_val))
    112                             {
    113                                 /**
    114                                  * If the custom field already has a value, update it.
    115                                  */
    116                                 var_dump(\update_post_meta($post_id, $field_key, trim(esc_attr($field_val))));
    117                             }
    118                             else
    119                             {
    120                                 /**
    121                                  * Delete the meta key if there's no value
    122                                  */
    123                                 \delete_post_meta($post_id, $field_key);
    124                             }
    125                         }
    126                                 else
    127                         {
    128                             /**
    129                              * If the custom field doesn't have a value, add it.
    130                              */
    131                             \add_post_meta($post_id, $field_key, trim(esc_attr($field_val)));
    132                         }
    133                     }
    134                         }
    135             }
    136             $msg = $messages['PRODUCT_MAP']['SUCCESS'];
    137             Notice::setFlashMessage('success', $msg);
    138         }else if (Request::post('check_submit') == 'sort_field'){ // sort_field is for sorting 
    139             $orderBy = (!empty(Request::post('orderby'))) ? Request::post('orderby') : 'post_title';
    140             $order = (!empty(Request::post('order'))) ? Request::post('order') : 'desc';
    141             $param .= (empty($_GET['orderby'])) ? '&orderby='.$orderBy : $orderBy;
    142             $param .= (empty($_GET['order'])) ? '&order='.$order : $order;
    143         }else{
    144             $msg = $messages['COMMON']['ERROR'];
    145             Notice::setFlashMessage('error', $msg);
    146         }
    147        
    148         wp_redirect(Request::post('_wp_http_referer').(!empty($param) ? $param : ''));
    149         exit();
    150     }
     87    {
     88        $nonce = Request::post('_wpnonce');
     89        $messages = Helper::getDataFromFile('Messages');
     90        $param = '';
    15191
    152     public static function save_shipping()
    153     {
    154         $nonce = Request::post('_wpnonce');
    155         $messages = Helper::getDataFromFile('Messages');
    156         $param = '';
    157        
    158         if (wp_verify_nonce($nonce, 'unify-shipping') && Request::post('check_submit') == 'update_product')
    159         {
    160             $fields = ['crm_shipping_id','woo_shipping_method_price','crm_shipping_price'];
    161            
    162             foreach (Request::post()['map'] as $post_id => $value)
    163             {
    164                 foreach ($value as $field_key => $field_val)
    165                 {
    166                     if (in_array($field_key, $fields))
    167                     {
    168                         if (
    169                             (gettype(\get_post_meta($post_id, $field_key, true))=='array' && count(\get_post_meta($post_id, $field_key, true)) > 0) ||
    170                             (gettype(\get_post_meta($post_id, $field_key, true))=='string' && !empty(\get_post_meta($post_id, $field_key, true)))
    171                             )
    172                         {                       
    173                             if (!empty($field_val))
    174                             {
    175                                 /**
    176                                  * If the custom field already has a value, update it.
    177                                  */
    178                                 var_dump(\update_post_meta($post_id, $field_key, trim(esc_attr($field_val))));
    179                             }
    180                             else
    181                             {
    182                                 /**
    183                                  * Delete the meta key if there's no value
    184                                  */
    185                                 \delete_post_meta($post_id, $field_key);
    186                             }
    187                         }
    188                                 else
    189                         {
    190                             /**
    191                              * If the custom field doesn't have a value, add it.
    192                              */
    193                             \add_post_meta($post_id, $field_key, trim(esc_attr($field_val)));
    194                         }
    195                     }
    196                         }
    197             }
    198             $msg = $messages['SHIPPING_MAP']['SUCCESS'];
    199             Notice::setFlashMessage('success', $msg);
    200         }else{
    201             $msg = $messages['COMMON']['ERROR'];
    202             Notice::setFlashMessage('error', $msg);
    203         }
    204        
    205         wp_redirect(Request::post('_wp_http_referer').(!empty($param) ? $param : ''));
    206         exit();
    207     }
     92        if (wp_verify_nonce($nonce, 'unify-product') && Request::post('check_submit') == 'update_product') {
     93            $fields = ['codeclouds_unify_connection', 'codeclouds_unify_shipping', 'codeclouds_unify_offer_id', 'codeclouds_unify_billing_model_id', 'codeclouds_unify_group_id'];
     94
     95            foreach (Request::post()['map'] as $post_id => $value) {
     96                foreach ($value as $field_key => $field_val) {
     97                    if (in_array($field_key, $fields)) {
     98                        if (count(\get_post_meta($post_id, $field_key)) > 0) {
     99                            if (!empty($field_val)) {
     100                                /**
     101                                 * If the custom field already has a value, update it.
     102                                 */
     103                                var_dump(\update_post_meta($post_id, $field_key, trim(esc_attr($field_val))));
     104                            } else {
     105                                /**
     106                                 * Delete the meta key if there's no value
     107                                 */
     108                                \delete_post_meta($post_id, $field_key);
     109                            }
     110                        } else {
     111                            /**
     112                             * If the custom field doesn't have a value, add it.
     113                             */
     114                            \add_post_meta($post_id, $field_key, trim(esc_attr($field_val)));
     115                        }
     116                    }
     117                }
     118            }
     119            $msg = $messages['PRODUCT_MAP']['SUCCESS'];
     120            Notice::setFlashMessage('success', $msg);
     121        } else if (Request::post('check_submit') == 'sort_field') { // sort_field is for sorting
     122            $orderBy = (!empty(Request::post('orderby'))) ? Request::post('orderby') : 'post_title';
     123            $order = (!empty(Request::post('order'))) ? Request::post('order') : 'desc';
     124            $param .= (empty($_GET['orderby'])) ? '&orderby=' . $orderBy : $orderBy;
     125            $param .= (empty($_GET['order'])) ? '&order=' . $order : $order;
     126        } else {
     127            $msg = $messages['COMMON']['ERROR'];
     128            Notice::setFlashMessage('error', $msg);
     129        }
     130
     131        wp_redirect(Request::post('_wp_http_referer') . (!empty($param) ? $param : ''));
     132        exit();
     133    }
     134
     135    public static function save_shipping()
     136    {
     137        $nonce = Request::post('_wpnonce');
     138        $messages = Helper::getDataFromFile('Messages');
     139        $param = '';
     140
     141        if (wp_verify_nonce($nonce, 'unify-shipping') && Request::post('check_submit') == 'update_product') {
     142            $fields = ['crm_shipping_id', 'woo_shipping_method_price', 'crm_shipping_price'];
     143
     144            foreach (Request::post()['map'] as $post_id => $value) {
     145                foreach ($value as $field_key => $field_val) {
     146                    if (in_array($field_key, $fields)) {
     147                        if (count(\get_post_meta($post_id, $field_key)) > 0) {
     148                            if (!empty($field_val)) {
     149                                /**
     150                                 * If the custom field already has a value, update it.
     151                                 */
     152                                var_dump(\update_post_meta($post_id, $field_key, trim(esc_attr($field_val))));
     153                            } else {
     154                                /**
     155                                 * Delete the meta key if there's no value
     156                                 */
     157                                \delete_post_meta($post_id, $field_key);
     158                            }
     159                        } else {
     160                            /**
     161                             * If the custom field doesn't have a value, add it.
     162                             */
     163                            \add_post_meta($post_id, $field_key, trim(esc_attr($field_val)));
     164                        }
     165                    }
     166                }
     167            }
     168
     169            $msg = $messages['SHIPPING_MAP']['SUCCESS'];
     170            Notice::setFlashMessage('success', $msg);
     171        } else {
     172            $msg = $messages['COMMON']['ERROR'];
     173            Notice::setFlashMessage('error', $msg);
     174        }
     175
     176        wp_redirect(Request::post('_wp_http_referer') . (!empty($param) ? $param : ''));
     177        exit();
     178    }
    208179}
  • unify/trunk/readme.txt

    r2719260 r2737858  
    55Tested up to: 5.9
    66Requires PHP: 5.6
    7 Stable tag: 3.3.4
     7Stable tag: 3.3.5
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html\
     
    9595== Changelog ==
    9696
     97= 3.3.5 =
     98* Fix - Product mapping saving issue.
     99
    97100= 3.3.4 =
    98101* Enhacement - Updated License management links.
  • unify/trunk/unify.php

    r2719260 r2737858  
    77 * Author: CodeClouds <sales@codeclouds.com>
    88 * Author URI: https://www.CodeClouds.com/
    9  * Version: 3.3.4
     9 * Version: 3.3.5
    1010 * License: GPLv2 or later
    1111 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6060define('UNIFY_PLATFORM_LOGIN', 'https://accounts.unify.to/login');
    6161define('UNIFY_WP_HOME_URL', home_url());
    62 define('UNIFY_JS_VERSION', '3.3.4');
     62define('UNIFY_JS_VERSION', '3.3.5');
Note: See TracChangeset for help on using the changeset viewer.