Merge pull request #16949 from woocommerce/fix/16928
[Importer] Display error message when it's impossible to get a sample of the file
This commit is contained in:
commit
9800d72c82
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -5674,6 +5674,34 @@ table.bar_chart {
|
|||
}
|
||||
}
|
||||
|
||||
.button {
|
||||
font-size: 1.25em;
|
||||
padding: 0.5em 1em !important;
|
||||
line-height: 1.5em !important;
|
||||
margin-right: 0.5em;
|
||||
margin-bottom: 2px;
|
||||
height: auto !important;
|
||||
border-radius: 4px;
|
||||
background-color: #bb77ae;
|
||||
border-color: #a36597;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
text-shadow: 0 -1px 1px #a36597, 1px 0 1px #a36597, 0 1px 1px #a36597, -1px 0 1px #a36597;
|
||||
margin: 0;
|
||||
opacity: 1;
|
||||
|
||||
&:hover, &:focus, &:active {
|
||||
background: #a36597;
|
||||
border-color: #a36597;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
}
|
||||
}
|
||||
|
||||
.error .button {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.wc-actions {
|
||||
overflow: hidden;
|
||||
border-top: 1px solid #eee;
|
||||
|
@ -5683,27 +5711,6 @@ table.bar_chart {
|
|||
|
||||
.button {
|
||||
float: right;
|
||||
font-size: 1.25em;
|
||||
padding: 0.5em 1em !important;
|
||||
line-height: 1.5em !important;
|
||||
margin-right: 0.5em;
|
||||
margin-bottom: 2px;
|
||||
height: auto !important;
|
||||
border-radius: 4px;
|
||||
background-color: #bb77ae;
|
||||
border-color: #a36597;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
text-shadow: 0 -1px 1px #a36597, 1px 0 1px #a36597, 0 1px 1px #a36597, -1px 0 1px #a36597;
|
||||
margin: 0;
|
||||
opacity: 1;
|
||||
|
||||
&:hover, &:focus, &:active {
|
||||
background: #a36597;
|
||||
border-color: #a36597;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 0 #a36597;
|
||||
}
|
||||
}
|
||||
|
||||
.woocommerce-importer-toggle-advanced-options {
|
||||
|
|
|
@ -165,19 +165,37 @@ class WC_Product_CSV_Importer_Controller {
|
|||
|
||||
/**
|
||||
* Add error message.
|
||||
*
|
||||
* @param string $message Error message.
|
||||
* @param array $actions List of actions with 'url' and 'label'.
|
||||
*/
|
||||
protected function add_error( $error ) {
|
||||
$this->errors[] = $error;
|
||||
protected function add_error( $message, $actions = array() ) {
|
||||
$this->errors[] = array(
|
||||
'message' => $message,
|
||||
'actions' => $actions,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add error message.
|
||||
*/
|
||||
protected function output_errors() {
|
||||
if ( $this->errors ) {
|
||||
foreach ( $this->errors as $error ) {
|
||||
echo '<div class="error inline"><p>' . esc_html( $error ) . '</p></div>';
|
||||
if ( ! $this->errors ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $this->errors as $error ) {
|
||||
echo '<div class="error inline">';
|
||||
echo '<p>' . esc_html( $error['message'] ) . '</p>';
|
||||
|
||||
if ( ! empty( $error['actions'] ) ) {
|
||||
echo '<p>';
|
||||
foreach ( $error['actions'] as $action ) {
|
||||
echo '<a class="button button-primary" href="' . esc_url( $action['url'] ) . '">' . esc_html( $action['label'] ) . '</a> ';
|
||||
}
|
||||
echo '</p>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +316,18 @@ class WC_Product_CSV_Importer_Controller {
|
|||
$sample = current( $importer->get_raw_data() );
|
||||
|
||||
if ( empty( $sample ) ) {
|
||||
$this->add_error( __( 'The file is empty, please try again with a new file.', 'woocommerce' ) );
|
||||
$this->add_error(
|
||||
__( 'The file is empty or using a different encoding than UTF-8, please try again with a new file.', 'woocommerce' ),
|
||||
array(
|
||||
array(
|
||||
'url' => admin_url( 'edit.php?post_type=product&page=product_importer' ),
|
||||
'label' => __( 'Upload a new file', 'woocommerce' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Force output the errors in the same page.
|
||||
$this->output_errors();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue