Remove deprecated get_variation_id()

This commit is contained in:
Claudio Sanches 2016-11-11 12:14:10 -02:00
parent a33b222f0e
commit 638ab62ec3
2 changed files with 9 additions and 38 deletions

View File

@ -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<product_id>[\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 ) ),

View File

@ -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;