Plugin Directory

Changeset 2903804


Ignore:
Timestamp:
04/25/2023 10:05:43 AM (3 years ago)
Author:
abrestan
Message:

2.2.6

Location:
abrestan/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • abrestan/trunk/abrestan.php

    r2643897 r2903804  
    44 *    Plugin URI: abrestan.com
    55 *    Description: Using this web service, you can connect your store to abrestan cloud accounting software.
    6  *    Version: 2.2.3
     6 *    Version: 2.2.6
    77 *    Author: KTE
    88 *    WC requires at least: 4.1.0
     
    180180{
    181181    $logs = get_log();
    182     unlink(__DIR__ . "/abrestan_logs.log");
     182    if (file_exists(__DIR__ . "/abrestan_logs.log")){
     183        unlink(__DIR__ . "/abrestan_logs.log");
     184    }
     185
    183186    $file = fopen(__DIR__ . "/abrestan_logs.log", "a");
    184187    foreach ($logs as $log) {
  • abrestan/trunk/assets/js/custom210.js

    r2636452 r2903804  
    144144                dataType: 'json',
    145145                success: function (response) {
     146                    $('.loader').show();
    146147                    send_order(response)
    147                     $('.loader').show();
    148148                }
    149149            });
     
    170170                dataType: 'json',
    171171                success: function (response) {
     172
    172173                    $('#alert-success-sync_orders').each(function (){
    173174                        $(this).removeClass();
     
    208209                dataType: 'json',
    209210                success: function (response) {
    210                     console.log(response)
     211
    211212                    $(".loader").hide();
    212213                    $("#abrestan_setting_btn").removeAttr('disabled', 'disabled');
     
    246247                    'orders': part_data,
    247248                };
    248                 console.log(data)
     249
    249250
    250251                $.ajax({
     
    255256                    async: false,
    256257                    success: function (res) {
    257                         $('#alert-success-sync_orders').each(function (){
    258                             $(this).removeClass();
    259                             $(this).addClass("uk-alert uk-alert-success");
    260                             $(this).show();
    261                             $(this).children("p").text("عملیات با موفقیت انجام شد. جهت کسب اطلاعات بیشتر رخداد هارا بررسی بفرمایید!");
    262                         })
    263258
    264259                    }
     
    267262            }
    268263        }
    269 
     264        $('#alert-success-sync_orders').each(function (){
     265            $(this).removeClass();
     266            $(this).addClass("uk-alert uk-alert-success");
     267            $(this).show();
     268            $(this).children("p").text("عملیات با موفقیت انجام شد. جهت کسب اطلاعات بیشتر رخداد هارا بررسی بفرمایید!");
     269        })
    270270        $(".loader").hide();
    271271        $("#abrestan_sync_orders_btn").removeAttr('disabled', 'disabled');
  • abrestan/trunk/inc/Api/abrestan_CreateFactor.php

    r2636452 r2903804  
    2525        return $randomString;
    2626    }
     27    public function tr_num($str, $mod = 'en', $mf = '٫') {
     28        $num_a = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.');
     29        $key_a = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', $mf);
     30        return ($mod == 'fa') ? str_replace($num_a, $key_a, $str) : str_replace($key_a, $num_a, $str);
     31    }
    2732
    2833    public function create_factor($order_id)
    2934    {
     35        $hidden_order_itemmeta = apply_filters(
     36            'woocommerce_hidden_order_itemmeta',
     37            array(
     38                '_qty',
     39                '_tax_class',
     40                '_product_id',
     41                '_variation_id',
     42                '_line_subtotal',
     43                '_line_subtotal_tax',
     44                '_line_total',
     45                '_line_tax',
     46                'method_id',
     47                'cost',
     48                '_reduced_stock',
     49                '_restock_refunded_items',
     50            )
     51        );
     52
     53
     54
     55
    3056        $item_details = new ItemsDetails();
    3157        $order = wc_get_order($order_id);
     
    3965        $custmerLastName = $order_billing_data['last_name'];
    4066
    41         if ($custmer_id == 0) {
    42             if (abrestan_string_to_bool(get_option('abrestan_setting')['AddCustomerToOrder'])) {
    43                 $lastUser = get_user_by('login', $order_billing_data['phone']);
    44 
    45                 if ($lastUser) {
    46                     $custmer_id = $lastUser->ID;
     67        $user = new \WP_User($custmer_id);
     68
     69        if (!$user->exists()) {
     70var_dump($this->tr_num($order_billing_data['phone']));
     71
     72
     73
     74
     75
     76            $custmerFirstName = ($order_billing_data['first_name'])?$order_billing_data['first_name']:(($order_billing_data['last_name'])?$order_billing_data['last_name']:"کاربر");
     77            $custmerLastName = ($order_billing_data['last_name'])?$order_billing_data['last_name']:(($order_billing_data['first_name'])?$order_billing_data['first_name']:"مهمان");;
     78            $custmerUserLogin = ($order_billing_data['phone'])?$this->tr_num($order_billing_data['phone']):$this->randomStr(12);
     79            $custmerUserEmail = ($order_billing_data['email'])?$order_billing_data['email']:"";
     80
     81            var_dump($custmerFirstName);
     82            var_dump($custmerLastName);
     83            var_dump($custmerUserLogin);
     84            var_dump($custmerUserEmail);
     85            var_dump($custmer_id);
     86
     87            if ($custmer_id == 0) {
     88                if (abrestan_string_to_bool(get_option('abrestan_setting')['AddCustomerToOrder'])) {
     89                    $lastUser = get_user_by('login', $order_billing_data['phone']);
     90
     91                    if ($lastUser) {
     92                        $custmer_id = $lastUser->ID;
     93                        update_post_meta($order->get_id(), '_customer_user', $custmer_id);
     94                    } else {
     95                        $userdata = array(
     96                            'user_pass' => $this->randomStr(12),   //(string) The plain-text user password.
     97                            'user_login' => $custmerUserLogin,   //(string) The user's login username.
     98                            'user_email' => $custmerUserEmail,   //(string) The user email address.
     99                            'display_name' => $custmerFirstName . " " . $custmerLastName,   //(string) The user's display name. Default is the user's username.
     100                            'first_name' => $custmerFirstName,   //(string) The user's first name. For new users, will be used to build the first part of the user's display name if $display_name is not specified.
     101                            'last_name' => $custmerLastName,   //(string) The user's last name. For new users, will be used to build the second part of the user's display name if $display_name is not specified.
     102                            'role' => 'Customer',
     103                        );
     104                        $user_id = wp_insert_user($userdata);
     105                        update_post_meta($order->get_id(), '_customer_user', $user_id);
     106                        $custmer_id = $user_id;
     107                    }
     108                } else {
     109                    $custmer_id = "9999";
     110                    $custmerFirstName = "کاربر";
     111                    $custmerLastName = "مهمان";
     112                }
     113
     114            } else {
     115
     116
     117
     118                $lastUserbymobile = get_user_by('login', $order_billing_data['phone']);
     119                $lastUserbyemail = get_user_by('email', $order_billing_data['email']);
     120
     121                if ($lastUserbymobile) {
     122                    $custmer_id = $lastUserbymobile->ID;
     123                    update_post_meta($order->get_id(), '_customer_user', $custmer_id);
     124                } elseif ($lastUserbyemail) {
     125                    $custmer_id = $lastUserbyemail->ID;
    47126                    update_post_meta($order->get_id(), '_customer_user', $custmer_id);
    48127                } else {
    49128                    $userdata = array(
    50129                        'user_pass' => $this->randomStr(12),   //(string) The plain-text user password.
    51                         'user_login' => $order_billing_data['phone'],   //(string) The user's login username.
    52                         'user_email' => $order_billing_data['email'],   //(string) The user email address.
     130                        'user_login' => $custmerUserLogin,   //(string) The user's login username.
     131                        'user_email' => $custmerUserEmail,   //(string) The user email address.
    53132                        'display_name' => $custmerFirstName . " " . $custmerLastName,   //(string) The user's display name. Default is the user's username.
    54133                        'first_name' => $custmerFirstName,   //(string) The user's first name. For new users, will be used to build the first part of the user's display name if $display_name is not specified.
     
    60139                    $custmer_id = $user_id;
    61140                }
    62             } else {
    63                 $custmer_id = "9999";
    64                 $custmerFirstName = "کاربر";
    65                 $custmerLastName = "مهمان";
    66141            }
     142
    67143
    68144        }
     
    75151
    76152
     153
    77154            if ($product_id != "error") {
    78                 $product_name = $product_details->get_product_name($product_id);
     155
     156
     157
     158
     159
     160
     161
     162
     163                $product_name = $product_details->get_product_name($order_item);
    79164                $product_quantity = $product_data['quantity'];
    80165                $product_price = $item_details->covert_price($product_data['subtotal'] / $product_data['quantity'], $order_currency);
     
    134219        }
    135220
     221
    136222        return $factor;
    137223
  • abrestan/trunk/inc/Api/abrestan_sync_orders.php

    r2643897 r2903804  
    129129        $result = json_decode(wp_remote_retrieve_body($wp_remote_post), true);
    130130
     131        var_dump($result);
     132
    131133        if ($result['code'] == 105) {
    132134
  • abrestan/trunk/inc/Controller/ProductDetails.php

    r2597509 r2903804  
    3333        return $product_id;
    3434    }
    35     public function get_product_name($product_id)
     35    public function get_product_name($item)
    3636    {
    37         $product=$this->get_product($product_id);
    38         $product_name=$product->get_data()['name'];
     37        $hidden_order_itemmeta = apply_filters(
     38            'woocommerce_hidden_order_itemmeta',
     39            array(
     40                '_qty',
     41                '_tax_class',
     42                '_product_id',
     43                '_variation_id',
     44                '_line_subtotal',
     45                '_line_subtotal_tax',
     46                '_line_total',
     47                '_line_tax',
     48                'method_id',
     49                'cost',
     50                '_reduced_stock',
     51                '_restock_refunded_items',
     52            )
     53        );
     54        $product_name=$item->get_name();
     55        $meta_data = $item->get_all_formatted_meta_data( '' );
     56        if ( $meta_data ){
     57            if (count($meta_data)>1){
     58                foreach ( $meta_data as $meta_id => $meta ){
     59                    if ( in_array( $meta->key, $hidden_order_itemmeta, true ) ) {
     60                        continue;
     61                    }
     62                    $product_name=$product_name." - ".strip_tags(wp_kses_post( force_balance_tags( $meta->display_value )));
     63
     64                }
     65            }
     66
     67        }
     68
    3969
    4070        return $product_name;
  • abrestan/trunk/templates/admin/admin.php

    r2636452 r2903804  
    11<?php
     2$login=false;
    23if (get_option('abrestan_login')) {
    34    $login = true;
     
    174175                                            <?php
    175176                                            $companies = get_option('abrestan_companies_list');
     177
    176178                                            $i = 0;
    177                                             foreach ($companies as $company) {
    178                                                 ?>
    179                                                 <option <?php echo (get_option('abrestan_company')['companyCode'] == esc_attr($company['company_id'])) ? 'selected' : ''; ?>
    180                                                         value=<?php echo esc_attr($company['company_id']) ?>><?php echo esc_attr($company['company_name']) ?></option>
    181                                                 <?php
    182                                                 $i++;
     179                                            if ($companies){
     180                                                foreach ($companies as $company) {
     181                                                    ?>
     182                                                    <option <?php echo (get_option('abrestan_company') && get_option('abrestan_company')['companyCode'] == esc_attr($company['company_id'])) ? 'selected' : ''; ?>
     183                                                            value="<?php echo esc_attr($company['company_id']) ?>"><?php echo esc_attr($company['company_name']) ?></option>
     184                                                    <?php
     185                                                    $i++;
     186                                                }
    183187                                            }
     188
    184189                                            ?>
    185190                                        </select>
     
    220225                                           for="from-date"><?php _e('from date', 'abrestan'); ?></label>
    221226                                    <input dir="ltr" class="uk-input uk-form-width-small" id="from-date" type="text"
    222                                            name="from-date" placeholder="1400/01/01" value="1400/01/01">
     227                                           name="from-date" placeholder="1400/01/01" value="1401/05/01">
    223228                                </div>
    224229                                <div class="uk-margin  uk-grid ">
     
    226231                                           for="to-date"><?php _e('to date', 'abrestan'); ?></label>
    227232                                    <input dir="ltr" class="uk-input uk-form-width-small" id="to-date" type="text"
    228                                            name="to-date" placeholder="1400/12/29" value="1400/12/29">
     233                                           name="to-date" placeholder="1400/12/29" value="1401/05/29">
    229234                                </div>
    230235                                <div class="uk-margin">
Note: See TracChangeset for help on using the changeset viewer.