From 638ab62ec3e340b61f11d4bea054ef9bd99eef85 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 11 Nov 2016 12:14:10 -0200 Subject: [PATCH] Remove deprecated get_variation_id() --- ...-wc-rest-product-variations-controller.php | 4 +- .../api/class-wc-rest-products-controller.php | 43 +++---------------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/includes/api/class-wc-rest-product-variations-controller.php b/includes/api/class-wc-rest-product-variations-controller.php index ad2c732d410..5120f4e00b2 100644 --- a/includes/api/class-wc-rest-product-variations-controller.php +++ b/includes/api/class-wc-rest-product-variations-controller.php @@ -132,7 +132,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller public function prepare_item_for_response( $post, $request ) { $variation = wc_get_product( $post ); $data = array( - 'id' => $variation->get_variation_id(), + 'id' => $variation->get_id(), 'date_created' => wc_rest_prepare_date_response( $variation->get_date_created() ), 'date_modified' => wc_rest_prepare_date_response( $variation->get_date_modified() ), 'description' => $variation->get_variation_description(), @@ -625,7 +625,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller $base = str_replace( '(?P[\d]+)', $product_id, $this->rest_base ); $links = array( 'self' => array( - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $variation->get_variation_id() ) ), + 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $variation->get_id() ) ), ), 'collection' => array( 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index 348eabb1bf1..0d00e2a7f0f 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -281,23 +281,12 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { $images = array(); $attachment_ids = array(); - if ( $product->is_type( 'variation' ) ) { - if ( has_post_thumbnail( $product->get_variation_id() ) ) { - // Add variation image if set. - $variation = wc_get_product( $product->get_variation_id() ); - $attachment_ids[] = $variation->get_image_id(); - } elseif ( has_post_thumbnail( $product->get_id() ) ) { - // Otherwise use the parent product featured image if set. - $attachment_ids[] = $product->get_image_id(); - } - } else { - // Add featured image. - if ( has_post_thumbnail( $product->get_id() ) ) { - $attachment_ids[] = $product->get_image_id(); - } - // Add gallery images. - $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); + // Add featured image. + if ( has_post_thumbnail( $product->get_id() ) ) { + $attachment_ids[] = $product->get_image_id(); } + // Add gallery images. + $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); // Build image data. foreach ( $attachment_ids as $position => $attachment_id ) { @@ -459,24 +448,6 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { return $attributes; } - /** - * Get product menu order. - * - * @param WC_Product $product - * @return int - */ - protected function get_product_menu_order( $product ) { - $post = get_post( $product->get_id() ); - $menu_order = $post->menu_order; - - if ( $product->is_type( 'variation' ) ) { - $variation = get_post( $product->get_variation_id() ); - $menu_order = $variation->menu_order; - } - - return $menu_order; - } - /** * Get product data. * @@ -485,7 +456,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { */ protected function get_product_data( $product ) { $data = array( - 'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->get_id(), + 'id' => $product->get_id(), 'name' => $product->get_name(), 'slug' => $product->get_slug(), 'permalink' => $product->get_permalink(), @@ -549,7 +520,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { 'default_attributes' => $this->get_default_attributes( $product ), 'variations' => array(), 'grouped_products' => array(), - 'menu_order' => $this->get_product_menu_order( $product ), + 'menu_order' => $product->get_menu_order(), ); return $data;