Merge pull request #15306 from woocommerce/fix/15297

Get external products working in importer/exporter.
This commit is contained in:
Claudiu Lodromanean 2017-05-26 12:45:48 -07:00 committed by GitHub
commit 1d394f41a7
4 changed files with 22 additions and 11 deletions

View File

@ -377,6 +377,8 @@ class WC_Product_CSV_Importer_Controller {
'parent_id',
'upsell_ids',
'cross_sell_ids',
'product_url',
'button_text',
);
return apply_filters( 'woocommerce_csv_product_default_fields', $fields );
@ -426,7 +428,7 @@ class WC_Product_CSV_Importer_Controller {
'parent_id' => __( 'Parent', 'woocommerce' ),
'upsell_ids' => __( 'Upsells', 'woocommerce' ),
'cross_sell_ids' => __( 'Cross-sells', 'woocommerce' ),
'external_url' => __( 'External URL', 'woocommerce' ),
'product_url' => __( 'External URL', 'woocommerce' ),
'button_text' => __( 'Button text', 'woocommerce' ),
) ) );
@ -540,7 +542,7 @@ class WC_Product_CSV_Importer_Controller {
'external' => array(
'name' => __( 'External product', 'woocommerce' ),
'options' => array(
'external_url' => __( 'External URL', 'woocommerce' ),
'product_url' => __( 'External URL', 'woocommerce' ),
'button_text' => __( 'Button text', 'woocommerce' ),
),
),

View File

@ -110,7 +110,8 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
'parent_id' => __( 'Parent', 'woocommerce' ),
'upsell_ids' => __( 'Upsells', 'woocommerce' ),
'cross_sell_ids' => __( 'Cross-sells', 'woocommerce' ),
// @todo product_url button_text
'product_url' => __( 'External URL', 'woocommerce' ),
'button_text' => __( 'Button text', 'woocommerce' ),
);
}

View File

@ -188,6 +188,10 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
$updating = true;
}
if ( 'external' === $object->get_type() ) {
unset( $data['manage_stock'], $data['stock_status'], $data['backorders'] );
}
$result = $object->set_props( array_diff_key( $data, array_flip( array( 'meta_data', 'raw_image_id', 'raw_gallery_image_ids', 'raw_attributes' ) ) ) );
if ( is_wp_error( $result ) ) {

View File

@ -347,7 +347,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
'cross_sell_ids' => array( $this, 'parse_relative_comma_field' ),
'download_limit' => 'absint',
'download_expiry' => 'absint',
'external_url' => 'esc_url_raw',
'product_url' => 'esc_url_raw',
);
/**
@ -408,11 +408,6 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$data['id'] = $product_id;
}
// Manage stock is mapped from the stock_quantity field.
if ( isset( $data['stock_quantity'] ) ) {
$data['manage_stock'] = 0 < $data['stock_quantity'];
}
// Status is mapped from a special published field.
if ( isset( $data['published'] ) ) {
$data['status'] = ( $data['published'] ? 'publish' : 'draft' );
@ -440,9 +435,18 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$data['type'] = current( array_diff( $data['type'], array( 'virtual', 'downloadable' ) ) );
}
if ( isset( $data['stock_quantity'] ) ) {
$data['manage_stock'] = 0 < $data['stock_quantity'];
}
// Stock is bool.
if ( isset( $data['stock_status'] ) ) {
$stock_status = $data['stock_status'] ? 'instock' : 'outofstock';
$data['stock_status'] = $data['stock_status'] ? 'instock' : 'outofstock';
}
// Backorders is bool.
if ( isset( $data['backorders'] ) ) {
$data['backorders'] = $data['backorders'] ? 'yes' : 'no';
}
// Handle special column names which span multiple columns.
@ -615,7 +619,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
if ( is_wp_error( $result ) ) {
$result->add_data( array( 'row' => $this->get_row_id( $parsed_data ) ) );
$data['failed'][] = $result['id'];
$data['failed'][] = $result;
} elseif ( $result['updated'] ) {
$data['updated'][] = $result['id'];
} else {