Merge pull request #16000 from woocommerce/fix/csv-mapping

Change how mapping is posted
This commit is contained in:
Claudiu Lodromanean 2017-07-06 11:37:24 -07:00 committed by GitHub
commit 74d6c2378b
3 changed files with 12 additions and 3 deletions

View File

@ -311,7 +311,8 @@ class WC_Product_CSV_Importer_Controller {
}
if ( ! empty( $_POST['map_to'] ) ) {
$mapping = wp_unslash( $_POST['map_to'] );
$mapping_from = wp_unslash( $_POST['map_from'] );
$mapping_to = wp_unslash( $_POST['map_to'] );
} else {
wp_redirect( esc_url_raw( $this->get_next_step_link( 'upload' ) ) );
exit;
@ -319,7 +320,10 @@ class WC_Product_CSV_Importer_Controller {
wp_localize_script( 'wc-product-import', 'wc_product_import_params', array(
'import_nonce' => wp_create_nonce( 'wc-product-import' ),
'mapping' => $mapping,
'mapping' => array(
'from' => $mapping_from,
'to' => $mapping_to,
),
'file' => $this->file,
'update_existing' => $this->update_existing,
'delimiter' => $this->delimiter,

View File

@ -30,7 +30,8 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php endif; ?>
</td>
<td class="wc-importer-mapping-table-field">
<select name="map_to[<?php echo esc_attr( $name ); ?>]">
<input type="hidden" name="map_from[<?php echo esc_attr( $index ); ?>]" value="<?php echo esc_attr( $name ); ?>" />
<select name="map_to[<?php echo esc_attr( $index ); ?>]">
<option value=""><?php esc_html_e( 'Do not import', 'woocommerce' ); ?></option>
<option value="">--------------</option>
<?php foreach ( $this->get_mapping_options( $mapped_value ) as $key => $value ) : ?>

View File

@ -44,6 +44,10 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$this->params = wp_parse_args( $params, $default_args );
$this->file = $file;
if ( isset( $this->params['mapping']['from'], $this->params['mapping']['to'] ) ) {
$this->params['mapping'] = array_combine( $this->params['mapping']['from'], $this->params['mapping']['to'] );
}
$this->read_file();
}