From c18cc47286881210a5d2554803b59347d5215564 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 21 Dec 2017 15:43:45 -0200 Subject: [PATCH 1/2] Format prices while exporting products --- .../export/class-wc-product-csv-exporter.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/export/class-wc-product-csv-exporter.php b/includes/export/class-wc-product-csv-exporter.php index ee006f9e9fa..329da823119 100644 --- a/includes/export/class-wc-product-csv-exporter.php +++ b/includes/export/class-wc-product-csv-exporter.php @@ -199,6 +199,26 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { return isset( $statuses[ $status ] ) ? $statuses[ $status ] : -1; } + /** + * Get formatted sale price. + * + * @param WC_Product $product Product being exported. + * @return string + */ + protected function get_column_value_sale_price( $product ) { + return wc_format_localized_price( $product->get_sale_price( 'view' ) ); + } + + /** + * Get formatted regular price. + * + * @param WC_Product $product Product being exported. + * @return string + */ + protected function get_column_value_regular_price( $product ) { + return wc_format_localized_price( $product->get_regular_price() ); + } + /** * Get product_cat value. * From 71a1fd319ee050504e5aeab9990935abb0bbbecc Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 21 Dec 2017 15:53:12 -0200 Subject: [PATCH 2/2] Fixed coding standards --- .../export/class-wc-product-csv-exporter.php | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/includes/export/class-wc-product-csv-exporter.php b/includes/export/class-wc-product-csv-exporter.php index 329da823119..d862659562f 100644 --- a/includes/export/class-wc-product-csv-exporter.php +++ b/includes/export/class-wc-product-csv-exporter.php @@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) { * Include dependencies. */ if ( ! class_exists( 'WC_CSV_Batch_Exporter', false ) ) { - include_once( WC_ABSPATH . 'includes/export/abstract-wc-csv-batch-exporter.php' ); + include_once WC_ABSPATH . 'includes/export/abstract-wc-csv-batch-exporter.php'; } /** @@ -98,9 +98,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { 'stock' => __( 'Stock', 'woocommerce' ), 'backorders' => __( 'Backorders allowed?', 'woocommerce' ), 'sold_individually' => __( 'Sold individually?', 'woocommerce' ), + /* translators: %s: weight */ 'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), get_option( 'woocommerce_weight_unit' ) ), + /* translators: %s: length */ 'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ), + /* translators: %s: width */ 'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ), + /* translators: %s: Height */ 'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ), 'reviews_allowed' => __( 'Allow customer reviews?', 'woocommerce' ), 'purchase_note' => __( 'Purchase note', 'woocommerce' ), @@ -129,13 +133,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { */ public function prepare_data_to_export() { $columns = $this->get_column_names(); - $args = apply_filters( "woocommerce_product_export_{$this->export_type}_query_args", array( + $args = apply_filters( "woocommerce_product_export_{$this->export_type}_query_args", array( 'status' => array( 'private', 'publish', 'draft' ), 'type' => $this->product_types_to_export, 'limit' => $this->get_limit(), 'page' => $this->get_page(), 'orderby' => array( - 'ID' => 'ASC', + 'ID' => 'ASC', ), 'return' => 'objects', 'paginate' => true, @@ -267,7 +271,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { $images = array(); foreach ( $image_ids as $image_id ) { - $image = wp_get_attachment_image_src( $image_id, 'full' ); + $image = wp_get_attachment_image_src( $image_id, 'full' ); if ( $image ) { $images[] = $image[0]; @@ -352,7 +356,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { } $grouped_products = array(); - $child_ids = $product->get_children( 'edit' ); + $child_ids = $product->get_children( 'edit' ); foreach ( $child_ids as $child_id ) { $child = wc_get_product( $child_id ); if ( ! $child ) { @@ -434,9 +438,9 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { $backorders = $product->get_backorders( 'edit' ); switch ( $backorders ) { - case 'notify' : + case 'notify': return 'notify'; - default : + default: return wc_string_to_bool( $backorders ) ? 1 : 0; } } @@ -477,10 +481,12 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { if ( $downloads ) { $i = 1; foreach ( $downloads as $download ) { + /* translators: %s: download number */ $this->column_names[ 'downloads:name' . $i ] = sprintf( __( 'Download %d name', 'woocommerce' ), $i ); - $this->column_names[ 'downloads:url' . $i ] = sprintf( __( 'Download %d URL', 'woocommerce' ), $i ); - $row[ 'downloads:name' . $i ] = $download->get_name(); - $row[ 'downloads:url' . $i ] = $download->get_file(); + /* translators: %s: download number */ + $this->column_names[ 'downloads:url' . $i ] = sprintf( __( 'Download %d URL', 'woocommerce' ), $i ); + $row[ 'downloads:name' . $i ] = $download->get_name(); + $row[ 'downloads:url' . $i ] = $download->get_file(); $i++; } } @@ -502,9 +508,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { if ( count( $attributes ) ) { $i = 1; foreach ( $attributes as $attribute_name => $attribute ) { - $this->column_names[ 'attributes:name' . $i ] = sprintf( __( 'Attribute %d name', 'woocommerce' ), $i ); - $this->column_names[ 'attributes:value' . $i ] = sprintf( __( 'Attribute %d value(s)', 'woocommerce' ), $i ); - $this->column_names[ 'attributes:visible' . $i ] = sprintf( __( 'Attribute %d visible', 'woocommerce' ), $i ); + /* translators: %s: attribute number */ + $this->column_names[ 'attributes:name' . $i ] = sprintf( __( 'Attribute %d name', 'woocommerce' ), $i ); + /* translators: %s: attribute number */ + $this->column_names[ 'attributes:value' . $i ] = sprintf( __( 'Attribute %d value(s)', 'woocommerce' ), $i ); + /* translators: %s: attribute number */ + $this->column_names[ 'attributes:visible' . $i ] = sprintf( __( 'Attribute %d visible', 'woocommerce' ), $i ); + /* translators: %s: attribute number */ $this->column_names[ 'attributes:taxonomy' . $i ] = sprintf( __( 'Attribute %d global', 'woocommerce' ), $i ); if ( is_a( $attribute, 'WC_Product_Attribute' ) ) { @@ -542,12 +552,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { } if ( $product->is_type( 'variable' ) && isset( $default_attributes[ sanitize_title( $attribute_name ) ] ) ) { + /* translators: %s: attribute number */ $this->column_names[ 'attributes:default' . $i ] = sprintf( __( 'Attribute %d default', 'woocommerce' ), $i ); $default_value = $default_attributes[ sanitize_title( $attribute_name ) ]; if ( 0 === strpos( $attribute_name, 'pa_' ) ) { $option_term = get_term_by( 'slug', $default_value, $attribute_name ); // @codingStandardsIgnoreLine. - $row[ 'attributes:default' . $i ] = $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $default_value; + $row[ 'attributes:default' . $i ] = $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $default_value; } else { $row[ 'attributes:default' . $i ] = $default_value; } @@ -585,7 +596,8 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter { continue; } - $column_key = 'meta:' . esc_attr( $meta->key ); + $column_key = 'meta:' . esc_attr( $meta->key ); + /* translators: %s: meta data name */ $this->column_names[ $column_key ] = sprintf( __( 'Meta: %s', 'woocommerce' ), $meta->key ); $row[ $column_key ] = $meta_value; $i ++;