Remove deprecated get_variation_id()
This commit is contained in:
parent
a33b222f0e
commit
638ab62ec3
|
@ -132,7 +132,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
|
||||||
public function prepare_item_for_response( $post, $request ) {
|
public function prepare_item_for_response( $post, $request ) {
|
||||||
$variation = wc_get_product( $post );
|
$variation = wc_get_product( $post );
|
||||||
$data = array(
|
$data = array(
|
||||||
'id' => $variation->get_variation_id(),
|
'id' => $variation->get_id(),
|
||||||
'date_created' => wc_rest_prepare_date_response( $variation->get_date_created() ),
|
'date_created' => wc_rest_prepare_date_response( $variation->get_date_created() ),
|
||||||
'date_modified' => wc_rest_prepare_date_response( $variation->get_date_modified() ),
|
'date_modified' => wc_rest_prepare_date_response( $variation->get_date_modified() ),
|
||||||
'description' => $variation->get_variation_description(),
|
'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 );
|
$base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
|
||||||
$links = array(
|
$links = array(
|
||||||
'self' => 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(
|
'collection' => array(
|
||||||
'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
|
'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
|
||||||
|
|
|
@ -281,23 +281,12 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
||||||
$images = array();
|
$images = array();
|
||||||
$attachment_ids = 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.
|
// Add featured image.
|
||||||
if ( has_post_thumbnail( $product->get_id() ) ) {
|
if ( has_post_thumbnail( $product->get_id() ) ) {
|
||||||
$attachment_ids[] = $product->get_image_id();
|
$attachment_ids[] = $product->get_image_id();
|
||||||
}
|
}
|
||||||
// Add gallery images.
|
// Add gallery images.
|
||||||
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
$attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() );
|
||||||
}
|
|
||||||
|
|
||||||
// Build image data.
|
// Build image data.
|
||||||
foreach ( $attachment_ids as $position => $attachment_id ) {
|
foreach ( $attachment_ids as $position => $attachment_id ) {
|
||||||
|
@ -459,24 +448,6 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
||||||
return $attributes;
|
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.
|
* Get product data.
|
||||||
*
|
*
|
||||||
|
@ -485,7 +456,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
||||||
*/
|
*/
|
||||||
protected function get_product_data( $product ) {
|
protected function get_product_data( $product ) {
|
||||||
$data = array(
|
$data = array(
|
||||||
'id' => (int) $product->is_type( 'variation' ) ? $product->get_variation_id() : $product->get_id(),
|
'id' => $product->get_id(),
|
||||||
'name' => $product->get_name(),
|
'name' => $product->get_name(),
|
||||||
'slug' => $product->get_slug(),
|
'slug' => $product->get_slug(),
|
||||||
'permalink' => $product->get_permalink(),
|
'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 ),
|
'default_attributes' => $this->get_default_attributes( $product ),
|
||||||
'variations' => array(),
|
'variations' => array(),
|
||||||
'grouped_products' => array(),
|
'grouped_products' => array(),
|
||||||
'menu_order' => $this->get_product_menu_order( $product ),
|
'menu_order' => $product->get_menu_order(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
Loading…
Reference in New Issue