Merge branch 'refactor/fix-importer-and-improve-unit-tests' into feature/product-csv-import-export

This commit is contained in:
Mike Jolley 2017-05-31 12:20:46 +01:00
commit 714fafbb28
6 changed files with 559 additions and 117 deletions

View File

@ -414,9 +414,10 @@ class WC_Product_CSV_Importer_Controller {
__( 'Description', 'woocommerce' ) => 'description',
__( 'Date sale price starts', 'woocommerce' ) => 'date_on_sale_from',
__( 'Date sale price ends', 'woocommerce' ) => 'date_on_sale_to',
__( 'Tax class', 'woocommerce' ) => 'tax_status',
__( 'Tax status', 'woocommerce' ) => 'tax_status',
__( 'Tax class', 'woocommerce' ) => 'tax_class',
__( 'In stock?', 'woocommerce' ) => 'stock_status',
__( 'Stock', 'woocommerce' ) => 'stock',
__( 'Stock', 'woocommerce' ) => 'stock_quantity',
__( 'Backorders allowed?', 'woocommerce' ) => 'backorders',
__( 'Sold individually?', 'woocommerce' ) => 'sold_individually',
sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight',
@ -430,13 +431,13 @@ class WC_Product_CSV_Importer_Controller {
__( 'Categories', 'woocommerce' ) => 'category_ids',
__( 'Tags', 'woocommerce' ) => 'tag_ids',
__( 'Shipping class', 'woocommerce' ) => 'shipping_class_id',
__( 'Images', 'woocommerce' ) => 'image_id',
__( 'Images', 'woocommerce' ) => 'images',
__( 'Download limit', 'woocommerce' ) => 'download_limit',
__( 'Download expiry days', 'woocommerce' ) => 'download_expiry',
__( 'Parent', 'woocommerce' ) => 'parent_id',
__( 'Grouped products', 'woocommerce' ) => 'grouped_products',
__( 'Upsells', 'woocommerce' ) => 'upsell_ids',
__( 'Cross-sells', 'woocommerce' ) => 'cross_sell_ids',
__( 'Grouped products', 'woocommerce' ) => 'grouped_products',
__( 'External URL', 'woocommerce' ) => 'product_url',
__( 'Button text', 'woocommerce' ) => 'button_text',
) );
@ -541,15 +542,15 @@ class WC_Product_CSV_Importer_Controller {
'purchase_note' => __( 'Purchase note', 'woocommerce' ),
'sale_price' => __( 'Sale price', 'woocommerce' ),
'regular_price' => __( 'Regular Price', 'woocommerce' ),
'stock' => __( 'Stock', 'woocommerce' ),
'stock_quantity' => __( 'Stock', 'woocommerce' ),
'category_ids' => __( 'Categories', 'woocommerce' ),
'tag_ids' => __( 'Tags', 'woocommerce' ),
'shipping_class_id' => __( 'Shipping class', 'woocommerce' ),
'image_id' => __( 'Images', 'woocommerce' ),
'images' => __( 'Images', 'woocommerce' ),
'parent_id' => __( 'Parent', 'woocommerce' ),
'grouped_products' => __( 'Grouped products', 'woocommerce' ),
'upsell_ids' => __( 'Upsells', 'woocommerce' ),
'cross_sell_ids' => __( 'Cross-sells', 'woocommerce' ),
'grouped_products' => __( 'Grouped products', 'woocommerce' ),
'external' => array(
'name' => __( 'External product', 'woocommerce' ),
'options' => array(

View File

@ -17,7 +17,7 @@ function wc_importer_generic_mappings( $mappings ) {
__( 'Product Title', 'woocommerce' ) => 'name',
__( 'Price', 'woocommerce' ) => 'regular_price',
__( 'Parent SKU', 'woocommerce' ) => 'parent_id',
__( 'Quantity', 'woocommerce' ) => 'stock',
__( 'Quantity', 'woocommerce' ) => 'stock_quantity',
);
return array_merge( $mappings, $generic_mappings );

View File

@ -134,7 +134,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
/**
* Prepare a single product for create or update.
*
* @param array $data Row data.
* @param array $data Item data.
* @return WC_Product|WP_Error
*/
protected function get_product_object( $data ) {
@ -177,6 +177,11 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
*/
protected function process_item( $data ) {
try {
// Get product ID from SKU if created during the importation.
if ( empty( $data['id'] ) && ! empty( $data['sku'] ) && ( $product_id = wc_get_product_id_by_sku( $data['sku'] ) ) ) {
$data['id'] = $product_id;
}
$object = $this->get_product_object( $data );
$updating = false;
@ -226,8 +231,8 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
/**
* Convert raw image URLs to IDs and set.
*
* @param WC_Product $product
* @param array $data
* @param WC_Product $product Product instance.
* @param array $data Item data.
*/
protected function set_image_data( &$product, $data ) {
// Image URLs need converting to IDs before inserting.
@ -249,8 +254,8 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
/**
* Append meta data.
*
* @param WC_Product $product
* @param array $data
* @param WC_Product $product Product instance.
* @param array $data Item data.
*/
protected function set_meta_data( &$product, $data ) {
if ( isset( $data['meta_data'] ) ) {
@ -264,7 +269,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
* Set product data.
*
* @param WC_Product $product Product instance.
* @param array $data Row data.
* @param array $data Item data.
*
* @return WC_Product|WP_Error
* @throws Exception
@ -356,7 +361,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
* Set variation data.
*
* @param WC_Product $variation Product instance.
* @param array $data Row data.
* @param array $data Item data.
*
* @return WC_Product|WP_Error
* @throws Exception

View File

@ -304,6 +304,47 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
return array_map( 'esc_url_raw', array_map( 'trim', explode( ',', $field ) ) );
}
/**
* Parse dates from a CSV.
* Dates requires the format YYYY-MM-DD.
*
* @param string $field Field value.
* @return string|null
*/
protected function parse_date_field( $field ) {
if ( empty( $field ) ) {
return null;
}
if ( preg_match( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $field ) ) {
return $field;
}
return null;
}
/**
* Parse backorders from a CSV.
*
* @param string $field Field value.
* @return string
*/
protected function parse_backorders_field( $field ) {
if ( empty( $field ) ) {
return '';
}
$field = $this->parse_bool_field( $field );
if ( 'notify' === $field ) {
return 'notify';
} elseif ( is_bool( $field ) ) {
return $field ? 'yes' : 'no';
}
return '';
}
/**
* Get formatting callback.
*
@ -320,13 +361,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
'type' => array( $this, 'parse_comma_field' ),
'published' => array( $this, 'parse_bool_field' ),
'featured' => array( $this, 'parse_bool_field' ),
'date_on_sale_from' => 'strtotime',
'date_on_sale_to' => 'strtotime',
'date_on_sale_from' => array( $this, 'parse_date_field' ),
'date_on_sale_to' => array( $this, 'parse_date_field' ),
'name' => 'wp_filter_post_kses',
'short_description' => 'wp_filter_post_kses',
'description' => 'wp_filter_post_kses',
'manage_stock' => array( $this, 'parse_bool_field' ),
'backorders' => array( $this, 'parse_bool_field' ),
'backorders' => array( $this, 'parse_backorders_field' ),
'stock_status' => array( $this, 'parse_bool_field' ),
'sold_individually' => array( $this, 'parse_bool_field' ),
'width' => array( $this, 'parse_float_field' ),
@ -337,7 +378,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
'purchase_note' => 'wp_filter_post_kses',
'price' => 'wc_format_decimal',
'regular_price' => 'wc_format_decimal',
'stock_quantity' => 'absint',
'stock_quantity' => 'wc_stock_amount',
'category_ids' => array( $this, 'parse_categories_field' ),
'tag_ids' => array( $this, 'parse_tags_field' ),
'shipping_class_id' => array( $this, 'parse_shipping_class_field' ),
@ -405,11 +446,6 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
protected function expand_data( $data ) {
$data = apply_filters( 'woocommerce_product_importer_pre_expand_data', $data );
// Product ID and SKU mapping.
if ( empty( $data['id'] ) && ! empty( $data['sku'] ) && ( $product_id = wc_get_product_id_by_sku( $data['sku'] ) ) ) {
$data['id'] = $product_id;
}
// Status is mapped from a special published field.
if ( isset( $data['published'] ) ) {
$data['status'] = ( $data['published'] ? 'publish' : 'draft' );
@ -446,11 +482,6 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$data['stock_status'] = $data['stock_status'] ? 'instock' : 'outofstock';
}
// Backorders is bool.
if ( isset( $data['backorders'] ) ) {
$data['backorders'] = $data['backorders'] ? 'yes' : 'no';
}
// Prepare grouped products.
if ( isset( $data['grouped_products'] ) ) {
$data['children'] = $data['grouped_products'];
@ -483,7 +514,9 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
unset( $data[ $key ] );
} elseif ( $this->starts_with( $key, 'attributes:default' ) ) {
if ( ! empty( $value ) ) {
$attributes[ str_replace( 'attributes:default', '', $key ) ]['default'] = $value;
}
unset( $data[ $key ] );
// Downloads.
@ -510,7 +543,14 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
}
if ( ! empty( $attributes ) ) {
$data['raw_attributes'] = $attributes;
// Remove empty attributes and clear indexes.
foreach ( $attributes as $attribute ) {
if ( empty( $attribute['name'] ) ) {
continue;
}
$data['raw_attributes'][] = $attribute;
}
}
if ( ! empty( $downloads ) ) {
@ -523,7 +563,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$data['downloads'][] = array(
'name' => $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['url'] ),
'file' => apply_filters( 'woocommerce_file_download_path', $file['url'], $product, $key ),
'file' => $file['url'],
);
}
}

View File

@ -24,29 +24,77 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
}
/**
* Test import.
* @todo enable the importer again after conclude the parser.
* Get CSV mapped items.
*
* @since 3.1.0
* @return array
*/
public function test_import() {
$mapped = array(
private function get_csv_mapped_items() {
return array(
'Type' => 'type',
'SKU' => 'sku',
'Name' => 'name',
'Published' => 'published',
'Is featured?' => 'featured',
'Visibility in catalog' => 'catalog_visibility',
'Short description' => 'short_description',
'Description' => 'description',
'Date sale price starts' => 'date_on_sale_from',
'Date sale price ends' => 'date_on_sale_to',
'Tax status' => 'tax_status',
'Tax class' => 'tax_class',
'In stock?' => 'stock_status',
'Stock' => 'stock_quantity',
'Backorders allowed?' => 'backorders',
'Sold individually?' => 'sold_individually',
'Weight (kg)' => 'weight',
'Length (cm)' => 'length',
'Width (cm)' => 'width',
'Height (cm)' => 'height',
'Allow customer reviews?' => 'reviews_allowed',
'Purchase note' => 'purchase_note',
'Sale price' => 'sale_price',
'Regular price' => 'regular_price',
'Categories' => 'category_ids',
'Tags' => 'tag_ids',
'Shipping class' => 'shipping_class_id',
'Images' => 'images',
'Download limit' => 'download_limit',
'Download expiry days' => 'download_expiry',
'Parent' => 'parent_id',
'Upsells' => 'upsell_ids',
'Cross-sells' => 'cross_sell_ids',
'Grouped products' => 'grouped_products',
'External URL' => 'product_url',
'Button text' => 'button_text',
'Attribute 1 name' => 'attributes:name1',
'Attribute 1 value(s)' => 'attributes:value2',
'Attribute 2 name' => 'attributes:name2',
'Attribute 2 value(s)' => 'attributes:value2',
'Attribute 1 default' => 'attributes:default1',
'Attribute 2 default' => 'attributes:default2',
'Download 1 name' => 'downloads:name1',
'Download 1 URL' => 'downloads:url1',
);
}
/**
* Test import.
* @since 3.1.0
*/
public function test_import() {
$args = array(
'mapping' => $mapped,
'mapping' => $this->get_csv_mapped_items(),
'parse' => true,
);
$importer = new WC_Product_CSV_Importer( $this->csv_file, $args );
$results = $importer->import();
$this->assertEquals( 3, count( $results['imported'] ) );
$this->assertEquals( 7, count( $results['imported'] ) );
$this->assertEquals( 0, count( $results['failed'] ) );
$this->assertEquals( 0, count( $results['updated'] ) );
$this->assertEquals( 0, count( $results['skipped'] ) );
// Exclude imported products.
foreach ( $results['imported'] as $id ) {
@ -59,14 +107,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
* @since 3.1.0
*/
public function test_get_raw_keys() {
$importer = new WC_Product_CSV_Importer( $this->csv_file );
$raw_keys = array(
'Type',
'SKU',
'Name',
'Published',
'Regular price',
);
$importer = new WC_Product_CSV_Importer( $this->csv_file, array( 'lines' => 1 ) );
$raw_keys = array_keys( $this->get_csv_mapped_items() );
$this->assertEquals( $raw_keys, $importer->get_raw_keys() );
}
@ -76,21 +118,14 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
* @since 3.1.0
*/
public function test_get_mapped_keys() {
$mapped = array(
'Type' => 'type',
'SKU' => 'sku',
'Name' => 'name',
'Published' => 'published',
'Regular price' => 'regular_price',
);
$args = array(
'mapping' => $mapped,
'mapping' => $this->get_csv_mapped_items(),
'lines' => 1,
);
$importer = new WC_Product_CSV_Importer( $this->csv_file, $args );
$this->assertEquals( array_values( $mapped ), $importer->get_mapped_keys() );
$this->assertEquals( array_values( $args['mapping'] ), $importer->get_mapped_keys() );
}
/**
@ -98,28 +133,99 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
* @since 3.1.0
*/
public function test_get_raw_data() {
$importer = new WC_Product_CSV_Importer( $this->csv_file, array( 'parse' => false ) );
$importer = new WC_Product_CSV_Importer( $this->csv_file, array( 'parse' => false, 'lines' => 2 ) );
$items = array(
array(
'simple',
'PRODUCT-01',
'Imported Product 1',
1,
40,
'WOOLOGO',
'Woo Logo',
'1',
'',
'visible',
'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'2017-01-01',
'2030-01-01',
'taxable',
'standard',
'1',
'5',
'notify',
'1',
'1',
'1',
'20',
'40',
'1',
'Lorem ipsum dolor sit amet.',
'18',
'20',
'Clothing, Clothing > T-shirts',
'',
'',
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_back.jpg',
'',
'',
'',
'WOOALBUM',
'WOOALBUM',
'',
'',
'',
'Color',
'Red',
'',
'',
'',
'',
'',
'',
),
array(
'simple',
'PRODUCT-02',
'Imported Product 2',
1,
41,
),
array(
'simple',
'PRODUCT-03',
'Imported Product 3',
1,
42,
'simple, downloadable, virtual',
'WOOALBUM',
'Woo Album #1',
'1',
'1',
'visible',
'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'',
'',
'taxable',
'standard',
'1',
'',
'',
'',
'',
'',
'',
'',
'1',
'Lorem ipsum dolor sit amet.',
'',
'5',
'Music > Albums, Music',
'Woo',
'',
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_flat.jpg',
'10',
'90',
'',
'WOOLOGO',
'WOOLOGO',
'',
'',
'',
'Label',
'WooCommerce',
'Vinyl',
'180-Gram',
'',
'',
'Album flac',
'http://woo.dev/albums/album.flac',
),
);
@ -131,50 +237,336 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
* @since 3.1.0
*/
public function test_get_parsed_data() {
$mapped = array(
'Type' => 'type',
'SKU' => 'sku',
'Name' => 'name',
'Published' => 'published',
'Regular price' => 'regular_price',
);
$args = array(
'mapping' => $mapped,
'parse' => true,
'mapping' => $this->get_csv_mapped_items(),
'parse' => true
);
$importer = new WC_Product_CSV_Importer( $this->csv_file, $args );
$items = array(
array(
'type' => 'simple',
'sku' => 'PRODUCT-01',
'name' => 'Imported Product 1',
'regular_price' => '40',
'sku' => 'WOOLOGO',
'name' => 'Woo Logo',
'featured' => '',
'catalog_visibility' => 'visible',
'short_description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => '2017-01-01',
'date_on_sale_to' => '2030-01-01',
'tax_status' => 'taxable',
'tax_class' => 'standard',
'stock_status' => 'instock',
'stock_quantity' => 5,
'backorders' => 'notify',
'sold_individually' => true,
'weight' => 1.0,
'length' => 1.0,
'width' => 20.0,
'height' => 40.0,
'reviews_allowed' => true,
'purchase_note' => 'Lorem ipsum dolor sit amet.',
'sale_price' => '18',
'regular_price' => '20',
'shipping_class_id' => 0,
'download_limit' => 0,
'download_expiry' => 0,
'product_url' => '',
'button_text' => '',
'status' => 'publish',
'raw_image_id' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg',
'raw_gallery_image_ids' => array( 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_back.jpg' ),
'virtual' => '',
'downloadable' => '',
'manage_stock' => true,
'virtual' => false,
'downloadable' => false,
'status' => 'publish',
'raw_attributes' => array(
array(
'name' => 'Color',
),
),
),
array(
'type' => 'simple',
'sku' => 'PRODUCT-02',
'name' => 'Imported Product 2',
'regular_price' => '41',
'virtual' => false,
'downloadable' => false,
'sku' => 'WOOALBUM',
'name' => 'Woo Album #1',
'featured' => true,
'catalog_visibility' => 'visible',
'short_description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => null,
'date_on_sale_to' => null,
'tax_status' => 'taxable',
'tax_class' => 'standard',
'stock_status' => 'instock',
'stock_quantity' => 0,
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => true,
'purchase_note' => 'Lorem ipsum dolor sit amet.',
'sale_price' => '',
'regular_price' => '5',
'shipping_class_id' => 0,
'download_limit' => 10,
'download_expiry' => 90,
'product_url' => '',
'button_text' => '',
'status' => 'publish',
'raw_image_id' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg',
'raw_gallery_image_ids' => array( 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_flat.jpg' ),
'virtual' => true,
'downloadable' => true,
'manage_stock' => false,
'raw_attributes' => array(
array(
'name' => 'Label',
),
array(
'type' => 'simple',
'sku' => 'PRODUCT-03',
'name' => 'Imported Product 3',
'regular_price' => '42',
'value' => array( '180-Gram' ),
'name' => 'Vinyl',
),
),
'downloads' => array(
array(
'name' => 'Album flac',
'file' => 'http://woo.dev/albums/album.flac',
),
),
),
array(
'type' => 'external',
'sku' => '',
'name' => 'WooCommerce Product CSV Suite',
'featured' => '',
'catalog_visibility' => 'visible',
'short_description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => null,
'date_on_sale_to' => null,
'tax_status' => 'taxable',
'tax_class' => 'standard',
'stock_status' => 'instock',
'stock_quantity' => 0,
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => false,
'purchase_note' => 'Lorem ipsum dolor sit amet.',
'sale_price' => '',
'regular_price' => '199',
'shipping_class_id' => 0,
'download_limit' => 0,
'download_expiry' => 0,
'product_url' => 'https://woocommerce.com/products/product-csv-import-suite/',
'button_text' => 'Buy on WooCommerce.com',
'status' => 'publish',
'raw_image_id' => null,
'virtual' => false,
'downloadable' => false,
'manage_stock' => false,
),
array(
'type' => 'variable',
'sku' => 'WOOIDEA',
'name' => 'Ship Your Idea',
'featured' => '',
'catalog_visibility' => 'visible',
'short_description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => null,
'date_on_sale_to' => null,
'tax_status' => '',
'tax_class' => '',
'stock_status' => 'outofstock',
'stock_quantity' => 0,
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => true,
'purchase_note' => 'Lorem ipsum dolor sit amet.',
'sale_price' => '',
'regular_price' => '',
'shipping_class_id' => 0,
'download_limit' => 0,
'download_expiry' => 0,
'product_url' => '',
'button_text' => '',
'status' => 'publish',
'raw_image_id' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg',
'raw_gallery_image_ids' => array(
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg',
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg',
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg',
),
'virtual' => false,
'downloadable' => false,
'manage_stock' => false,
'raw_attributes' => array(
array(
'name' => 'Color',
'default' => 'Green',
),
array(
'value' => array( 'M', 'L' ),
'name' => 'Size',
'default' => 'L'
),
),
),
array(
'type' => 'variation',
'sku' => '',
'name' => '',
'featured' => '',
'catalog_visibility' => 'visible',
'short_description' => '',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => null,
'date_on_sale_to' => null,
'tax_status' => 'taxable',
'tax_class' => 'standard',
'stock_status' => 'instock',
'stock_quantity' => 6,
'backorders' => '',
'sold_individually' => '',
'weight' => 1.0,
'length' => 2.0,
'width' => 25.0,
'height' => 55.0,
'reviews_allowed' => '',
'purchase_note' => '',
'sale_price' => '',
'regular_price' => '20',
'shipping_class_id' => 0,
'download_limit' => 0,
'download_expiry' => 0,
'product_url' => '',
'button_text' => '',
'status' => 'publish',
'raw_image_id' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg',
'virtual' => false,
'downloadable' => false,
'manage_stock' => true,
'raw_attributes' => array(
array(
'name' => 'Color',
),
array(
'value' => array( 'M' ),
'name' => 'Size',
),
),
),
array(
'type' => 'variation',
'sku' => '',
'name' => '',
'featured' => '',
'catalog_visibility' => 'visible',
'short_description' => '',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => null,
'date_on_sale_to' => null,
'tax_status' => 'taxable',
'tax_class' => 'standard',
'stock_status' => 'instock',
'stock_quantity' => 10,
'backorders' => 'yes',
'sold_individually' => '',
'weight' => 1.0,
'length' => 2.0,
'width' => 25.0,
'height' => 55.0,
'reviews_allowed' => '',
'purchase_note' => '',
'sale_price' => '17.99',
'regular_price' => '20',
'shipping_class_id' => 0,
'download_limit' => 0,
'download_expiry' => 0,
'product_url' => '',
'button_text' => '',
'status' => 'publish',
'raw_image_id' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg',
'virtual' => false,
'downloadable' => false,
'manage_stock' => true,
'raw_attributes' => array(
array(
'name' => 'Color',
),
array(
'value' => array( 'L' ),
'name' => 'Size'
)
),
),
array(
'type' => 'grouped',
'sku' => '',
'name' => 'Best Woo Products',
'featured' => true,
'catalog_visibility' => 'visible',
'short_description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'description' => 'Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.',
'date_on_sale_from' => null,
'date_on_sale_to' => null,
'tax_status' => '',
'tax_class' => '',
'stock_status' => 'instock',
'stock_quantity' => 0,
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => '',
'purchase_note' => '',
'sale_price' => '',
'regular_price' => '',
'shipping_class_id' => 0,
'download_limit' => 0,
'download_expiry' => 0,
'product_url' => '',
'button_text' => '',
'status' => 'publish',
'raw_image_id' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg',
'raw_gallery_image_ids' => array( 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg' ),
'virtual' => false,
'downloadable' => false,
'manage_stock' => false,
),
);
$this->assertEquals( $items, $importer->get_parsed_data() );
$parsed_data = $importer->get_parsed_data();
// Remove fields that depends on product ID or term ID.
foreach ( $parsed_data as &$data ) {
unset( $data['parent_id'], $data['upsell_ids'], $data['cross_sell_ids'], $data['children'], $data['category_ids'], $data['tag_ids'] );
}
$this->assertEquals( $items, $parsed_data );
// Remove temporary products.
$temp_products = get_posts( array(
'post_status' => 'importing',
'post_type' => 'product',
'fields' => 'ids',
) );
foreach ( $temp_products as $id ) {
wp_delete_post( $id, true );
}
}
}

View File

@ -1,4 +1,8 @@
Type,SKU,Name,Published,Regular price
simple,PRODUCT-01,Imported Product 1,1,40
simple,PRODUCT-02,Imported Product 2,1,41
simple,PRODUCT-03,Imported Product 3,1,42
Type,SKU,Name,Published,Is featured?,Visibility in catalog,Short description,Description,Date sale price starts,Date sale price ends,Tax status,Tax class,In stock?,Stock,Backorders allowed?,Sold individually?,Weight (kg),Length (cm),Width (cm),Height (cm),Allow customer reviews?,Purchase note,Sale price,Regular price,Categories,Tags,Shipping class,Images,Download limit,Download expiry days,Parent,Upsells,Cross-sells,Grouped products,External URL,Button text,Attribute 1 name,Attribute 1 value(s),Attribute 2 name,Attribute 2 value(s),Attribute 1 default,Attribute 2 default,Download 1 name,Download 1 URL
simple,WOOLOGO,Woo Logo,1,,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",2017-01-01,2030-01-01,taxable,standard,1,5,notify,1,1,1,20,40,1,Lorem ipsum dolor sit amet.,18,20,"Clothing, Clothing > T-shirts",,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_back.jpg",,,,WOOALBUM,WOOALBUM,,,,Color,Red,,,,,,
"simple, downloadable, virtual",WOOALBUM,Woo Album #1,1,1,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,,,,,,,,1,Lorem ipsum dolor sit amet.,,5,"Music > Albums, Music",Woo,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_flat.jpg",10,90,,WOOLOGO,WOOLOGO,,,,Label,WooCommerce,Vinyl,180-Gram,,,Album flac,http://woo.dev/albums/album.flac
external,,WooCommerce Product CSV Suite,1,,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,,,,,,,,0,Lorem ipsum dolor sit amet.,,199,Software,WooCommerce,,,,,,,,,https://woocommerce.com/products/product-csv-import-suite/,Buy on WooCommerce.com,,,,,,,,
variable,WOOIDEA,Ship Your Idea,1,,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,,,,,,,,,,,1,Lorem ipsum dolor sit amet.,,,"Clothing, Clothing > T-shirts",,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg",,,,,,,,,Color,"Black, Green",Size,"M, L",Green,L,,
variation,,,1,,visible,,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,6,0,,1,2,25,55,,,,20,,,,http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg,,,WOOIDEA,,,,,,Color,Black,Size,M,,,,
variation,,,1,,visible,,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,10,1,,1,2,25,55,,,17.99,20,,,,http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg,,,WOOIDEA,,,,,,Color,Green,Size,L,,,,
grouped,,Best Woo Products,1,1,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,,,1,,,,,,,,,,,,"Clothing, Clothing > T-shirts, Music > Albums, Music",,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg",,,,,,"WOOLOGO, WOOALBUM",,,,,,,,,,

1 Type SKU Name Published Is featured? Visibility in catalog Short description Description Date sale price starts Date sale price ends Tax status Tax class In stock? Stock Backorders allowed? Sold individually? Weight (kg) Length (cm) Width (cm) Height (cm) Allow customer reviews? Purchase note Sale price Regular price Categories Tags Shipping class Images Download limit Download expiry days Parent Upsells Cross-sells Grouped products External URL Button text Attribute 1 name Attribute 1 value(s) Attribute 2 name Attribute 2 value(s) Attribute 1 default Attribute 2 default Download 1 name Download 1 URL
2 simple PRODUCT-01 WOOLOGO Imported Product 1 Woo Logo 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. 2017-01-01 2030-01-01 taxable standard 1 5 notify 1 1 1 20 40 1 Lorem ipsum dolor sit amet. 18 40 20 Clothing, Clothing > T-shirts http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_back.jpg WOOALBUM WOOALBUM Color Red
3 simple simple, downloadable, virtual PRODUCT-02 WOOALBUM Imported Product 2 Woo Album #1 1 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. taxable standard 1 1 Lorem ipsum dolor sit amet. 41 5 Music > Albums, Music Woo http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_flat.jpg 10 90 WOOLOGO WOOLOGO Label WooCommerce Vinyl 180-Gram Album flac http://woo.dev/albums/album.flac
4 simple external PRODUCT-03 Imported Product 3 WooCommerce Product CSV Suite 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. taxable standard 1 0 Lorem ipsum dolor sit amet. 42 199 Software WooCommerce https://woocommerce.com/products/product-csv-import-suite/ Buy on WooCommerce.com
5 variable WOOIDEA Ship Your Idea 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. 1 Lorem ipsum dolor sit amet. Clothing, Clothing > T-shirts http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg Color Black, Green Size M, L Green L
6 variation 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. taxable standard 1 6 0 1 2 25 55 20 http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg WOOIDEA Color Black Size M
7 variation 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. taxable standard 1 10 1 1 2 25 55 17.99 20 http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg WOOIDEA Color Green Size L
8 grouped Best Woo Products 1 1 visible Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an. 1 Clothing, Clothing > T-shirts, Music > Albums, Music http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg WOOLOGO, WOOALBUM