From 022d0a6480b9a79b0c1b02e40a97ec8c77baaa68 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Wed, 27 Mar 2013 17:57:26 +1000 Subject: [PATCH 1/5] Add WC_Product::get_formatted_name() For #2788 --- classes/abstracts/abstract-wc-product.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/classes/abstracts/abstract-wc-product.php b/classes/abstracts/abstract-wc-product.php index 83ca095dff6..f5c52b76324 100644 --- a/classes/abstracts/abstract-wc-product.php +++ b/classes/abstracts/abstract-wc-product.php @@ -1271,4 +1271,22 @@ class WC_Product { return $image; } + + + /** + * Get product name with extra details such as SKU price and attributes. Used within admin. + * + * @access public + * @param mixed $product + * @return void + */ + function get_formatted_name() { + + if ( $this->get_sku() ) + $identifier = $this->get_sku(); + else + $identifier = '#' . $this->id; + + return sprintf( __( '%s – %s', 'woocommerce' ), $identifier, $this->get_title() ); + } } \ No newline at end of file From 4bd469899159bb03795054fffc0ca61d56bee143 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Wed, 27 Mar 2013 17:57:52 +1000 Subject: [PATCH 2/5] Add WC_Product_Variation::get_formatted_name() For #2788 --- classes/class-wc-product-variation.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/classes/class-wc-product-variation.php b/classes/class-wc-product-variation.php index c1e5378044a..405c7e10db5 100644 --- a/classes/class-wc-product-variation.php +++ b/classes/class-wc-product-variation.php @@ -452,4 +452,25 @@ class WC_Product_Variation extends WC_Product { // allow overriding based on the particular file being requested return apply_filters( 'woocommerce_file_download_path', $file_path, $this->variation_id, $download_id ); } + + + /** + * Get product name with extra details such as SKU price and attributes. Used within admin. + * + * @access public + * @param mixed $product + * @return void + */ + function get_formatted_name() { + + if ( $this->get_sku() ) + $identifier = $this->get_sku(); + else + $identifier = '#' . $this->variation_id; + + $attributes = $this->get_variation_attributes(); + $extra_data = ' – ' . implode( ', ', $attributes ) . ' – ' . woocommerce_price( $this->get_price() ); + + return sprintf( __( '%s – %s%s', 'woocommerce' ), $identifier, $this->get_title(), $extra_data ); + } } \ No newline at end of file From 9431f82a240d12836bcbbd6ff4b7bc2796ad09c0 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Wed, 27 Mar 2013 17:58:14 +1000 Subject: [PATCH 3/5] Deprecate woocommerce_get_formatted_product_name() For #2788 --- woocommerce-core-functions.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/woocommerce-core-functions.php b/woocommerce-core-functions.php index 4e8c2949644..e73bff4e5c0 100644 --- a/woocommerce-core-functions.php +++ b/woocommerce-core-functions.php @@ -248,24 +248,10 @@ function woocommerce_get_weight( $weight, $to_unit ) { * @return void */ function woocommerce_get_formatted_product_name( $product ) { - if ( ! $product || ! is_object( $product ) ) - return; - if ( $product->get_sku() ) - $identifier = $product->get_sku(); - elseif ( $product->is_type( 'variation' ) ) - $identifier = '#' . $product->variation_id; - else - $identifier = '#' . $product->id; + _deprecated_function( __FUNCTION__, '2.1', 'WC_Product::get_formatted_name()' ); - if ( $product->is_type( 'variation' ) ) { - $attributes = $product->get_variation_attributes(); - $extra_data = ' – ' . implode( ', ', $attributes ) . ' – ' . woocommerce_price( $product->get_price() ); - } else { - $extra_data = ''; - } - - return sprintf( __( '%s – %s%s', 'woocommerce' ), $identifier, $product->get_title(), $extra_data ); + return $product->get_formatted_name(); } From 9e71cd699fb2e463dadd6415963ced1d2b639eeb Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Wed, 27 Mar 2013 17:58:48 +1000 Subject: [PATCH 4/5] Update woocommerce_get_formatted_product_name use To use new WC_Product::get_formatted_name() function. For #2788 --- .../post-types/writepanels/writepanel-coupon_data.php | 10 ++++------ .../writepanels/writepanel-order_downloads.php | 3 +-- .../post-types/writepanels/writepanel-product_data.php | 10 ++++------ woocommerce-ajax.php | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/admin/post-types/writepanels/writepanel-coupon_data.php b/admin/post-types/writepanels/writepanel-coupon_data.php index 8a0ed594cf1..57e42e86106 100644 --- a/admin/post-types/writepanels/writepanel-coupon_data.php +++ b/admin/post-types/writepanels/writepanel-coupon_data.php @@ -79,10 +79,9 @@ function woocommerce_coupon_data_meta_box( $post ) { $product_ids = array_map( 'absint', explode( ',', $product_ids ) ); foreach ( $product_ids as $product_id ) { - $product = get_product( $product_id ); - $product_name = woocommerce_get_formatted_product_name( $product ); + $product = get_product( $product_id ); - echo ''; + echo ''; } } ?> @@ -99,10 +98,9 @@ function woocommerce_coupon_data_meta_box( $post ) { $product_ids = array_map( 'absint', explode( ',', $product_ids ) ); foreach ( $product_ids as $product_id ) { - $product = get_product( $product_id ); - $product_name = woocommerce_get_formatted_product_name( $product ); + $product = get_product( $product_id ); - echo ''; + echo ''; } } ?> diff --git a/admin/post-types/writepanels/writepanel-order_downloads.php b/admin/post-types/writepanels/writepanel-order_downloads.php index d79987712d4..a5818beb11a 100644 --- a/admin/post-types/writepanels/writepanel-order_downloads.php +++ b/admin/post-types/writepanels/writepanel-order_downloads.php @@ -76,9 +76,8 @@ function woocommerce_order_downloads_meta_box() { if ( $products ) foreach ( $products as $product ) { $product_object = get_product( $product->ID ); - $product_name = woocommerce_get_formatted_product_name( $product_object ); - echo ''; + echo ''; } ?> diff --git a/admin/post-types/writepanels/writepanel-product_data.php b/admin/post-types/writepanels/writepanel-product_data.php index cb425b648a5..c86064d7828 100644 --- a/admin/post-types/writepanels/writepanel-product_data.php +++ b/admin/post-types/writepanels/writepanel-product_data.php @@ -526,10 +526,9 @@ function woocommerce_product_data_box() { if ( $product_ids ) { foreach ( $product_ids as $product_id ) { - $product = get_product( $product_id ); - $product_name = woocommerce_get_formatted_product_name( $product ); + $product = get_product( $product_id ); - echo ''; + echo ''; } } ?> @@ -543,10 +542,9 @@ function woocommerce_product_data_box() { if ( $product_ids ) { foreach ( $product_ids as $product_id ) { - $product = get_product( $product_id ); - $product_name = woocommerce_get_formatted_product_name( $product ); + $product = get_product( $product_id ); - echo ''; + echo ''; } } ?> diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php index 71cafbc465d..a2b2405d431 100644 --- a/woocommerce-ajax.php +++ b/woocommerce-ajax.php @@ -1607,7 +1607,7 @@ function woocommerce_json_search_products( $x = '', $post_types = array('product $product = get_product( $post ); - $found_products[ $post ] = woocommerce_get_formatted_product_name( $product ); + $found_products[ $post ] = $product->get_formatted_name(); } From 854a9eccad5679bc1907fd4505d61980a51bd78c Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Wed, 27 Mar 2013 18:06:59 +1000 Subject: [PATCH 5/5] Update phpdoc --- classes/abstracts/abstract-wc-product.php | 4 ++-- classes/class-wc-product-variation.php | 6 +++--- woocommerce-core-functions.php | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/classes/abstracts/abstract-wc-product.php b/classes/abstracts/abstract-wc-product.php index f5c52b76324..036f7bf4f85 100644 --- a/classes/abstracts/abstract-wc-product.php +++ b/classes/abstracts/abstract-wc-product.php @@ -1274,11 +1274,11 @@ class WC_Product { /** - * Get product name with extra details such as SKU price and attributes. Used within admin. + * Get product name with SKU or ID. Used within admin. * * @access public * @param mixed $product - * @return void + * @return string Formatted product name */ function get_formatted_name() { diff --git a/classes/class-wc-product-variation.php b/classes/class-wc-product-variation.php index 405c7e10db5..d9e0e93964e 100644 --- a/classes/class-wc-product-variation.php +++ b/classes/class-wc-product-variation.php @@ -455,13 +455,13 @@ class WC_Product_Variation extends WC_Product { /** - * Get product name with extra details such as SKU price and attributes. Used within admin. + * Get product name with extra details such as SKU, price and attributes. Used within admin. * * @access public * @param mixed $product - * @return void + * @return string Formatted product name, including attributes and price */ - function get_formatted_name() { + public function get_formatted_name() { if ( $this->get_sku() ) $identifier = $this->get_sku(); diff --git a/woocommerce-core-functions.php b/woocommerce-core-functions.php index e73bff4e5c0..7beccd0aafd 100644 --- a/woocommerce-core-functions.php +++ b/woocommerce-core-functions.php @@ -245,6 +245,7 @@ function woocommerce_get_weight( $weight, $to_unit ) { * * @access public * @param mixed $product + * @deprecated 2.1 * @return void */ function woocommerce_get_formatted_product_name( $product ) {