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