|
|
|
|
@@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
|
class Siti_Stock_Supplier_Exports {
|
|
|
|
|
|
|
|
|
|
const CRON_HOOK = 'siti_stock_plugin_supplier_export';
|
|
|
|
|
const SUPPLIER_META_KEY = '_wpbc_supplier';
|
|
|
|
|
const SUPPLIER_META_KEY = '_wpci_supplier';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Siti_Stock_Settings
|
|
|
|
|
@@ -178,7 +178,6 @@ class Siti_Stock_Supplier_Exports {
|
|
|
|
|
? $settings['supplier_exports']
|
|
|
|
|
: array();
|
|
|
|
|
|
|
|
|
|
$configured = $this->ensure_defaults( $configured );
|
|
|
|
|
$configured = $this->ensure_distinct_meta_suppliers( $configured );
|
|
|
|
|
|
|
|
|
|
uasort(
|
|
|
|
|
@@ -240,25 +239,28 @@ class Siti_Stock_Supplier_Exports {
|
|
|
|
|
$config['supplier']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$body_lines = array();
|
|
|
|
|
$body_lines[] = sprintf(
|
|
|
|
|
$rows_count = count( $data['rows'] );
|
|
|
|
|
$body = '';
|
|
|
|
|
$body .= '<p>' . sprintf(
|
|
|
|
|
/* translators: %s supplier name */
|
|
|
|
|
__( 'Overzicht voor leverancier %s.', 'siti-stock-plugin' ),
|
|
|
|
|
$config['supplier']
|
|
|
|
|
);
|
|
|
|
|
$body_lines[] = sprintf(
|
|
|
|
|
esc_html__( 'Overzicht voor leverancier %s.', 'siti-stock-plugin' ),
|
|
|
|
|
esc_html( $config['supplier'] )
|
|
|
|
|
) . '</p>';
|
|
|
|
|
$body .= '<p>' . sprintf(
|
|
|
|
|
/* translators: %d total items */
|
|
|
|
|
__( 'Totaal aantal regels: %d.', 'siti-stock-plugin' ),
|
|
|
|
|
count( $data['rows'] )
|
|
|
|
|
);
|
|
|
|
|
if ( empty( $data['rows'] ) ) {
|
|
|
|
|
$body_lines[] = __( 'Er zijn geen bestellingen gevonden in de afgelopen 24 uur.', 'siti-stock-plugin' );
|
|
|
|
|
}
|
|
|
|
|
$body_lines[] = '';
|
|
|
|
|
$body_lines[] = $csv;
|
|
|
|
|
esc_html__( 'Totaal aantal regels: %d.', 'siti-stock-plugin' ),
|
|
|
|
|
(int) $rows_count
|
|
|
|
|
) . '</p>';
|
|
|
|
|
|
|
|
|
|
$headers = array( 'Content-Type: text/plain; charset=UTF-8' );
|
|
|
|
|
$sent = wp_mail( $admin_email, $subject, implode( "\n", $body_lines ), $headers );
|
|
|
|
|
if ( empty( $data['rows'] ) ) {
|
|
|
|
|
$body .= '<p>' . esc_html__( 'Er zijn geen bestellingen gevonden in de afgelopen 24 uur.', 'siti-stock-plugin' ) . '</p>';
|
|
|
|
|
} else {
|
|
|
|
|
$body .= '<p>' . esc_html__( 'CSV-overzicht (kopieer onderstaande tabel):', 'siti-stock-plugin' ) . '</p>';
|
|
|
|
|
$body .= '<pre style="font-family: monospace; white-space: pre;">' . esc_html( $csv ) . '</pre>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
|
|
|
|
|
$sent = wp_mail( $admin_email, $subject, $body, $headers );
|
|
|
|
|
|
|
|
|
|
if ( ! $sent ) {
|
|
|
|
|
return new WP_Error( 'siti_stock_mail_failed', __( 'E-mail verzenden is mislukt.', 'siti-stock-plugin' ) );
|
|
|
|
|
@@ -439,7 +441,7 @@ class Siti_Stock_Supplier_Exports {
|
|
|
|
|
$lines[] = sprintf( '%s;%d', $sku, $quantity );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return implode( "\n", $lines );
|
|
|
|
|
return implode( "\r\n", $lines );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -471,37 +473,6 @@ class Siti_Stock_Supplier_Exports {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ensure default suppliers exist in config.
|
|
|
|
|
*
|
|
|
|
|
* @param array<string,mixed> $configured Configured values.
|
|
|
|
|
* @return array<string,array<string,mixed>>
|
|
|
|
|
*/
|
|
|
|
|
private function ensure_defaults( array $configured ) {
|
|
|
|
|
foreach ( $this->get_default_suppliers() as $key => $data ) {
|
|
|
|
|
if ( isset( $configured[ $key ] ) ) {
|
|
|
|
|
if ( empty( $configured[ $key ]['supplier'] ) ) {
|
|
|
|
|
$configured[ $key ]['supplier'] = $data['label'];
|
|
|
|
|
}
|
|
|
|
|
$configured[ $key ]['time'] = $this->normalize_time(
|
|
|
|
|
isset( $configured[ $key ]['time'] ) ? $configured[ $key ]['time'] : $data['time']
|
|
|
|
|
);
|
|
|
|
|
if ( ! isset( $configured[ $key ]['enabled'] ) ) {
|
|
|
|
|
$configured[ $key ]['enabled'] = $data['enabled'];
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$configured[ $key ] = array(
|
|
|
|
|
'supplier' => $data['label'],
|
|
|
|
|
'time' => $data['time'],
|
|
|
|
|
'enabled' => $data['enabled'],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $configured;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add entries for suppliers found in product meta.
|
|
|
|
|
*
|
|
|
|
|
@@ -509,22 +480,21 @@ class Siti_Stock_Supplier_Exports {
|
|
|
|
|
* @return array<string,mixed>
|
|
|
|
|
*/
|
|
|
|
|
private function ensure_distinct_meta_suppliers( array $configured ) {
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
|
|
foreach ( $this->get_distinct_suppliers() as $supplier ) {
|
|
|
|
|
$key = $this->normalize_supplier_key( $supplier );
|
|
|
|
|
|
|
|
|
|
if ( isset( $configured[ $key ] ) ) {
|
|
|
|
|
$configured[ $key ]['supplier'] = $supplier;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$configured[ $key ] = array(
|
|
|
|
|
$existing = isset( $configured[ $key ] ) ? $configured[ $key ] : array();
|
|
|
|
|
$result[ $key ] = array(
|
|
|
|
|
'supplier' => $supplier,
|
|
|
|
|
'time' => $this->get_default_time_for_key( $key ),
|
|
|
|
|
'enabled' => $this->is_default_enabled( $key ),
|
|
|
|
|
'time' => $this->normalize_time(
|
|
|
|
|
isset( $existing['time'] ) ? $existing['time'] : $this->get_default_time_for_key( $key )
|
|
|
|
|
),
|
|
|
|
|
'enabled' => isset( $existing['enabled'] ) ? (bool) $existing['enabled'] : $this->is_default_enabled( $key ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $configured;
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|