Merge pull request 'fix: Update plugin version to 1.3.0 and add new settings for supplier exports' (#1) from fix/fixed-bug-with-planning-time into master

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2026-04-14 19:59:26 +02:00
3 changed files with 73 additions and 3 deletions

View File

@@ -301,6 +301,7 @@ class Siti_Stock_Admin {
<th><?php esc_html_e( 'Leverancier', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Tijd (24u)', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Automatisch verzenden', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Geen mail zonder orders', 'siti-stock-plugin' ); ?></th>
</tr>
</thead>
<tbody>
@@ -327,6 +328,17 @@ class Siti_Stock_Admin {
<?php esc_html_e( 'Activeer e-mail', 'siti-stock-plugin' ); ?>
</label>
</td>
<td>
<label>
<input
type="checkbox"
name="<?php echo esc_attr( 'supplier_exports[' . $key . '][skip_empty]' ); ?>"
value="1"
<?php checked( ! empty( $config['skip_empty'] ) ); ?>
/>
<?php esc_html_e( 'Sla lege export over', 'siti-stock-plugin' ); ?>
</label>
</td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@@ -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;
}
}

View File

@@ -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