From 780ce1a4e6ce7fff11ccaf521d7773b82be459a6 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 18:42:07 -0300 Subject: [PATCH 01/18] Fixed deprecated `set_stock` notice --- ...ass-wc-product-csv-importer-controller.php | 4 +-- .../import/abstract-wc-product-importer.php | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index c9dc36359a3..454b8edc322 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -408,7 +408,7 @@ class WC_Product_CSV_Importer_Controller { 'date_on_sale_to' => __( 'Date sale price ends', 'woocommerce' ), 'tax_status' => __( 'Tax Class', 'woocommerce' ), 'stock_status' => __( 'In stock?', 'woocommerce' ), - 'stock' => __( 'Stock', 'woocommerce' ), + 'stock_quantity' => __( 'Stock', 'woocommerce' ), 'backorders' => __( 'Backorders allowed?', 'woocommerce' ), 'sold_individually' => __( 'Sold individually?', 'woocommerce' ), 'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ), @@ -531,7 +531,7 @@ 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' ), diff --git a/includes/import/abstract-wc-product-importer.php b/includes/import/abstract-wc-product-importer.php index 4fb425c9b8f..4e732bf998a 100644 --- a/includes/import/abstract-wc-product-importer.php +++ b/includes/import/abstract-wc-product-importer.php @@ -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 ) { @@ -192,7 +192,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { 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' ) ) ) ); + $result = $object->set_props( array_diff_key( $data, array_flip( array( 'meta_data', 'raw_image_id', 'raw_gallery_image_ids', 'raw_attributes', 'stock_quantity' ) ) ) ); if ( is_wp_error( $result ) ) { throw new Exception( $result->get_error_message() ); @@ -205,6 +205,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { } $this->set_image_data( $object, $data ); + $this->set_stock_quantity( $object, $data ); $this->set_meta_data( $object, $data ); if ( 'importing' === $object->get_status() ) { @@ -226,8 +227,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. @@ -246,11 +247,23 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { } } + /** + * Set stock quantity. + * + * @param WC_Product $product Product instance. + * @param array $data Item data. + */ + protected function set_stock_quantity( &$product, $data ) { + if ( isset( $data['stock_quantity'] ) && $product->get_manage_stock() ) { + wc_update_product_stock( $product, $data['stock_quantity'] ); + } + } + /** * 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 +277,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 @@ -352,7 +365,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 From 02a27ae2580492abedeecce88b413c9a6f72650d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 18:44:22 -0300 Subject: [PATCH 02/18] Fixed PHP Notice about undefined name for product attributes --- includes/import/class-wc-product-csv-importer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 6579d75f817..7f9ae54168f 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -463,15 +463,21 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { unset( $data[ $key ] ); } elseif ( $this->starts_with( $key, 'attributes:value' ) ) { - $attributes[ str_replace( 'attributes:value', '', $key ) ]['value'] = $value; + if ( ! empty( $value ) ) { + $attributes[ str_replace( 'attributes:value', '', $key ) ]['value'] = $value; + } unset( $data[ $key ] ); } elseif ( $this->starts_with( $key, 'attributes:visible' ) ) { - $attributes[ str_replace( 'attributes:visible', '', $key ) ]['visible'] = wc_string_to_bool( $value ); + if ( ! empty( $value ) ) { + $attributes[ str_replace( 'attributes:visible', '', $key ) ]['visible'] = wc_string_to_bool( $value ); + } unset( $data[ $key ] ); } elseif ( $this->starts_with( $key, 'attributes:default' ) ) { - $attributes[ str_replace( 'attributes:default', '', $key ) ]['default'] = $value; + if ( ! empty( $value ) ) { + $attributes[ str_replace( 'attributes:default', '', $key ) ]['default'] = $value; + } unset( $data[ $key ] ); // Downloads. From 2eeb444eeb3f0cc5fb22e61268ed685d71add67f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 18:53:22 -0300 Subject: [PATCH 03/18] Properly set stock quantity --- includes/import/abstract-wc-product-importer.php | 15 +-------------- includes/import/class-wc-product-csv-importer.php | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/includes/import/abstract-wc-product-importer.php b/includes/import/abstract-wc-product-importer.php index 4e732bf998a..3a120ac93b7 100644 --- a/includes/import/abstract-wc-product-importer.php +++ b/includes/import/abstract-wc-product-importer.php @@ -192,7 +192,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { 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', 'stock_quantity' ) ) ) ); + $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 ) ) { throw new Exception( $result->get_error_message() ); @@ -205,7 +205,6 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { } $this->set_image_data( $object, $data ); - $this->set_stock_quantity( $object, $data ); $this->set_meta_data( $object, $data ); if ( 'importing' === $object->get_status() ) { @@ -247,18 +246,6 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { } } - /** - * Set stock quantity. - * - * @param WC_Product $product Product instance. - * @param array $data Item data. - */ - protected function set_stock_quantity( &$product, $data ) { - if ( isset( $data['stock_quantity'] ) && $product->get_manage_stock() ) { - wc_update_product_stock( $product, $data['stock_quantity'] ); - } - } - /** * Append meta data. * diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 7f9ae54168f..85ab7ba5bda 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -337,7 +337,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' ), From fe67ca0afff11ab84787e609da860626ef7c822e Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 18:58:35 -0300 Subject: [PATCH 04/18] Fixed images mapping key --- .../importers/class-wc-product-csv-importer-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 454b8edc322..6da92fc5f38 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -422,7 +422,7 @@ class WC_Product_CSV_Importer_Controller { 'category_ids' => __( 'Categories', 'woocommerce' ), 'tag_ids' => __( 'Tags', 'woocommerce' ), 'shipping_class_id' => __( 'Shipping Class', 'woocommerce' ), - 'image_id' => __( 'Images', 'woocommerce' ), + 'images' => __( 'Images', 'woocommerce' ), 'download_limit' => __( 'Download Limit', 'woocommerce' ), 'download_expiry' => __( 'Download Expiry Days', 'woocommerce' ), 'parent_id' => __( 'Parent', 'woocommerce' ), @@ -535,7 +535,7 @@ class WC_Product_CSV_Importer_Controller { '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' ), 'upsell_ids' => __( 'Upsells', 'woocommerce' ), 'cross_sell_ids' => __( 'Cross-sells', 'woocommerce' ), From 4bc139fef9dc6f68b0f95fc77425491f0001df42 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 19:09:57 -0300 Subject: [PATCH 05/18] Fixed conflicts --- .../importers/class-wc-product-csv-importer-controller.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 665ba3171d3..1b90fd7b805 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -534,13 +534,10 @@ class WC_Product_CSV_Importer_Controller { 'stock_quantity' => __( 'Stock', 'woocommerce' ), 'category_ids' => __( 'Categories', 'woocommerce' ), 'tag_ids' => __( 'Tags', 'woocommerce' ), -<<<<<<< HEAD 'shipping_class_id' => __( 'Shipping Class', 'woocommerce' ), 'images' => __( 'Images', 'woocommerce' ), -======= 'shipping_class_id' => __( 'Shipping class', 'woocommerce' ), - 'image_id' => __( 'Images', 'woocommerce' ), ->>>>>>> feature/product-csv-import-export + 'images' => __( 'Images', 'woocommerce' ), 'parent_id' => __( 'Parent', 'woocommerce' ), 'upsell_ids' => __( 'Upsells', 'woocommerce' ), 'cross_sell_ids' => __( 'Cross-sells', 'woocommerce' ), From 0719746af2855a8163632882671855957c21acfb Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 19:25:44 -0300 Subject: [PATCH 06/18] Validate dates and use string format to use website timezone --- .../import/class-wc-product-csv-importer.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 85ab7ba5bda..67ce4a65de4 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -304,6 +304,25 @@ 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; + } + /** * Get formatting callback. * @@ -320,8 +339,8 @@ 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', From 77fcaf33921e5503152336e5a45a256ea2bf19fb Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 19:30:42 -0300 Subject: [PATCH 07/18] Fixed images map handler --- .../importers/class-wc-product-csv-importer-controller.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 1b90fd7b805..79df81b2820 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -422,7 +422,7 @@ class WC_Product_CSV_Importer_Controller { 'category_ids' => __( 'Categories', 'woocommerce' ), 'tag_ids' => __( 'Tags', 'woocommerce' ), 'shipping_class_id' => __( 'Shipping class', 'woocommerce' ), - 'image_id' => __( 'Images', 'woocommerce' ), + 'images' => __( 'Images', 'woocommerce' ), 'download_limit' => __( 'Download limit', 'woocommerce' ), 'download_expiry' => __( 'Download expiry days', 'woocommerce' ), 'parent_id' => __( 'Parent', 'woocommerce' ), @@ -534,10 +534,8 @@ class WC_Product_CSV_Importer_Controller { 'stock_quantity' => __( 'Stock', 'woocommerce' ), 'category_ids' => __( 'Categories', 'woocommerce' ), 'tag_ids' => __( 'Tags', 'woocommerce' ), - 'shipping_class_id' => __( 'Shipping Class', 'woocommerce' ), - 'images' => __( 'Images', 'woocommerce' ), 'shipping_class_id' => __( 'Shipping class', 'woocommerce' ), - 'images' => __( 'Images', 'woocommerce' ), + 'images' => __( 'Images', 'woocommerce' ), 'parent_id' => __( 'Parent', 'woocommerce' ), 'upsell_ids' => __( 'Upsells', 'woocommerce' ), 'cross_sell_ids' => __( 'Cross-sells', 'woocommerce' ), From 3d5891e589ea3f9b774f12ba34257c3fd973defb Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 19:39:20 -0300 Subject: [PATCH 08/18] Fixed how backorders field is parsed --- .../import/class-wc-product-csv-importer.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 67ce4a65de4..dff4332da26 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -323,6 +323,28 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { 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. * @@ -345,7 +367,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { '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' ), @@ -463,11 +485,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'; - } - // Handle special column names which span multiple columns. $attributes = array(); $downloads = array(); From 6d54ae35048c99691fa87c24c11569be57edcbc7 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 19:57:31 -0300 Subject: [PATCH 09/18] Fetch product ID for temporary products only while processing the item --- includes/import/abstract-wc-product-importer.php | 5 +++++ includes/import/class-wc-product-csv-importer.php | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/import/abstract-wc-product-importer.php b/includes/import/abstract-wc-product-importer.php index 3a120ac93b7..17cf16ed09c 100644 --- a/includes/import/abstract-wc-product-importer.php +++ b/includes/import/abstract-wc-product-importer.php @@ -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; diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index dff4332da26..4730d7a42ff 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -444,11 +444,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' ); From 62871767410f641ab76e45c82dbeb69161f8fd8e Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 26 May 2017 20:05:41 -0300 Subject: [PATCH 10/18] Updated sample.csv data --- tests/unit-tests/importer/sample.csv | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit-tests/importer/sample.csv b/tests/unit-tests/importer/sample.csv index 8eec2f0b43a..497f08b9a63 100644 --- a/tests/unit-tests/importer/sample.csv +++ b/tests/unit-tests/importer/sample.csv @@ -1,4 +1,4 @@ -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 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,External URL,Button text,Attribute 1 name,Attribute 1 value(s),Attribute 2 name,Attribute 2 value(s),Attribute 1 default,Attribute 2 default +simple,WOOLOGO,Woo Logo,1,,visible,"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",2017-01-01,2030-01-01,taxable,1,5,notify,,1,1,20,40,1,Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.,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_front.jpg",,,,WOOALBUM,WOOALBUM,,,Color,Red,,,, +"simple, downloadable, virtual",WOOALBUM,Woo Album #1,1,1,visible,"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",,,taxable,1,,,,,,,,1,Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.,,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_angle.jpg",10,90,,WOOLOGO,WOOLOGO,,,Label,WooCommerce,Vinyl,180-Gram,, +external,,WooCommerce Product CSV Suite,1,,visible,"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",,,,1,,,,,,,,0,Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.,,199,Software,WooCommerce,,,,,,,,https://woocommerce.com/products/product-csv-import-suite/,Buy on WooCommerce.com,,,,,, From 9556e248a4494eeffbc68f4d362acd82e494548a Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 12:52:29 -0300 Subject: [PATCH 11/18] Missing tax class --- .../importers/class-wc-product-csv-importer-controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 79df81b2820..5d8f375cfc9 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -406,7 +406,8 @@ class WC_Product_CSV_Importer_Controller { 'description' => __( 'Description', 'woocommerce' ), 'date_on_sale_from' => __( 'Date sale price starts', 'woocommerce' ), 'date_on_sale_to' => __( 'Date sale price ends', 'woocommerce' ), - 'tax_status' => __( 'Tax class', 'woocommerce' ), + 'tax_status' => __( 'Tax status', 'woocommerce' ), + 'tax_class' => __( 'Tax class', 'woocommerce' ), 'stock_status' => __( 'In stock?', 'woocommerce' ), 'stock_quantity' => __( 'Stock', 'woocommerce' ), 'backorders' => __( 'Backorders allowed?', 'woocommerce' ), From 73e34b583fed916ff4477e52802620338e077326 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 13:04:16 -0300 Subject: [PATCH 12/18] Fixed generic stock mapping --- includes/admin/importers/mappings/generic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/importers/mappings/generic.php b/includes/admin/importers/mappings/generic.php index eee79b0c832..bf8114758fa 100644 --- a/includes/admin/importers/mappings/generic.php +++ b/includes/admin/importers/mappings/generic.php @@ -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 ); From 18e903df153dedf8f19f053004f90cafc158f9ab Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 14:26:16 -0300 Subject: [PATCH 13/18] Updated unit test sample.csv --- tests/unit-tests/importer/sample.csv | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/unit-tests/importer/sample.csv b/tests/unit-tests/importer/sample.csv index 497f08b9a63..5e4ee96b190 100644 --- a/tests/unit-tests/importer/sample.csv +++ b/tests/unit-tests/importer/sample.csv @@ -1,4 +1,8 @@ -Type,SKU,Name,Published,Is featured?,Visibility in catalog,Short description,Description,Date sale price starts,Date sale price ends,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,External URL,Button text,Attribute 1 name,Attribute 1 value(s),Attribute 2 name,Attribute 2 value(s),Attribute 1 default,Attribute 2 default -simple,WOOLOGO,Woo Logo,1,,visible,"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",2017-01-01,2030-01-01,taxable,1,5,notify,,1,1,20,40,1,Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.,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_front.jpg",,,,WOOALBUM,WOOALBUM,,,Color,Red,,,, -"simple, downloadable, virtual",WOOALBUM,Woo Album #1,1,1,visible,"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",,,taxable,1,,,,,,,,1,Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.,,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_angle.jpg",10,90,,WOOLOGO,WOOLOGO,,,Label,WooCommerce,Vinyl,180-Gram,, -external,,WooCommerce Product CSV Suite,1,,visible,"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",,,,1,,,,,,,,0,Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.,,199,Software,WooCommerce,,,,,,,,https://woocommerce.com/products/product-csv-import-suite/,Buy on WooCommerce.com,,,,,, +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 +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,, +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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.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",,,,,,,, From 40c2b471f598076d22971a3b1616c40e17a8ba57 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 14:50:54 -0300 Subject: [PATCH 14/18] Grouped products after cross sells as in the admin screen --- .../importers/class-wc-product-csv-importer-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index d2329449e23..3fd308bc5f2 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -435,9 +435,9 @@ class WC_Product_CSV_Importer_Controller { __( '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', ) ); @@ -547,9 +547,9 @@ class WC_Product_CSV_Importer_Controller { 'shipping_class_id' => __( 'Shipping class', '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( From 0f79138b17e4cc70a849a2d8ef0953574ac62ba5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 15:01:43 -0300 Subject: [PATCH 15/18] Included download name and URL into the sample.csv --- tests/unit-tests/importer/sample.csv | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unit-tests/importer/sample.csv b/tests/unit-tests/importer/sample.csv index 5e4ee96b190..f22f5fba934 100644 --- a/tests/unit-tests/importer/sample.csv +++ b/tests/unit-tests/importer/sample.csv @@ -1,8 +1,8 @@ -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 -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,, -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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.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",,,,,,,, +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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.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",,,,,,,,,, From fb819948558f240824c54ad36d027f5edde78f8c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 15:01:48 -0300 Subject: [PATCH 16/18] Fixed downloads URLs in the CSV parser --- includes/import/class-wc-product-csv-importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 4276cedbe13..59b2c02b1af 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -555,7 +555,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'], ); } } From 611695b9f4d1c60164bf03af9916dad9ac6203cb Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 17:58:34 -0300 Subject: [PATCH 17/18] Updated and fixed importer unit tests --- tests/unit-tests/importer/product.php | 544 ++++++++++++++++++++++---- tests/unit-tests/importer/sample.csv | 14 +- 2 files changed, 473 insertions(+), 85 deletions(-) diff --git a/tests/unit-tests/importer/product.php b/tests/unit-tests/importer/product.php index 60f4f0fb171..ef955750fed 100644 --- a/tests/unit-tests/importer/product.php +++ b/tests/unit-tests/importer/product.php @@ -23,30 +23,78 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { require_once $bootstrap->plugin_dir . '/includes/import/class-wc-product-csv-importer.php'; } + /** + * Get CSV mapped items. + * + * @since 3.1.0 + * @return 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. - * @todo enable the importer again after conclude the parser. * @since 3.1.0 */ public function test_import() { - $mapped = array( - 'Type' => 'type', - 'SKU' => 'sku', - 'Name' => 'name', - 'Published' => 'published', - 'Regular price' => 'regular_price', - ); - $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,332 @@ 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', - 'virtual' => false, - 'downloadable' => false, - 'status' => 'publish', + 'type' => 'simple', + '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, + 'raw_attributes' => array( 1 => array( 'name' => 'Color' ) ), ), array( - 'type' => 'simple', - 'sku' => 'PRODUCT-02', - 'name' => 'Imported Product 2', - 'regular_price' => '41', - 'virtual' => false, - 'downloadable' => false, - 'status' => 'publish', + 'type' => 'simple', + '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( + 1 => array( + 'name' => 'Label', + ), + 2 => array( + 'value' => array( '180-Gram' ), + 'name' => 'Vinyl', + ), + ), + 'downloads' => array( + array( + 'name' => 'Album flac', + 'file' => 'http://woo.dev/albums/album.flac', + ), + ), ), array( - 'type' => 'simple', - 'sku' => 'PRODUCT-03', - 'name' => 'Imported Product 3', - 'regular_price' => '42', - 'virtual' => false, - 'downloadable' => false, - 'status' => 'publish', + '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( + 1 => array( + 'name' => 'Color', + 'default' => 'Green', + ), + 2 => 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( + 1 => array( + 'name' => 'Color', + ), + 2 => 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( + 1 => array( + 'name' => 'Color', + ), + 2 => 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 ); + } } } diff --git a/tests/unit-tests/importer/sample.csv b/tests/unit-tests/importer/sample.csv index f22f5fba934..54d268beb5a 100644 --- a/tests/unit-tests/importer/sample.csv +++ b/tests/unit-tests/importer/sample.csv @@ -1,8 +1,8 @@ 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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.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, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.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",,,,,,,,,, +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",,,,,,,,,, From 51ddc36080ebef00c46a2e3e968bbfb0310b52e1 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 May 2017 19:26:31 -0300 Subject: [PATCH 18/18] Skip empty attributes and reset indexes --- .../import/class-wc-product-csv-importer.php | 17 ++++++++------ tests/unit-tests/importer/product.php | 22 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 59b2c02b1af..ce01dd7f78e 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -501,15 +501,11 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { unset( $data[ $key ] ); } elseif ( $this->starts_with( $key, 'attributes:value' ) ) { - if ( ! empty( $value ) ) { - $attributes[ str_replace( 'attributes:value', '', $key ) ]['value'] = $value; - } + $attributes[ str_replace( 'attributes:value', '', $key ) ]['value'] = $value; unset( $data[ $key ] ); } elseif ( $this->starts_with( $key, 'attributes:visible' ) ) { - if ( ! empty( $value ) ) { - $attributes[ str_replace( 'attributes:visible', '', $key ) ]['visible'] = wc_string_to_bool( $value ); - } + $attributes[ str_replace( 'attributes:visible', '', $key ) ]['visible'] = wc_string_to_bool( $value ); unset( $data[ $key ] ); } elseif ( $this->starts_with( $key, 'attributes:default' ) ) { @@ -542,7 +538,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 ) ) { diff --git a/tests/unit-tests/importer/product.php b/tests/unit-tests/importer/product.php index ef955750fed..83377b6c764 100644 --- a/tests/unit-tests/importer/product.php +++ b/tests/unit-tests/importer/product.php @@ -281,7 +281,11 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { 'manage_stock' => true, 'virtual' => false, 'downloadable' => false, - 'raw_attributes' => array( 1 => array( 'name' => 'Color' ) ), + 'raw_attributes' => array( + array( + 'name' => 'Color', + ), + ), ), array( 'type' => 'simple', @@ -319,10 +323,10 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { 'downloadable' => true, 'manage_stock' => false, 'raw_attributes' => array( - 1 => array( + array( 'name' => 'Label', ), - 2 => array( + array( 'value' => array( '180-Gram' ), 'name' => 'Vinyl', ), @@ -409,11 +413,11 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { 'downloadable' => false, 'manage_stock' => false, 'raw_attributes' => array( - 1 => array( + array( 'name' => 'Color', 'default' => 'Green', ), - 2 => array( + array( 'value' => array( 'M', 'L' ), 'name' => 'Size', 'default' => 'L' @@ -455,10 +459,10 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { 'downloadable' => false, 'manage_stock' => true, 'raw_attributes' => array( - 1 => array( + array( 'name' => 'Color', ), - 2 => array( + array( 'value' => array( 'M' ), 'name' => 'Size', ), @@ -499,10 +503,10 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { 'downloadable' => false, 'manage_stock' => true, 'raw_attributes' => array( - 1 => array( + array( 'name' => 'Color', ), - 2 => array( + array( 'value' => array( 'L' ), 'name' => 'Size' )