Updated get methods on REST API for variations

This commit is contained in:
Claudio Sanches 2016-11-10 17:24:42 -02:00
parent 4083f5b8d7
commit 9fd64f49e4
2 changed files with 10 additions and 13 deletions

View File

@ -131,33 +131,32 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
*/
public function prepare_item_for_response( $post, $request ) {
$variation = wc_get_product( $post );
$post_data = get_post( $variation->get_variation_id() );
$data = array(
'id' => $variation->get_variation_id(),
'date_created' => wc_rest_prepare_date_response( $post_data->post_date_gmt ),
'date_modified' => wc_rest_prepare_date_response( $post_data->post_modified_gmt ),
'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(),
'permalink' => $variation->get_permalink(),
'sku' => $variation->get_sku(),
'price' => $variation->get_price(),
'regular_price' => $variation->get_regular_price(),
'sale_price' => $variation->get_sale_price(),
'date_on_sale_from' => $variation->sale_price_dates_from ? date( 'Y-m-d', $variation->sale_price_dates_from ) : '',
'date_on_sale_to' => $variation->sale_price_dates_to ? date( 'Y-m-d', $variation->sale_price_dates_to ) : '',
'date_on_sale_from' => $variation->get_date_on_sale_from() ? date( 'Y-m-d', $variation->get_date_on_sale_from() ) : '',
'date_on_sale_to' => $variation->get_date_on_sale_to() ? date( 'Y-m-d', $variation->get_date_on_sale_to() ) : '',
'on_sale' => $variation->is_on_sale(),
'visible' => $variation->is_visible(),
'purchasable' => $variation->is_purchasable(),
'virtual' => $variation->is_virtual(),
'downloadable' => $variation->is_downloadable(),
'downloads' => $this->get_downloads( $variation ),
'download_limit' => '' !== $variation->download_limit ? (int) $variation->download_limit : -1,
'download_expiry' => '' !== $variation->download_expiry ? (int) $variation->download_expiry : -1,
'download_limit' => '' !== $variation->get_download_limit() ? (int) $variation->get_download_limit() : -1,
'download_expiry' => '' !== $variation->get_download_expiry() ? (int) $variation->get_download_expiry() : -1,
'tax_status' => $variation->get_tax_status(),
'tax_class' => $variation->get_tax_class(),
'manage_stock' => $variation->managing_stock(),
'stock_quantity' => $variation->get_stock_quantity(),
'in_stock' => $variation->is_in_stock(),
'backorders' => $variation->backorders,
'backorders' => $variation->get_backorders(),
'backorders_allowed' => $variation->backorders_allowed(),
'backordered' => $variation->is_on_backorder(),
'weight' => $variation->get_weight(),

View File

@ -571,12 +571,10 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
continue;
}
$post_data = get_post( $variation->get_variation_id() );
$variations[] = array(
'id' => $variation->get_variation_id(),
'date_created' => wc_rest_prepare_date_response( $post_data->post_date_gmt ),
'date_modified' => wc_rest_prepare_date_response( $post_data->post_modified_gmt ),
'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() ),
'permalink' => $variation->get_permalink(),
'description' => $variation->get_variation_description(),
'sku' => $variation->get_sku(),