From ad1eb92b4c1a6590d0ef790548c45bb20970dd91 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 17 Jan 2013 11:23:11 +0000 Subject: [PATCH] Clean up variation display in admin. Closes #2241. --- .../writepanels/writepanel-coupon_data.php | 22 ++---- .../writepanel-order_downloads.php | 8 +-- .../writepanels/writepanel-product_data.php | 22 ++---- classes/class-wc-product-variation.php | 2 +- woocommerce-ajax.php | 67 ++----------------- woocommerce-core-functions.php | 43 ++++++++++++ 6 files changed, 63 insertions(+), 101 deletions(-) diff --git a/admin/post-types/writepanels/writepanel-coupon_data.php b/admin/post-types/writepanels/writepanel-coupon_data.php index e65aff09a2e..682dd12c48c 100644 --- a/admin/post-types/writepanels/writepanel-coupon_data.php +++ b/admin/post-types/writepanels/writepanel-coupon_data.php @@ -75,16 +75,11 @@ function woocommerce_coupon_data_meta_box( $post ) { if ( $product_ids ) { $product_ids = array_map( 'absint', explode( ',', $product_ids ) ); foreach ( $product_ids as $product_id ) { - $title = get_the_title( $product_id ); - $sku = get_post_meta( $product_id, '_sku', true ); - if ( ! $title ) - continue; + $product = get_product( $product_id ); + $product_name = woocommerce_get_formatted_product_name( $product ); - if ( ! empty( $sku ) ) - $sku = ' (SKU: ' . $sku . ')'; - - echo ''; + echo ''; } } ?> @@ -100,16 +95,11 @@ function woocommerce_coupon_data_meta_box( $post ) { if ( $product_ids ) { $product_ids = array_map( 'absint', explode( ',', $product_ids ) ); foreach ( $product_ids as $product_id ) { - $title = get_the_title( $product_id ); - $sku = get_post_meta( $product_id, '_sku', true ); - if ( ! $title ) - continue; + $product = get_product( $product_id ); + $product_name = woocommerce_get_formatted_product_name( $product ); - if ( ! empty( $sku ) ) - $sku = ' (SKU: ' . $sku . ')'; - - echo ''; + echo ''; } } ?> diff --git a/admin/post-types/writepanels/writepanel-order_downloads.php b/admin/post-types/writepanels/writepanel-order_downloads.php index 6ea2cbe88c8..707bc3cc3d2 100644 --- a/admin/post-types/writepanels/writepanel-order_downloads.php +++ b/admin/post-types/writepanels/writepanel-order_downloads.php @@ -75,12 +75,10 @@ function woocommerce_order_downloads_meta_box() { if ( $products ) foreach ( $products as $product ) { - $sku = get_post_meta( $product->ID, '_sku', true ); + $product_object = get_product( $product->ID ); + $product_name = woocommerce_get_formatted_product_name( $product ); - if ( $sku ) - $sku = ' SKU: ' . $sku; - - echo ''; + echo ''; } ?> diff --git a/admin/post-types/writepanels/writepanel-product_data.php b/admin/post-types/writepanels/writepanel-product_data.php index cb38030b5b9..a23da761ce6 100644 --- a/admin/post-types/writepanels/writepanel-product_data.php +++ b/admin/post-types/writepanels/writepanel-product_data.php @@ -507,16 +507,11 @@ function woocommerce_product_data_box() { $product_ids = ! empty( $upsell_ids ) ? array_map( 'absint', $upsell_ids ) : null; if ( $product_ids ) { foreach ( $product_ids as $product_id ) { - $title = get_the_title( $product_id ); - $sku = get_post_meta( $product_id, '_sku', true ); - if ( ! $title ) - continue; + $product = get_product( $product_id ); + $product_name = woocommerce_get_formatted_product_name( $product ); - if ( ! empty( $sku ) ) - $sku = ' (SKU: ' . $sku . ')'; - - echo ''; + echo ''; } } ?> @@ -529,16 +524,11 @@ function woocommerce_product_data_box() { $product_ids = ! empty( $crosssell_ids ) ? array_map( 'absint', $crosssell_ids ) : null; if ( $product_ids ) { foreach ( $product_ids as $product_id ) { - $title = get_the_title( $product_id ); - $sku = get_post_meta( $product_id, '_sku', true ); - if ( ! $title ) - continue; + $product = get_product( $product_id ); + $product_name = woocommerce_get_formatted_product_name( $product ); - if ( ! empty( $sku ) ) - $sku = ' (SKU: ' . $sku . ')'; - - echo ''; + echo ''; } } ?> diff --git a/classes/class-wc-product-variation.php b/classes/class-wc-product-variation.php index 8bd2700720c..581aa19f85b 100644 --- a/classes/class-wc-product-variation.php +++ b/classes/class-wc-product-variation.php @@ -60,7 +60,7 @@ class WC_Product_Variation extends WC_Product { */ public function __construct( $variation, $args = array() ) { - $this->product_type = 'variable'; + $this->product_type = 'variation'; if ( is_object( $variation ) ) { $this->variation_id = absint( $variation->ID ); diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php index 6ab5a58ffb9..4ffd12e460e 100644 --- a/woocommerce-ajax.php +++ b/woocommerce-ajax.php @@ -1616,17 +1616,15 @@ function woocommerce_json_search_products( $x = '', $post_types = array('product $found_products = array(); - if ($posts) foreach ($posts as $post) { + if ( $posts ) foreach ( $posts as $post ) { - $SKU = get_post_meta($post, '_sku', true); + $product = get_product( $post ); - if (isset($SKU) && $SKU) $SKU = ' (SKU: ' . $SKU . ')'; - - $found_products[$post] = get_the_title( $post ) . ' – #' . $post . $SKU; + $found_products[ $post ] = woocommerce_get_formatted_product_name( $product ); } - $found_products = apply_filters( 'woocommerce_json_search_found_products', $found_products); + $found_products = apply_filters( 'woocommerce_json_search_found_products', $found_products ); echo json_encode( $found_products ); @@ -1692,63 +1690,6 @@ function woocommerce_json_search_customers() { add_action('wp_ajax_woocommerce_json_search_customers', 'woocommerce_json_search_customers'); -/** - * Search for products for upsells/crosssells - * - * @access public - * @return void - */ -function woocommerce_upsell_crosssell_search_products() { - - check_ajax_referer( 'search-products', 'security' ); - - $search = (string) urldecode(stripslashes(strip_tags($_POST['search']))); - $name = (string) urldecode(stripslashes(strip_tags($_POST['name']))); - - if (empty($search)) die(); - - if (is_numeric($search)) : - - $args = array( - 'post_type' => 'product', - 'post_status' => 'publish', - 'posts_per_page' => 15, - 'post__in' => array(0, $search) - ); - - else : - - $args = array( - 'post_type' => 'product', - 'post_status' => 'publish', - 'posts_per_page' => 15, - 's' => $search - ); - - endif; - - $posts = apply_filters('woocommerce_upsell_crosssell_search_products', get_posts( $args )); - - if ($posts) : foreach ($posts as $post) : - - $SKU = get_post_meta($post->ID, '_sku', true); - - ?> -
  • post_title; ?> – #ID; ?>
  • -
  • get_sku() ) + $identifier = $product->get_sku(); + elseif ( $product->is_type( 'variation' ) ) + $identifier = '#' . $product->variation_id; + else + $identifier = '#' . $product->id; + + 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 ); +} + + /** * Get the placeholder image URL for products etc *