Plugin Directory

Changeset 3331481


Ignore:
Timestamp:
07/21/2025 12:29:27 PM (8 months ago)
Author:
closetechnology
Message:

Update to version 3.1.2 from GitHub

Location:
connect-ecommerce
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • connect-ecommerce/tags/3.1.2/connect-ecommerce.php

    r3329057 r3331481  
    66 * Author: Closetechnology
    77 * Author URI: https://close.technology/
    8  * Version: 3.1.1
     8 * Version: 3.1.2
    99 *
    1010 * @package WordPress
     
    1717defined( 'ABSPATH' ) || exit;
    1818
    19 define( 'CONECOM_VERSION', '3.1.1' );
     19define( 'CONECOM_VERSION', '3.1.2' );
    2020define( 'CONECOM_FILE', __FILE__ );
    2121define( 'CONECOM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     
    6161                'table_sync'                 => $wpdb->prefix . 'sync_conecom-clientify',
    6262                'file'                       => __FILE__,
    63                 'cron'                       => array(
    64                     array(
    65                         'key'      => 'every_five_minutes',
    66                         'interval' => 300,
    67                         'display'  => __( 'Every 5 minutes', 'connect-ecommerce' ),
    68                         'cron'     => 'conecom-clientify_sync_five_minutes',
    69                     ),
    70                     array(
    71                         'key'      => 'every_fifteen_minutes',
    72                         'interval' => 900,
    73                         'display'  => __( 'Every 15 minutes', 'connect-ecommerce' ),
    74                         'cron'     => 'conecom-clientify_sync_fifteen_minutes',
    75                     ),
    76                     array(
    77                         'key'      => 'every_thirty_minutes',
    78                         'interval' => 1800,
    79                         'display'  => __( 'Every 30 Minutes', 'connect-ecommerce' ),
    80                         'cron'     => 'conecom-clientify_sync_thirty_minutes',
    81                     ),
    82                     array(
    83                         'key'      => 'every_one_hour',
    84                         'interval' => 3600,
    85                         'display'  => __( 'Every 1 Hour', 'connect-ecommerce' ),
    86                         'cron'     => 'conecom-clientify_sync_one_hour',
    87                     ),
    88                     array(
    89                         'key'      => 'every_three_hours',
    90                         'interval' => 10800,
    91                         'display'  => __( 'Every 3 Hours', 'connect-ecommerce' ),
    92                         'cron'     => 'conecom-clientify_sync_three_hours',
    93                     ),
    94                     array(
    95                         'key'      => 'every_six_hours',
    96                         'interval' => 21600,
    97                         'display'  => __( 'Every 6 Hours', 'connect-ecommerce' ),
    98                         'cron'     => 'conecom-clientify_sync_six_hours',
    99                     ),
    100                     array(
    101                         'key'      => 'every_twelve_hours',
    102                         'interval' => 43200,
    103                         'display'  => __( 'Every 12 Hours', 'connect-ecommerce' ),
    104                         'cron'     => 'conecom-clientify_sync_twelve_hours',
    105                     ),
    106                 ),
    10763            ],
    10864        ]
  • connect-ecommerce/tags/3.1.2/includes/Admin/Import_Products.php

    r3329057 r3331481  
    292292            return;
    293293        }
    294         $pos = array_search( $this->sync_period, array_column( $this->options['cron'], 'cron' ), true );
    295         if ( false !== $pos ) {
    296             $cron_option = $this->options['cron'][ $pos ];
    297         }
     294        $cron_option = CRON::get_active_period( $this->sync_period );
    298295
    299296        if ( isset( $cron_option['cron'] ) && false === as_has_scheduled_action( $cron_option['cron'] ) ) {
     
    309306    public function cron_sync_products() {
    310307        $is_table_sync = ! empty( $this->options['table_sync'] ) ? true : false;
    311         $products_sync = CRON::get_products_sync( $this->settings, $this->options, $this->connapi_erp );
    312 
    313308        if ( $is_table_sync ) {
    314309            HELPER::check_table_sync( $this->options['table_sync'] );
    315         }
    316 
     310        } else {
     311            // Check if the API method exists.
     312            if ( ! method_exists( $this->connapi_erp, 'get_products_ids_since' ) ) {
     313                return;
     314            }
     315        }
     316
     317        // Get products to sync.
     318        $products_sync = CRON::get_products_sync( $this->settings, $this->options, $this->connapi_erp );
    317319        if ( empty( $products_sync ) && $is_table_sync ) {
    318320            CRON::send_sync_ended_products( $this->settings, $this->options['table_sync'], $this->options['name'], $this->options['slug'] );
    319             CRON::fill_table_sync( $this->settings, $this->options['table_sync'], $this->connapi_erp, $this->options['slug'] );
    320         } elseif ( ! empty( $products_sync ) ) {
     321            CRON::fill_table_sync( $this->settings, $this->options, $this->connapi_erp );
     322            $products_sync = CRON::get_products_sync( $this->settings, $this->options, $this->connapi_erp );
     323        }
     324        if ( ! empty( $products_sync ) ) {
    321325            foreach ( $products_sync as $product_sync ) {
    322326                $product_id = isset( $product_sync['prod_id'] ) ? $product_sync['prod_id'] : $product_sync;
  • connect-ecommerce/tags/3.1.2/includes/Admin/Settings.php

    r3301423 r3331481  
    1717use CLOSE\ConnectEcommerce\Helpers\HELPER;
    1818use CLOSE\ConnectEcommerce\Helpers\AI;
     19use CLOSE\ConnectEcommerce\Helpers\CRON;
    1920
    2021/**
     
    14651466            <option value="no" <?php selected( $sync, 'no' ); ?>><?php esc_html_e( 'No', 'connect-ecommerce' ); ?></option>
    14661467            <?php
    1467             if ( ! empty( $this->options['cron'] ) ) {
    1468                 foreach ( $this->options['cron'] as $cron_option ) {
    1469                     echo '<option value="' . esc_html( $cron_option['cron'] ) . '" ';
    1470                     selected( $sync, $cron_option['cron'] );
    1471                     echo '>' . esc_html( $cron_option['display'] ) . '</option>';
     1468            $periods = CRON::get_cron_periods();
     1469            if ( ! empty( $periods ) ) {
     1470                foreach ( $periods as $period ) {
     1471                    echo '<option value="' . esc_html( $period['cron'] ) . '" ';
     1472                    selected( $sync, $period['cron'] );
     1473                    echo '>' . esc_html( $period['display'] ) . '</option>';
    14721474                }
    14731475            }
  • connect-ecommerce/tags/3.1.2/includes/Helpers/CRON.php

    r3281293 r3331481  
    4848     * @return boolean
    4949     */
    50     public static function fill_table_sync( $settings, $table_sync, $api_erp, $option_prefix ) {
    51         global $wpdb;
     50    public static function fill_table_sync( $settings, $options, $api_erp ) {
     51        global $wpdb;
     52        $table_sync = isset( $options['table_sync'] ) ? $options['table_sync'] : '';
     53        if ( empty( $table_sync ) ) {
     54            return false;
     55        }
    5256        $wpdb->query( "TRUNCATE TABLE $table_sync;" );
    5357
    54         // Get products from API.
    55         $products = $api_erp->get_products();
     58        // Get ALL products from API.
     59        $products       = array();
     60        $api_pagination = ! empty( $options['api_pagination'] ) ? (int) $options['api_pagination'] : false;
     61        if ( $api_pagination ) {
     62            $sync_loop = 0;
     63
     64            do {
     65                $loop_page    = $sync_loop * $api_pagination;
     66                $api_products = $api_erp->get_products( null, $loop_page );
     67                if ( empty( $api_products ) ) {
     68                    break;
     69                }
     70                $sync_loop++;
     71                $count_products = count( $api_products );
     72                $products       = array_merge( $products, $api_products );
     73            } while ( $count_products === $api_pagination );
     74
     75        } else {
     76            $products = $api_erp->get_products();
     77        }
     78           
    5679        if ( ! is_array( $products ) ) {
    5780            return;
    5881        }
    5982
    60         update_option( $option_prefix . '_total_api_products', count( $products ) );
    61         update_option( $option_prefix . '_sync_start_time', strtotime( 'now' ) );
    62         update_option( $option_prefix . '_sync_errors', array() );
     83        update_option( 'conecom_total_api_products', count( $products ) );
     84        update_option( 'conecom_sync_start_time', strtotime( 'now' ) );
     85        update_option( 'conecom_sync_errors', array() );
    6386
    6487        foreach ( $products as $product ) {
     
    93116        // Method with modified products.
    94117        if ( empty( $table_sync ) ) {
    95             $sync_period = isset( $settings['sync'] ) ? strval( $settings['sync'] ) : 'no';
    96             $pos         = array_search( $sync_period, array_column( $options['cron'], 'cron' ), true );
    97             if ( false !== $pos ) {
    98                 $cron_option = $options['cron'][ $pos ];
    99             }
    100             $modified_since_date = isset( $cron_option['interval'] ) ? strtotime( '-' . $cron_option['interval'] . ' seconds' ) : strtotime( '-1 day' );
     118            $period              = self::get_active_period( $settings );
     119            $modified_since_date = isset( $period['interval'] ) ? strtotime( '-' . $period['interval'] . ' seconds' ) : strtotime( '-1 day' );
    101120            if ( ! method_exists( $connapi_erp, 'get_products_ids_since' ) ) {
    102121                return false;
     
    106125        // Method with table sync.
    107126        global $wpdb;
    108         $limit = isset( $settings['sync_num'] ) ? $settings['sync_num'] : 5;
     127        $limit = isset( $settings['sync_num'] ) ? (int) $settings['sync_num'] : 50;
    109128
    110129        $results = $wpdb->get_results(
    111130            $wpdb->prepare(
    112                 'SELECT prod_id FROM %i WHERE synced = 0 LIMIT %s',
     131                'SELECT prod_id FROM %i WHERE synced = 0 LIMIT %d',
    113132                $table_sync,
    114133                $limit
     
    248267        }
    249268    }
     269
     270    /**
     271     * Returns the active period for sync.
     272     *
     273     * @param array $settings|value Settings of plugin or period.
     274     *
     275     * @return array|false
     276     */
     277    public static function get_active_period( $sync_period ) {
     278        $sync_period = is_array( $sync_period ) ? $sync_period['sync'] : $sync_period;
     279
     280        if ( 'no' === $sync_period ) {
     281            return false;
     282        }
     283        $periods     = self::get_cron_periods();
     284        $pos         = array_search( $sync_period, array_column( $periods, 'cron' ), true );
     285
     286        return false !== $pos ? $periods[ $pos ] : end( $periods );
     287    }
     288
     289    /**
     290     * Returns the cron periods.
     291     *
     292     * @return array
     293     */
     294    public static function get_cron_periods() {
     295        return array(
     296            array(
     297                'key'      => 'every_five_minutes',
     298                'interval' => 300,
     299                'display'  => __( 'Every 5 minutes', 'connect-ecommerce' ),
     300                'cron'     => 'conecom_sync_five_minutes',
     301            ),
     302            array(
     303                'key'      => 'every_fifteen_minutes',
     304                'interval' => 900,
     305                'display'  => __( 'Every 15 minutes', 'connect-ecommerce' ),
     306                'cron'     => 'conecom_sync_fifteen_minutes',
     307            ),
     308            array(
     309                'key'      => 'every_thirty_minutes',
     310                'interval' => 1800,
     311                'display'  => __( 'Every 30 Minutes', 'connect-ecommerce' ),
     312                'cron'     => 'conecom_sync_thirty_minutes',
     313            ),
     314            array(
     315                'key'      => 'every_one_hour',
     316                'interval' => 3600,
     317                'display'  => __( 'Every 1 Hour', 'connect-ecommerce' ),
     318                'cron'     => 'conecom_sync_one_hour',
     319            ),
     320            array(
     321                'key'      => 'every_three_hours',
     322                'interval' => 10800,
     323                'display'  => __( 'Every 3 Hours', 'connect-ecommerce' ),
     324                'cron'     => 'conecom_sync_three_hours',
     325            ),
     326            array(
     327                'key'      => 'every_six_hours',
     328                'interval' => 21600,
     329                'display'  => __( 'Every 6 Hours', 'connect-ecommerce' ),
     330                'cron'     => 'conecom_sync_six_hours',
     331            ),
     332            array(
     333                'key'      => 'every_twelve_hours',
     334                'interval' => 43200,
     335                'display'  => __( 'Every 12 Hours', 'connect-ecommerce' ),
     336                'cron'     => 'conecom_sync_twelve_hours',
     337            ),
     338        );
     339    }
    250340}
  • connect-ecommerce/tags/3.1.2/includes/Helpers/PROD.php

    r3329057 r3331481  
    576576            $variation->set_props( $variation_props );
    577577            // Stock.
    578             if ( ! empty( $variant['stock'] ) ) {
    579                 $variation->set_stock_quantity( $variant['stock'] );
     578            if ( isset( $variant['stock'] ) ) {
     579                $stock_status = 0 === (int) $variant['stock'] ? 'outofstock' : 'instock';
     580                $variation->set_stock_quantity( (int) $variant['stock'] );
    580581                $variation->set_manage_stock( true );
    581                 $variation->set_stock_status( 'instock' );
     582                $variation->set_stock_status( $stock_status );
    582583            } else {
    583584                $variation->set_manage_stock( false );
     
    10881089    }
    10891090
     1091
     1092
    10901093    /**
    10911094     * Get attribute category ID
     
    10961099     */
    10971100    private static function get_rate_price( $item, $rate_id ) {
     1101        $price = null;
     1102
    10981103        if ( empty( $item ) ) {
    1099             return null;
    1100         }
     1104            return $price;
     1105        }
     1106
    11011107        if ( 'default' === $rate_id || '' === $rate_id || empty( $item['rates'] ) || ! is_array( $item['rates'] ) ) {
    1102             return isset( $item['price'] ) ? $item['price'] : null;
     1108            $price = isset( $item['price'] ) ? $item['price'] : null;
    11031109        } else {
    11041110            $price_key = array_search( $rate_id, array_column( $item['rates'], 'id' ) );
    1105             return isset( $item['rates'][ $price_key ]['subtotal'] ) ? $item['rates'][ $price_key ]['subtotal'] : null;
    1106         }
     1111            $price     = isset( $item['rates'][ $price_key ]['subtotal'] ) ? $item['rates'][ $price_key ]['subtotal'] : null;
     1112            $price     = empty( $price ) && isset( $item['rates'][ $rate_id ]['subtotal'] ) ? $item['rates'][ $rate_id ]['subtotal'] : $price;
     1113        }
     1114        return (float) $price;
    11071115    }
    11081116
  • connect-ecommerce/tags/3.1.2/readme.txt

    r3329057 r3331481  
    66Requires PHP: 7.0
    77Tested up to: 6.8
    8 Stable tag: 3.1.1
    9 Version: 3.1.1
     8Stable tag: 3.1.2
     9Version: 3.1.2
    1010License: GPL2
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3737- [NEO TPV](https://close.technology/en/wordpress-plugins/connect-woocommerce-neo/)
    3838
     39== Frequently Asked Questions ==
     40
     41= What does this plugin do? =
     42Connect Ecommerce allows you to import products from a ERP/CRM via API with your WooCommerce store.
     43
     44= How are products and orders synchronized? =
     45Products are synchronized from the ERP/CRM to WooCommerce. This is because the ERP should always contain the most up-to-date information about your business. It is the correct source for managing products, pricing, and commercial data.
     46
     47Orders are synchronized from WooCommerce to the ERP/CRM. This ensures that every time a customer places an order, it is sent to your ERP for proper order and invoice management.
     48
     49= What happens when a simple product is out of stock? =
     50The default behavior is that the product disappears from the store catalog, but it remains visible to search engines. This is intentional and matches the expected behavior of the shop.
    3951
    4052== Installation ==
     
    6476
    6577== Changelog ==
     78
     79= 3.1.2 =
     80* Fixed: Getting prices rates from variation products.
     81* Fixed: Zero stock in variation products was giving not manage stock.
     82* Fixed: Automated products sync not working properly.
    6683
    6784= 3.1.1 =
  • connect-ecommerce/tags/3.1.2/vendor/composer/installed.php

    r3329057 r3331481  
    22    'root' => array(
    33        'name' => 'closemarketing/connect-ecommerce',
    4         'pretty_version' => '3.1.1',
    5         'version' => '3.1.1.0',
    6         'reference' => '3600b8f8ac4196bfd7f881d9f386cfd3d10ebb01',
     4        'pretty_version' => '3.1.2',
     5        'version' => '3.1.2.0',
     6        'reference' => 'fbf4de2acf91f556373c907e1880a7612681101a',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'closemarketing/connect-ecommerce' => array(
    14             'pretty_version' => '3.1.1',
    15             'version' => '3.1.1.0',
    16             'reference' => '3600b8f8ac4196bfd7f881d9f386cfd3d10ebb01',
     14            'pretty_version' => '3.1.2',
     15            'version' => '3.1.2.0',
     16            'reference' => 'fbf4de2acf91f556373c907e1880a7612681101a',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • connect-ecommerce/trunk/connect-ecommerce.php

    r3329057 r3331481  
    66 * Author: Closetechnology
    77 * Author URI: https://close.technology/
    8  * Version: 3.1.1
     8 * Version: 3.1.2
    99 *
    1010 * @package WordPress
     
    1717defined( 'ABSPATH' ) || exit;
    1818
    19 define( 'CONECOM_VERSION', '3.1.1' );
     19define( 'CONECOM_VERSION', '3.1.2' );
    2020define( 'CONECOM_FILE', __FILE__ );
    2121define( 'CONECOM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     
    6161                'table_sync'                 => $wpdb->prefix . 'sync_conecom-clientify',
    6262                'file'                       => __FILE__,
    63                 'cron'                       => array(
    64                     array(
    65                         'key'      => 'every_five_minutes',
    66                         'interval' => 300,
    67                         'display'  => __( 'Every 5 minutes', 'connect-ecommerce' ),
    68                         'cron'     => 'conecom-clientify_sync_five_minutes',
    69                     ),
    70                     array(
    71                         'key'      => 'every_fifteen_minutes',
    72                         'interval' => 900,
    73                         'display'  => __( 'Every 15 minutes', 'connect-ecommerce' ),
    74                         'cron'     => 'conecom-clientify_sync_fifteen_minutes',
    75                     ),
    76                     array(
    77                         'key'      => 'every_thirty_minutes',
    78                         'interval' => 1800,
    79                         'display'  => __( 'Every 30 Minutes', 'connect-ecommerce' ),
    80                         'cron'     => 'conecom-clientify_sync_thirty_minutes',
    81                     ),
    82                     array(
    83                         'key'      => 'every_one_hour',
    84                         'interval' => 3600,
    85                         'display'  => __( 'Every 1 Hour', 'connect-ecommerce' ),
    86                         'cron'     => 'conecom-clientify_sync_one_hour',
    87                     ),
    88                     array(
    89                         'key'      => 'every_three_hours',
    90                         'interval' => 10800,
    91                         'display'  => __( 'Every 3 Hours', 'connect-ecommerce' ),
    92                         'cron'     => 'conecom-clientify_sync_three_hours',
    93                     ),
    94                     array(
    95                         'key'      => 'every_six_hours',
    96                         'interval' => 21600,
    97                         'display'  => __( 'Every 6 Hours', 'connect-ecommerce' ),
    98                         'cron'     => 'conecom-clientify_sync_six_hours',
    99                     ),
    100                     array(
    101                         'key'      => 'every_twelve_hours',
    102                         'interval' => 43200,
    103                         'display'  => __( 'Every 12 Hours', 'connect-ecommerce' ),
    104                         'cron'     => 'conecom-clientify_sync_twelve_hours',
    105                     ),
    106                 ),
    10763            ],
    10864        ]
  • connect-ecommerce/trunk/includes/Admin/Import_Products.php

    r3329057 r3331481  
    292292            return;
    293293        }
    294         $pos = array_search( $this->sync_period, array_column( $this->options['cron'], 'cron' ), true );
    295         if ( false !== $pos ) {
    296             $cron_option = $this->options['cron'][ $pos ];
    297         }
     294        $cron_option = CRON::get_active_period( $this->sync_period );
    298295
    299296        if ( isset( $cron_option['cron'] ) && false === as_has_scheduled_action( $cron_option['cron'] ) ) {
     
    309306    public function cron_sync_products() {
    310307        $is_table_sync = ! empty( $this->options['table_sync'] ) ? true : false;
    311         $products_sync = CRON::get_products_sync( $this->settings, $this->options, $this->connapi_erp );
    312 
    313308        if ( $is_table_sync ) {
    314309            HELPER::check_table_sync( $this->options['table_sync'] );
    315         }
    316 
     310        } else {
     311            // Check if the API method exists.
     312            if ( ! method_exists( $this->connapi_erp, 'get_products_ids_since' ) ) {
     313                return;
     314            }
     315        }
     316
     317        // Get products to sync.
     318        $products_sync = CRON::get_products_sync( $this->settings, $this->options, $this->connapi_erp );
    317319        if ( empty( $products_sync ) && $is_table_sync ) {
    318320            CRON::send_sync_ended_products( $this->settings, $this->options['table_sync'], $this->options['name'], $this->options['slug'] );
    319             CRON::fill_table_sync( $this->settings, $this->options['table_sync'], $this->connapi_erp, $this->options['slug'] );
    320         } elseif ( ! empty( $products_sync ) ) {
     321            CRON::fill_table_sync( $this->settings, $this->options, $this->connapi_erp );
     322            $products_sync = CRON::get_products_sync( $this->settings, $this->options, $this->connapi_erp );
     323        }
     324        if ( ! empty( $products_sync ) ) {
    321325            foreach ( $products_sync as $product_sync ) {
    322326                $product_id = isset( $product_sync['prod_id'] ) ? $product_sync['prod_id'] : $product_sync;
  • connect-ecommerce/trunk/includes/Admin/Settings.php

    r3301423 r3331481  
    1717use CLOSE\ConnectEcommerce\Helpers\HELPER;
    1818use CLOSE\ConnectEcommerce\Helpers\AI;
     19use CLOSE\ConnectEcommerce\Helpers\CRON;
    1920
    2021/**
     
    14651466            <option value="no" <?php selected( $sync, 'no' ); ?>><?php esc_html_e( 'No', 'connect-ecommerce' ); ?></option>
    14661467            <?php
    1467             if ( ! empty( $this->options['cron'] ) ) {
    1468                 foreach ( $this->options['cron'] as $cron_option ) {
    1469                     echo '<option value="' . esc_html( $cron_option['cron'] ) . '" ';
    1470                     selected( $sync, $cron_option['cron'] );
    1471                     echo '>' . esc_html( $cron_option['display'] ) . '</option>';
     1468            $periods = CRON::get_cron_periods();
     1469            if ( ! empty( $periods ) ) {
     1470                foreach ( $periods as $period ) {
     1471                    echo '<option value="' . esc_html( $period['cron'] ) . '" ';
     1472                    selected( $sync, $period['cron'] );
     1473                    echo '>' . esc_html( $period['display'] ) . '</option>';
    14721474                }
    14731475            }
  • connect-ecommerce/trunk/includes/Helpers/CRON.php

    r3281293 r3331481  
    4848     * @return boolean
    4949     */
    50     public static function fill_table_sync( $settings, $table_sync, $api_erp, $option_prefix ) {
    51         global $wpdb;
     50    public static function fill_table_sync( $settings, $options, $api_erp ) {
     51        global $wpdb;
     52        $table_sync = isset( $options['table_sync'] ) ? $options['table_sync'] : '';
     53        if ( empty( $table_sync ) ) {
     54            return false;
     55        }
    5256        $wpdb->query( "TRUNCATE TABLE $table_sync;" );
    5357
    54         // Get products from API.
    55         $products = $api_erp->get_products();
     58        // Get ALL products from API.
     59        $products       = array();
     60        $api_pagination = ! empty( $options['api_pagination'] ) ? (int) $options['api_pagination'] : false;
     61        if ( $api_pagination ) {
     62            $sync_loop = 0;
     63
     64            do {
     65                $loop_page    = $sync_loop * $api_pagination;
     66                $api_products = $api_erp->get_products( null, $loop_page );
     67                if ( empty( $api_products ) ) {
     68                    break;
     69                }
     70                $sync_loop++;
     71                $count_products = count( $api_products );
     72                $products       = array_merge( $products, $api_products );
     73            } while ( $count_products === $api_pagination );
     74
     75        } else {
     76            $products = $api_erp->get_products();
     77        }
     78           
    5679        if ( ! is_array( $products ) ) {
    5780            return;
    5881        }
    5982
    60         update_option( $option_prefix . '_total_api_products', count( $products ) );
    61         update_option( $option_prefix . '_sync_start_time', strtotime( 'now' ) );
    62         update_option( $option_prefix . '_sync_errors', array() );
     83        update_option( 'conecom_total_api_products', count( $products ) );
     84        update_option( 'conecom_sync_start_time', strtotime( 'now' ) );
     85        update_option( 'conecom_sync_errors', array() );
    6386
    6487        foreach ( $products as $product ) {
     
    93116        // Method with modified products.
    94117        if ( empty( $table_sync ) ) {
    95             $sync_period = isset( $settings['sync'] ) ? strval( $settings['sync'] ) : 'no';
    96             $pos         = array_search( $sync_period, array_column( $options['cron'], 'cron' ), true );
    97             if ( false !== $pos ) {
    98                 $cron_option = $options['cron'][ $pos ];
    99             }
    100             $modified_since_date = isset( $cron_option['interval'] ) ? strtotime( '-' . $cron_option['interval'] . ' seconds' ) : strtotime( '-1 day' );
     118            $period              = self::get_active_period( $settings );
     119            $modified_since_date = isset( $period['interval'] ) ? strtotime( '-' . $period['interval'] . ' seconds' ) : strtotime( '-1 day' );
    101120            if ( ! method_exists( $connapi_erp, 'get_products_ids_since' ) ) {
    102121                return false;
     
    106125        // Method with table sync.
    107126        global $wpdb;
    108         $limit = isset( $settings['sync_num'] ) ? $settings['sync_num'] : 5;
     127        $limit = isset( $settings['sync_num'] ) ? (int) $settings['sync_num'] : 50;
    109128
    110129        $results = $wpdb->get_results(
    111130            $wpdb->prepare(
    112                 'SELECT prod_id FROM %i WHERE synced = 0 LIMIT %s',
     131                'SELECT prod_id FROM %i WHERE synced = 0 LIMIT %d',
    113132                $table_sync,
    114133                $limit
     
    248267        }
    249268    }
     269
     270    /**
     271     * Returns the active period for sync.
     272     *
     273     * @param array $settings|value Settings of plugin or period.
     274     *
     275     * @return array|false
     276     */
     277    public static function get_active_period( $sync_period ) {
     278        $sync_period = is_array( $sync_period ) ? $sync_period['sync'] : $sync_period;
     279
     280        if ( 'no' === $sync_period ) {
     281            return false;
     282        }
     283        $periods     = self::get_cron_periods();
     284        $pos         = array_search( $sync_period, array_column( $periods, 'cron' ), true );
     285
     286        return false !== $pos ? $periods[ $pos ] : end( $periods );
     287    }
     288
     289    /**
     290     * Returns the cron periods.
     291     *
     292     * @return array
     293     */
     294    public static function get_cron_periods() {
     295        return array(
     296            array(
     297                'key'      => 'every_five_minutes',
     298                'interval' => 300,
     299                'display'  => __( 'Every 5 minutes', 'connect-ecommerce' ),
     300                'cron'     => 'conecom_sync_five_minutes',
     301            ),
     302            array(
     303                'key'      => 'every_fifteen_minutes',
     304                'interval' => 900,
     305                'display'  => __( 'Every 15 minutes', 'connect-ecommerce' ),
     306                'cron'     => 'conecom_sync_fifteen_minutes',
     307            ),
     308            array(
     309                'key'      => 'every_thirty_minutes',
     310                'interval' => 1800,
     311                'display'  => __( 'Every 30 Minutes', 'connect-ecommerce' ),
     312                'cron'     => 'conecom_sync_thirty_minutes',
     313            ),
     314            array(
     315                'key'      => 'every_one_hour',
     316                'interval' => 3600,
     317                'display'  => __( 'Every 1 Hour', 'connect-ecommerce' ),
     318                'cron'     => 'conecom_sync_one_hour',
     319            ),
     320            array(
     321                'key'      => 'every_three_hours',
     322                'interval' => 10800,
     323                'display'  => __( 'Every 3 Hours', 'connect-ecommerce' ),
     324                'cron'     => 'conecom_sync_three_hours',
     325            ),
     326            array(
     327                'key'      => 'every_six_hours',
     328                'interval' => 21600,
     329                'display'  => __( 'Every 6 Hours', 'connect-ecommerce' ),
     330                'cron'     => 'conecom_sync_six_hours',
     331            ),
     332            array(
     333                'key'      => 'every_twelve_hours',
     334                'interval' => 43200,
     335                'display'  => __( 'Every 12 Hours', 'connect-ecommerce' ),
     336                'cron'     => 'conecom_sync_twelve_hours',
     337            ),
     338        );
     339    }
    250340}
  • connect-ecommerce/trunk/includes/Helpers/PROD.php

    r3329057 r3331481  
    576576            $variation->set_props( $variation_props );
    577577            // Stock.
    578             if ( ! empty( $variant['stock'] ) ) {
    579                 $variation->set_stock_quantity( $variant['stock'] );
     578            if ( isset( $variant['stock'] ) ) {
     579                $stock_status = 0 === (int) $variant['stock'] ? 'outofstock' : 'instock';
     580                $variation->set_stock_quantity( (int) $variant['stock'] );
    580581                $variation->set_manage_stock( true );
    581                 $variation->set_stock_status( 'instock' );
     582                $variation->set_stock_status( $stock_status );
    582583            } else {
    583584                $variation->set_manage_stock( false );
     
    10881089    }
    10891090
     1091
     1092
    10901093    /**
    10911094     * Get attribute category ID
     
    10961099     */
    10971100    private static function get_rate_price( $item, $rate_id ) {
     1101        $price = null;
     1102
    10981103        if ( empty( $item ) ) {
    1099             return null;
    1100         }
     1104            return $price;
     1105        }
     1106
    11011107        if ( 'default' === $rate_id || '' === $rate_id || empty( $item['rates'] ) || ! is_array( $item['rates'] ) ) {
    1102             return isset( $item['price'] ) ? $item['price'] : null;
     1108            $price = isset( $item['price'] ) ? $item['price'] : null;
    11031109        } else {
    11041110            $price_key = array_search( $rate_id, array_column( $item['rates'], 'id' ) );
    1105             return isset( $item['rates'][ $price_key ]['subtotal'] ) ? $item['rates'][ $price_key ]['subtotal'] : null;
    1106         }
     1111            $price     = isset( $item['rates'][ $price_key ]['subtotal'] ) ? $item['rates'][ $price_key ]['subtotal'] : null;
     1112            $price     = empty( $price ) && isset( $item['rates'][ $rate_id ]['subtotal'] ) ? $item['rates'][ $rate_id ]['subtotal'] : $price;
     1113        }
     1114        return (float) $price;
    11071115    }
    11081116
  • connect-ecommerce/trunk/readme.txt

    r3329057 r3331481  
    66Requires PHP: 7.0
    77Tested up to: 6.8
    8 Stable tag: 3.1.1
    9 Version: 3.1.1
     8Stable tag: 3.1.2
     9Version: 3.1.2
    1010License: GPL2
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3737- [NEO TPV](https://close.technology/en/wordpress-plugins/connect-woocommerce-neo/)
    3838
     39== Frequently Asked Questions ==
     40
     41= What does this plugin do? =
     42Connect Ecommerce allows you to import products from a ERP/CRM via API with your WooCommerce store.
     43
     44= How are products and orders synchronized? =
     45Products are synchronized from the ERP/CRM to WooCommerce. This is because the ERP should always contain the most up-to-date information about your business. It is the correct source for managing products, pricing, and commercial data.
     46
     47Orders are synchronized from WooCommerce to the ERP/CRM. This ensures that every time a customer places an order, it is sent to your ERP for proper order and invoice management.
     48
     49= What happens when a simple product is out of stock? =
     50The default behavior is that the product disappears from the store catalog, but it remains visible to search engines. This is intentional and matches the expected behavior of the shop.
    3951
    4052== Installation ==
     
    6476
    6577== Changelog ==
     78
     79= 3.1.2 =
     80* Fixed: Getting prices rates from variation products.
     81* Fixed: Zero stock in variation products was giving not manage stock.
     82* Fixed: Automated products sync not working properly.
    6683
    6784= 3.1.1 =
  • connect-ecommerce/trunk/vendor/composer/installed.php

    r3329057 r3331481  
    22    'root' => array(
    33        'name' => 'closemarketing/connect-ecommerce',
    4         'pretty_version' => '3.1.1',
    5         'version' => '3.1.1.0',
    6         'reference' => '3600b8f8ac4196bfd7f881d9f386cfd3d10ebb01',
     4        'pretty_version' => '3.1.2',
     5        'version' => '3.1.2.0',
     6        'reference' => 'fbf4de2acf91f556373c907e1880a7612681101a',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'closemarketing/connect-ecommerce' => array(
    14             'pretty_version' => '3.1.1',
    15             'version' => '3.1.1.0',
    16             'reference' => '3600b8f8ac4196bfd7f881d9f386cfd3d10ebb01',
     14            'pretty_version' => '3.1.2',
     15            'version' => '3.1.2.0',
     16            'reference' => 'fbf4de2acf91f556373c907e1880a7612681101a',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.