Plugin Directory

Changeset 3412783


Ignore:
Timestamp:
12/06/2025 06:49:39 AM (3 months ago)
Author:
hamsalam
Message:

1.6.1

Location:
sync-basalam
Files:
276 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • sync-basalam/trunk/CHANGELOG.md

    r3406805 r3412783  
    11# Changelog
     2
     3<details>
     4<summary>1.6.1 - 2025-12-6</summary>
     5
     6### Changed / Improved
     7- Handle cursor for get order lists
     8
     9### Fixed
     10- don't send request to core.basalam.com
     11- add reduce/increase stock action for woosalam order statuses
     12
     13</details>
     14
    215<details>
    316<summary>1.6.0 - 2025-12-1</summary>
  • sync-basalam/trunk/includes/class-sync-basalam-plugin.php

    r3406805 r3412783  
    44class SyncBasalamPlugin
    55{
    6     const VERSION = '1.6.0';
     6    const VERSION = '1.6.1';
    77
    88    public function __construct()
     
    182182        add_filter('wc_order_statuses', [new SyncBasalamOrderStatuses(), 'orderStatuses']);
    183183
     184        add_action('woocommerce_order_status_bslm-rejected', 'wc_maybe_increase_stock_levels');
     185        add_action('woocommerce_order_status_bslm-preparation', 'wc_maybe_reduce_stock_levels');
     186        add_action('woocommerce_order_status_bslm-shipping', 'wc_maybe_reduce_stock_levels');
     187        add_action('woocommerce_order_status_bslm-completed', 'wc_maybe_reduce_stock_levels');
     188
    184189        add_action('sync_basalam_process_discount_tasks', array($this, 'processDiscountTasksCron'));
    185190
  • sync-basalam/trunk/includes/logger/class-sync-basalam-woo-logger.php

    r3397803 r3412783  
    2828            $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    2929            foreach (array_reverse($lines) as $line) {
    30                 if (preg_match('/^(.*?) (INFO|WARNING|ERROR|DEBUG|ALERT) (.*?)( CONTEXT: (.*))?$/', $line, $matches)) {
     30                // Match ISO 8601 date format more strictly: YYYY-MM-DDTHH:MM:SS+TZ
     31                if (preg_match('/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}) (INFO|WARNING|ERROR|DEBUG|ALERT) (.*?)( CONTEXT: (.*))?$/', $line, $matches)) {
    3132                    $tehranDatetime = SyncBasalamDateConverter::utcToTehran($matches[1]);
     33
     34                    // Skip this log entry if date conversion failed
     35                    if ($tehranDatetime === null) {
     36                        continue;
     37                    }
     38
    3239                    $jalaliDate = SyncBasalamDateConverter::gregorianToJalali(
    3340                        $tehranDatetime->format('Y'),
  • sync-basalam/trunk/includes/services/class-sync-basalam-date-converter.php

    r3397803 r3412783  
    77    public static function utcToTehran($utcDatetime)
    88    {
    9         $utcDate = new DateTime($utcDatetime, new DateTimeZone('UTC'));
    10         $tehranDate = $utcDate->setTimezone(new DateTimeZone('Asia/Tehran'));
    11         return $tehranDate;
     9        try {
     10            $utcDate = new DateTime($utcDatetime, new DateTimeZone('UTC'));
     11            $tehranDate = $utcDate->setTimezone(new DateTimeZone('Asia/Tehran'));
     12            return $tehranDate;
     13        } catch (Exception $e) {
     14            error_log('Invalid date format in utcToTehran: ' . $utcDatetime . ' - Error: ' . $e->getMessage());
     15            return null;
     16        }
    1217    }
    1318
  • sync-basalam/trunk/includes/services/class-sync-basalam-fetch-weekly-unsync-orders.php

    r3397803 r3412783  
    1212    public function addUnsyncBasalamOrderToWoo()
    1313    {
    14         $orders = $this->getSyncBasalamOrdersService->getWeeklySyncBasalamOrders();
    15         $orders = $orders['data'];
    16 
    1714        global $wpdb;
    1815        $table_name_payments = $wpdb->prefix . 'sync_basalam_payments';
    19         if (!$orders['data'] && $orders['status_code'] = 200) {
     16       
     17        $orders = $this->getSyncBasalamOrdersService->getWeeklySyncBasalamOrders();
     18        $orders = $orders;
     19
     20        if (!$orders) {
    2021            return [
    2122                'success' => true,
     
    2526        }
    2627        $new_order = false;
    27         foreach ($orders['data'] as $order) {
     28        foreach ($orders as $order) {
    2829            $invoice_id = $order['order']['id'];
    2930
  • sync-basalam/trunk/includes/services/class-sync-basalam-get-basalam-orders.php

    r3397803 r3412783  
    11<?php
    22if (! defined('ABSPATH')) exit;
     3
    34class SyncBasalamGetSyncBasalamOrders
    45{
     
    1314        $this->apiservice = new SyncBasalamApiServiceManager();
    1415    }
     16
    1517    public function getWeeklySyncBasalamOrders()
    1618    {
    1719        $oneWeekAgoTimestamp = current_time('timestamp', true) - (7 * 24 * 60 * 60);
    1820        $oneWeekAgoIso = gmdate('c', $oneWeekAgoTimestamp);
     21
    1922        $headers = [
    2023            'Authorization' => 'Bearer ' . $this->token
    2124        ];
    2225
    23         $baseUrl = SyncBasalamAdminSettings::getStaticSettings("url_get_sync_basalam_orders");
    24         $url = $baseUrl . '?per_page=30' . '&created_at%5Bgte%5D=' . urlencode($oneWeekAgoIso);
     26        $firstPageUrl = $this->url . '?per_page=30&created_at%5Bgte%5D=' . urlencode($oneWeekAgoIso);
    2527
    26         $orders = $this->apiservice->sendGetRequest($url, $headers);
    27         return $orders;
     28        return $this->fetchAllPages($firstPageUrl, $headers);
     29    }
     30
     31    private function fetchAllPages($url, $headers, $collected = [])
     32    {
     33        $response = $this->apiservice->sendGetRequest($url, $headers);
     34
     35        if (!isset($response['data'])) {
     36            return $collected;
     37        }
     38
     39        $collected = array_merge($collected, $response['data']['data']);
     40
     41        $next = $response['data']['next_cursor'] ?? null;
     42
     43        if ($next) {
     44            $nextUrl = $url . '&cursor=' . urlencode($next);
     45            return $this->fetchAllPages($nextUrl, $headers, $collected);
     46        }
     47
     48        return $collected;
    2849    }
    2950}
  • sync-basalam/trunk/includes/services/class-sync-basalam-order-manager.php

    r3406805 r3412783  
    255255                $order_status = $status_map[$status_id] ?? 'bslm-wait-vendor';
    256256                $order->set_status($order_status);
    257                 wc_reduce_stock_levels($order->get_id());
    258257            }
    259258
  • sync-basalam/trunk/includes/services/class-sync-basalam-system-resource-monitor.php

    r3397803 r3412783  
    171171    }
    172172
    173     private function getNetworkScore()
    174     {
    175         $startTime = microtime(true);
    176         $response = wp_remote_get('https://core.basalam.com/', [
    177             'timeout' => 5,
    178             'sslverify' => false
    179         ]);
    180         $responseTime = microtime(true) - $startTime;
    181 
    182         if (is_wp_error($response)) {
    183             return 50;
    184         }
    185 
    186         if ($responseTime < 0.1) {
    187             return 100;
    188         } elseif ($responseTime < 0.3) {
    189             return 80;
    190         } elseif ($responseTime < 0.7) {
    191             return 60;
    192         } elseif ($responseTime < 1.5) {
    193             return 40;
    194         } else {
    195             return 20;
    196         }
    197     }
    198 
    199173    public function calculateOptimalTasksPerMinute()
    200174    {
     
    204178            'php_version' => $this->getPhpVersionScore(),
    205179            'server_load' => $this->getServerLoadScore(),
    206             'network' => $this->getNetworkScore()
    207180        ];
    208181
     
    211184            'execution_time' => 0.20,
    212185            'server_load' => 0.20,
    213             'network' => 0.30,
    214186            'php_version' => 0.05
    215187        ];
  • sync-basalam/trunk/readme.txt

    r3406805 r3412783  
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 1.6.0
     7Stable tag: 1.6.1
    88License: GPL-2.0-or-later 
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html 
  • sync-basalam/trunk/sync-basalam.php

    r3406805 r3412783  
    55 * Plugin Name: sync basalam | ووسلام
    66 * Description: با استفاده از پلاگین ووسلام  میتوایند تمامی محصولات ووکامرس را با یک کلیک به غرفه باسلامی خود اضافه کنید‌، همچنین تمامی سفارش باسلامی شما به سایت شما اضافه میگردد.
    7  * Version: 1.6.0
     7 * Version: 1.6.1
    88 * Author: Woosalam Dev
    99 * Author URI: https://wp.hamsalam.ir/
  • sync-basalam/trunk/templates/admin/menu/main/section/setting.php

    r3406805 r3412783  
    186186    </section>
    187187</div>
     188
     189<script>
     190(function() {
     191    'use strict';
     192
     193    const initialValues = new Map();
     194
     195    function saveInitialValues(form) {
     196        const elements = form.querySelectorAll('input, select, textarea');
     197        elements.forEach(function(element) {
     198            const name = element.name;
     199            if (!name || name === 'action' || name === '_wpnonce' || name === '_wp_http_referer') {
     200                return;
     201            }
     202
     203            let value;
     204            if (element.type === 'checkbox' || element.type === 'radio') {
     205                value = element.checked;
     206            } else {
     207                value = element.value;
     208            }
     209
     210            const key = name + '_' + (element.type === 'radio' || element.type === 'checkbox' ? element.value : '');
     211            initialValues.set(key, value);
     212        });
     213    }
     214
     215    function handleFormSubmit(event) {
     216        const form = event.target;
     217        const elements = form.querySelectorAll('input, select, textarea');
     218
     219        elements.forEach(function(element) {
     220            const name = element.name;
     221            if (!name || name === 'action' || name === '_wpnonce' || name === '_wp_http_referer') {
     222                return;
     223            }
     224
     225            let currentValue;
     226            if (element.type === 'checkbox' || element.type === 'radio') {
     227                currentValue = element.checked;
     228            } else {
     229                currentValue = element.value;
     230            }
     231
     232            const key = name + '_' + (element.type === 'radio' || element.type === 'checkbox' ? element.value : '');
     233            const initialValue = initialValues.get(key);
     234
     235            if (initialValue === currentValue) {
     236                element.disabled = true;
     237            }
     238        });
     239
     240        setTimeout(function() {
     241            elements.forEach(function(element) {
     242                element.disabled = false;
     243            });
     244        }, 100);
     245    }
     246
     247    document.addEventListener('DOMContentLoaded', function() {
     248        const forms = document.querySelectorAll('form[action*="admin-post.php"]');
     249
     250        forms.forEach(function(form) {
     251            const actionInput = form.querySelector('input[name="action"][value="basalam_update_setting"]');
     252            if (actionInput) {
     253                saveInitialValues(form);
     254
     255                form.addEventListener('submit', handleFormSubmit);
     256            }
     257        });
     258    });
     259})();
     260</script>
Note: See TracChangeset for help on using the changeset viewer.