diff --git a/includes/class-siti-stock-admin.php b/includes/class-siti-stock-admin.php
index 4e615a7..4202f63 100644
--- a/includes/class-siti-stock-admin.php
+++ b/includes/class-siti-stock-admin.php
@@ -301,6 +301,7 @@ class Siti_Stock_Admin {
|
|
|
+ |
@@ -327,6 +328,17 @@ class Siti_Stock_Admin {
+
+
+ |
diff --git a/includes/class-siti-stock-supplier-exports.php b/includes/class-siti-stock-supplier-exports.php
index 9f9a3ef..e13f469 100644
--- a/includes/class-siti-stock-supplier-exports.php
+++ b/includes/class-siti-stock-supplier-exports.php
@@ -54,6 +54,7 @@ class Siti_Stock_Supplier_Exports {
* @param string $supplier_key Supplier identifier.
*/
public function run_scheduled_export( $supplier_key ) {
+ $this->schedule_next_supplier_run( $supplier_key );
$this->send_export( $supplier_key );
}
@@ -69,7 +70,12 @@ class Siti_Stock_Supplier_Exports {
continue;
}
- if ( ! wp_next_scheduled( self::CRON_HOOK, array( $key ) ) ) {
+ $scheduled_event = function_exists( 'wp_get_scheduled_event' )
+ ? wp_get_scheduled_event( self::CRON_HOOK, array( $key ) )
+ : false;
+
+ if ( ! $scheduled_event || ! empty( $scheduled_event->schedule ) ) {
+ $this->clear_schedule_for_supplier( $key );
$this->schedule_supplier( $key, $config );
}
}
@@ -116,6 +122,15 @@ class Siti_Stock_Supplier_Exports {
if ( is_wp_error( $result ) ) {
$this->notices->add_notice( $result->get_error_message(), 'error' );
+ } elseif ( ! empty( $result['skipped_empty'] ) ) {
+ $this->notices->add_notice(
+ sprintf(
+ /* translators: %s supplier label */
+ __( 'Geen export verzonden voor %s omdat er geen orders zijn gevonden.', 'siti-stock-plugin' ),
+ isset( $result['label'] ) ? $result['label'] : $supplier_key
+ ),
+ 'info'
+ );
} else {
$this->notices->add_notice(
sprintf(
@@ -227,6 +242,14 @@ class Siti_Stock_Supplier_Exports {
$data = $this->collect_rows_for_supplier( $config['supplier'] );
+ if ( empty( $data['rows'] ) && ! empty( $config['skip_empty'] ) ) {
+ return array(
+ 'label' => $config['supplier'],
+ 'rows' => 0,
+ 'skipped_empty' => true,
+ );
+ }
+
$admin_email = get_option( 'admin_email' );
if ( ! $admin_email || ! is_email( $admin_email ) ) {
return new WP_Error( 'siti_stock_missing_email', __( 'Admin e-mailadres kon niet worden opgehaald.', 'siti-stock-plugin' ) );
@@ -290,6 +313,7 @@ class Siti_Stock_Supplier_Exports {
'supplier' => isset( $config['supplier'] ) ? $config['supplier'] : '',
'time' => $time,
'enabled' => ! empty( $row['enabled'] ),
+ 'skip_empty' => ! empty( $row['skip_empty'] ),
);
}
@@ -456,7 +480,23 @@ class Siti_Stock_Supplier_Exports {
}
$timestamp = $this->calculate_next_timestamp( $config['time'] );
- wp_schedule_event( $timestamp, 'daily', self::CRON_HOOK, array( $supplier_key ) );
+ wp_schedule_single_event( $timestamp, self::CRON_HOOK, array( $supplier_key ) );
+ }
+
+ /**
+ * Schedule the next supplier run using the site's configured timezone.
+ *
+ * @param string $supplier_key Key.
+ */
+ private function schedule_next_supplier_run( $supplier_key ) {
+ $config = $this->get_supplier_config( $supplier_key );
+
+ if ( empty( $config ) || empty( $config['enabled'] ) || empty( $config['time'] ) ) {
+ return;
+ }
+
+ $this->clear_schedule_for_supplier( $supplier_key );
+ $this->schedule_supplier( $supplier_key, $config );
}
/**
@@ -491,6 +531,7 @@ class Siti_Stock_Supplier_Exports {
isset( $existing['time'] ) ? $existing['time'] : $this->get_default_time_for_key( $key )
),
'enabled' => isset( $existing['enabled'] ) ? (bool) $existing['enabled'] : $this->is_default_enabled( $key ),
+ 'skip_empty' => isset( $existing['skip_empty'] ) ? (bool) $existing['skip_empty'] : $this->is_default_skip_empty( $key ),
);
}
@@ -593,26 +634,31 @@ class Siti_Stock_Supplier_Exports {
'label' => 'Orion',
'time' => '09:00',
'enabled' => true,
+ 'skip_empty' => false,
),
'shots' => array(
'label' => 'Shots',
'time' => '10:00',
'enabled' => true,
+ 'skip_empty' => false,
),
'stots' => array(
'label' => 'Stots',
'time' => '10:00',
'enabled' => true,
+ 'skip_empty' => false,
),
'leg-avenue' => array(
'label' => 'Leg Avenue',
'time' => '14:00',
'enabled' => true,
+ 'skip_empty' => false,
),
'oproducts' => array(
'label' => 'Oproducts',
'time' => '13:00',
'enabled' => true,
+ 'skip_empty' => false,
),
);
}
@@ -640,4 +686,16 @@ class Siti_Stock_Supplier_Exports {
return isset( $defaults[ $key ] ) ? (bool) $defaults[ $key ]['enabled'] : false;
}
+
+ /**
+ * Determine default skip-empty state for supplier key.
+ *
+ * @param string $key Supplier key.
+ * @return bool
+ */
+ private function is_default_skip_empty( $key ) {
+ $defaults = $this->get_default_suppliers();
+
+ return isset( $defaults[ $key ] ) ? ! empty( $defaults[ $key ]['skip_empty'] ) : false;
+ }
}
diff --git a/siti-stock-plugin.php b/siti-stock-plugin.php
index d2ee65c..97f656b 100644
--- a/siti-stock-plugin.php
+++ b/siti-stock-plugin.php
@@ -3,7 +3,7 @@
* Plugin Name: Siti Stock Plugin
* Plugin URI: https://github.com/SitiWeb/siti-stock-plugin
* Description: Synchroniseert WooCommerce voorraad met het externe Siti voorraadplatform.
- * Version: 1.2.9
+ * Version: 1.3.0
* Author: Roberto Guagliardo | SitiWeb
* Author URI: https://sitiweb.nl/
* Requires PHP: 8.1