Plugin Directory

Changeset 2742574


Ignore:
Timestamp:
06/15/2022 04:22:16 AM (4 years ago)
Author:
wesleydeveloper
Message:

Corrigindo erro de sincronização automática

Location:
ourivesweb-api/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ourivesweb-api/trunk/ourivesweb.php

    r2726965 r2742574  
    44 * Plugin URI:        https://wordpress.org/plugins/OurivesWeb-api/
    55 * Description:       Integração do OurivesWeb com o WooCommerce.
    6  * Version:           1.1.0
     6 * Version:           1.1.1
    77 * Requires at least: 5.2
    88 * Requires PHP:      7.3
     
    1818if (!defined('ABSPATH')) {
    1919    exit;
     20}
     21
     22if (!defined('OURIVES_VERSION')) {
     23    define('OURIVES_VERSION', '1.1.1');
    2024}
    2125
  • ourivesweb-api/trunk/readme.txt

    r2726965 r2742574  
    33Contributors: ponto25,wesleydeveloper
    44Tags: Invoicing, Faturação, Encomendas, Orders
    5 Stable tag: 1.1.0
     5Stable tag: 1.1.1
    66Requires at least: 4.6
    7 Tested up to: 5.9
     7Tested up to: 6.0
    88Requires PHP: 7.3
    99License: GPLv2 or later
     
    6363
    6464== Changelog ==
    65 * Fixed autoload errors
    66 * Replaced deprecated functions
    67 * Added pvpiva1, pvpiva2, pvpiva3 fields in price selection
    68 * Fixed auto sync option
    69 * Fixed logout route
     65* Corrigindo bugs e funções depreciadas
     66* Corrigindo função terminar sessão
     67* Adicionando opções IVA nas seleções de preço
     68* Resolvendo problemas de sincronização automática
    7069
    7170== Upgrade Notice ==
  • ourivesweb-api/trunk/src/Activators/Install.php

    r2726965 r2742574  
    9191        $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description) VALUES('document_type', 'Escolha o tipo de documentos que deseja emitir')");
    9292        $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description) VALUES('vat_field', 'Número de contribuinte')");
    93         $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description,selected) VALUES('Ourives_stock_sync', 'Sincronizar Stocks','0')");
    94         $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description,selected) VALUES('Ourives_stock_sync_time', 'Tempo de sincronização automatica dos stocks','21600')");
     93        $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description,selected) VALUES('ourivesweb_stock_sync', 'Sincronizar Stocks','0')");
     94        $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description,selected) VALUES('ourivesweb_stock_sync_time', 'Tempo de sincronização automatica dos stocks','21600')");
    9595        $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description) VALUES('OURIVESWEB_ACCESS_TOKEN', 'Token criado no login do utilizador')");
    9696        $wpdb->query("INSERT INTO `OurivesWeb_api_config`(config, description,selected) VALUES('IMPORT_STATUS', 'Artigos sincronizados são guardados como Rascunho ou publicados','1')");
  • ourivesweb-api/trunk/src/Plugin.php

    r2726965 r2742574  
    2222        Cat_meta_data::run();
    2323        $this->crons();
    24     }
    25 
    26     private function crons()
    27     {
    28         remove_action("woocommerce_update_product", __CLASS__ . '::productUpdated');
    29         add_action('woocommerce_update_product', __CLASS__ . '::productUpdated');
    30 
    31         add_action('woocommerce_Ourives_Sync_product', 'OurivesWeb\Plugin::syncProductCron');
    32 
    33 
    34         if ((!wp_next_scheduled('woocommerce_Ourives_Sync_product'))) {
    35             global $wpdb;
    36             $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'Ourives_stock_sync'");
    37 
    38             if ($results[0]->selected == 1) {
    39                 $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'Ourives_stock_sync_time'");
    40 
    41                 if (!empty($results)) {
    42                     $value = $results[0]->selected;
    43                 } else {
    44                     $value = 1000;
    45                 }
    46                 return wp_schedule_single_event(time() + $value, 'woocommerce_Ourives_Sync_product');
    47             }
    48         }
    49 
    50 
    51         add_action('woocommerce_order_status_changed', '\OurivesWeb\Plugin::autoDoc', 10, 3);
    52     }
    53 
    54     public static function defines()
    55     {
    56 
    57         if (isset($_REQUEST['page']) && sanitize_text_field($_REQUEST['page']) == 'OurivesWeb') {
    58             //Wordpress EnQueue Styles
    59             wp_enqueue_style('Bootstrap', plugins_url('assets/Includes/bootstrap.min.css', OURIVES_FILE));
    60             //Wordpress EnQueue JavaScripts
    61             wp_enqueue_script('Bootstrap.min.js', plugins_url('assets/Includes/bootstrap.min.js', OURIVES_FILE));
    62             wp_enqueue_script('bootstrap.bundle.min.js', plugins_url('assets/Includes/bootstrap.bundle.min.js', OURIVES_FILE));
    63         }
    64     }
    65 
    66     public static function productUpdated($product_id)
    67     {
    68         if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
    69             return;
    70         remove_action("woocommerce_update_product", __CLASS__ . "::productUpdated");
    71         update_post_meta(intval($product_id), "date_modified", strtotime("now"));
    72 
    73         add_action('woocommerce_update_product', __CLASS__ . "::productUpdated");
    74         return TRUE;
     24        $this->update();
    7525    }
    7626
     
    173123    }
    174124
    175     private function removeOrder($orderId)
    176     {
    177         $document = new Documents($orderId);
    178         $document->RemoveDocument();
    179     }
    180 
    181     private function createDocument($Soap_Client, $orderId)
    182     {
    183         $document = new Documents($orderId);
    184         $document->createDocument();
    185 
    186         if ($document->document_id) {
    187             $document = Documents::showDocument($Soap_Client, $orderId, "Documento gerado!", "success");
    188             $viewUrl = ' <a href="' . admin_url('admin.php?page=OurivesWeb&action=getInvoice&id=' . $document->document_id) . '" target="_BLANK">Ver documento</a>';
    189             add_settings_error('OurivesWeb', 'OurivesWeb-document-created-success', 'O documento foi gerado!' . $viewUrl, 'updated');
    190         }
    191 
    192         return $document;
     125    public static function defines()
     126    {
     127
     128        if (isset($_REQUEST['page']) && sanitize_text_field($_REQUEST['page']) == 'OurivesWeb') {
     129            //Wordpress EnQueue Styles
     130            wp_enqueue_style('Bootstrap', plugins_url('assets/Includes/bootstrap.min.css', OURIVES_FILE));
     131            //Wordpress EnQueue JavaScripts
     132            wp_enqueue_script('Bootstrap.min.js', plugins_url('assets/Includes/bootstrap.min.js', OURIVES_FILE));
     133            wp_enqueue_script('bootstrap.bundle.min.js', plugins_url('assets/Includes/bootstrap.bundle.min.js', OURIVES_FILE));
     134        }
     135    }
     136
     137    public static function productUpdated($product_id)
     138    {
     139        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
     140            return;
     141        remove_action("woocommerce_update_product", __CLASS__ . "::productUpdated");
     142        update_post_meta(intval($product_id), "date_modified", strtotime("now"));
     143
     144        add_action('woocommerce_update_product', __CLASS__ . "::productUpdated");
     145        return TRUE;
    193146    }
    194147
     
    209162        (new Product())->Update_OurivesWeb_ToWC();
    210163    }
     164
     165    private function crons()
     166    {
     167        remove_action("woocommerce_update_product", __CLASS__ . '::productUpdated');
     168        add_action('woocommerce_update_product', __CLASS__ . '::productUpdated');
     169
     170        add_action('woocommerce_Ourives_Sync_product', 'OurivesWeb\Plugin::syncProductCron');
     171
     172
     173        if ((!wp_next_scheduled('woocommerce_Ourives_Sync_product'))) {
     174            global $wpdb;
     175            $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync'");
     176
     177            if ($results[0]->selected == 1) {
     178                $results = $wpdb->get_results("SELECT selected FROM OurivesWeb_api_config WHERE config = 'ourivesweb_stock_sync_time'");
     179
     180                if (!empty($results)) {
     181                    $value = $results[0]->selected;
     182                } else {
     183                    $value = 1000;
     184                }
     185                return wp_schedule_single_event(time() + $value, 'woocommerce_Ourives_Sync_product');
     186            }
     187        }
     188
     189
     190        add_action('woocommerce_order_status_changed', '\OurivesWeb\Plugin::autoDoc', 10, 3);
     191    }
     192
     193    private function removeOrder($orderId)
     194    {
     195        $document = new Documents($orderId);
     196        $document->RemoveDocument();
     197    }
     198
     199    private function createDocument($Soap_Client, $orderId)
     200    {
     201        $document = new Documents($orderId);
     202        $document->createDocument();
     203
     204        if ($document->document_id) {
     205            $document = Documents::showDocument($Soap_Client, $orderId, "Documento gerado!", "success");
     206            $viewUrl = ' <a href="' . admin_url('admin.php?page=OurivesWeb&action=getInvoice&id=' . $document->document_id) . '" target="_BLANK">Ver documento</a>';
     207            add_settings_error('OurivesWeb', 'OurivesWeb-document-created-success', 'O documento foi gerado!' . $viewUrl, 'updated');
     208        }
     209
     210        return $document;
     211    }
     212
     213    private function update(){
     214        if(OURIVES_VERSION === '1.1.1') {
     215            global $wpdb;
     216            $wpdb->query("UPDATE OurivesWeb_api_config SET config='ourivesweb_stock_sync' WHERE config = 'Ourives_stock_sync'");
     217            $wpdb->query("UPDATE OurivesWeb_api_config SET config='ourivesweb_stock_sync_time' WHERE config = 'Ourives_stock_sync_time'");
     218        }
     219    }
     220
    211221}
  • ourivesweb-api/trunk/src/Views/settings.php

    r2726965 r2742574  
    352352                    </div>
    353353                    <h3 class="border  rounded text-center p-3 mb-3 ">Sincronização Automática</h3>
    354                     <div class="d-block my-3" id="ourivesweb_stock_sync" name='opt[ourivesweb_stock_sync]'>
     354                    <div class="d-block my-3" id="ourivesweb_stock_sync">
    355355
    356356                        <label class="btn btn-primary  btn-block">
    357357                            <?php
    358                             if (defined('PLUGIN_STOCK_SYNC') && PLUGIN_STOCK_SYNC == "1") {
     358                            if (defined('OURIVESWEB_STOCK_SYNC') && OURIVESWEB_STOCK_SYNC == "1") {
    359359                                $ifselectedAuto = "checked";
    360360                                $ifselected = "";
     
    415415                    </style>
    416416
    417                     <div class="d-block my-3" id="ourivesweb_stock_sync_time" name='opt[ourivesweb_stock_sync_time]'>
     417                    <div class="d-block my-3" id="ourivesweb_stock_sync_time">
    418418
    419419                        <label class="slidecontainer">
Note: See TracChangeset for help on using the changeset viewer.