Plugin Directory

Changeset 2716780


Ignore:
Timestamp:
05/01/2022 06:43:10 AM (4 years ago)
Author:
sokangroup
Message:

Fix bugs

Location:
sokan-integration
Files:
18 added
2 edited

Legend:

Unmodified
Added
Removed
  • sokan-integration/trunk/include/classes/class-skng-api.php

    r2708932 r2716780  
    116116     * send data to sokan in bulk mode
    117117     * every time bulk mode request failed this function chunked input array to two array and retry
    118      * @param $endpoint
    119118     * @param $data
    120119     * @return array
  • sokan-integration/trunk/include/classes/class-skng-db.php

    r2708932 r2716780  
    156156            $date = $value['modified_date'] ?? $date;
    157157            $order_date = $value['post_date'];
    158             $first_name = $value[$this->order_attr['first_name']] ?? "Undefined";
    159             $last_name = $value[$this->order_attr['last_name']] ?? "customer";
     158            $first_name = $value[$this->order_attr['first_name']] ?? "مشتری";
     159            $last_name = $value[$this->order_attr['last_name']] ?? "";
    160160            $customer_id = $value[$this->order_attr['user_id']] ?? 0;
    161             $customer_name = $first_name . " " . $last_name;
     161            $customer_name = trim($first_name, " ")  . " " . trim($last_name, " ");
     162            $customer_name = trim($customer_name, " ");
     163            $customer_phone = $value[$this->order_attr['phone']] ?? "";
     164
    162165            if ($customer_id == 0) {
     166
     167                if (!empty($customer_phone)){
     168                    if (preg_match('/^(?:98|\+98|0098|0)?9[0-9]{9}$/', $customer_phone)) {
     169                        $customer_id = $customer_phone = preg_replace('/^(?:98|\+98|0098|0)/', "0", $customer_phone);
     170                    }else{
     171                        $customer_id =  $customer_phone;
     172                    }
     173                }
     174
    163175                $customer_id = $customer_name;
    164176            }
    165             $customer_phone = $value[$this->order_attr['phone']] ?? "";
    166             $country = $value[$this->order_attr['country']] ?? "IR";
    167             $state = $value[$this->order_attr['state']] ?? "Undefined State";
    168             $city = $value[$this->order_attr['city']] ?? "Undefined City";
     177            $country = $value[$this->order_attr['country']] ?? "ایران";
     178            $state = $value[$this->order_attr['state']] ?? "استان نا مشخص";
     179            $city = $value[$this->order_attr['city']] ?? "شهر نامشخص";
    169180
    170181            if (!isset($value['items']) and isset($value['_order_total'])) {
     
    208219                }
    209220
    210                 $weight = $item['pa_weight']??0;
     221                $weight = $item['pa_weight'] ?? 0;
    211222
    212223                $order = [
     
    221232                    'customer_id' => $customer_id,
    222233                    'customer_name' => $customer_name,
    223                     'region0' => $country,
     234                    'region0' => trim($country," "),
    224235                    'region1' => self::getStateName($state),
    225                     'region2' => $city,
     236                    'region2' => trim($city," "),
    226237                    'sku_id' => $product_id,
    227238                    'product_name' => $product_id,
     
    230241
    231242                if (preg_match('/^(?:98|\+98|0098|0)?9[0-9]{9}$/', $customer_phone)) {
    232                     $order['customer_phone_number'] = (string)$customer_phone;
     243                    $order['customer_phone_number'] = (string)preg_replace('/^(?:98|\+98|0098)/', "0", $customer_phone);
    233244                }
    234245
     
    253264
    254265                $product = $all_products[$order_item['sku_id']];
    255                 $new_orders[$key]['product_name']= $product['name'];
     266                $new_orders[$key]['product_name'] = $product['name'];
    256267
    257268                if (isset($product['brands'])) {
    258269                    foreach (array_values($product['brands']) as $br_key => $name) {
    259                         $new_orders[$key]['product_brand' . $br_key]= $name;
     270                        $new_orders[$key]['product_brand' . $br_key] = $name;
    260271                        if ($br_key == 1) {
    261272                            break;
     
    266277                if (isset($product['categories'])) {
    267278                    foreach (array_values($product['categories']) as $cat_key => $name) {
    268                         $new_orders[$key]['product_category' . $cat_key]= $name;
     279                        $new_orders[$key]['product_category' . $cat_key] = $name;
    269280                        if ($cat_key == 9) {
    270281                            break;
     
    274285
    275286                if ($order_item['weight'] == 0 and isset($product['weight'])) {
    276                     $new_orders[$key]['weight']= (int)$product['weight'];
    277                 }
    278 
    279             }
    280         }
    281 
    282         $orders_for_sync = array_merge($this->getErrorLogs() , $new_orders);
     287                    $new_orders[$key]['weight'] = (int)$product['weight'];
     288                }
     289
     290            }
     291        }
     292
     293        $orders_for_sync = array_merge($this->getErrorLogs(), $new_orders);
    283294
    284295        return ['order' => $orders_for_sync, 'date' => $date];
     
    337348                   AND `{$this->db->prefix}posts`.post_modified > '$date'
    338349                   GROUP BY `{$this->db->prefix}posts`.ID
    339                    ORDER BY `{$this->db->prefix}posts`.post_modified LIMIT 200 ",
     350                   ORDER BY `{$this->db->prefix}posts`.post_modified LIMIT 50 ",
    340351            ARRAY_A
    341352        );
     
    446457            'QHM' => 'قم',
    447458            'KRD' => 'کردستان',
    448             'KBD' => 'کهگیلوییه و بویراحمد',
     459            'KBD' => 'کهگیلویه و بویراحمد',
    449460            'GLS' => 'گلستان',
    450461            'GIL' => 'گیلان',
     
    459470        }
    460471
    461         return $state;
     472        return trim($state, " ");
    462473    }
    463474}
Note: See TracChangeset for help on using the changeset viewer.