API endpoints
This commit is contained in:
parent
1bac579df7
commit
dd1b8e35dc
|
@ -37,8 +37,8 @@
|
|||
'description' => '<a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a>',
|
||||
) );
|
||||
|
||||
$sale_price_dates_from = ( $date = $product_object->get_date_on_sale_from( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = ( $date = $product_object->get_date_on_sale_to( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_from = $product_object->get_date_on_sale_from( 'edit' ) && ( $date = $product_object->get_date_on_sale_from( 'edit' )->getTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = $product_object->get_date_on_sale_to( 'edit' ) && ( $date = $product_object->get_date_on_sale_to( 'edit' )->getTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
|
||||
echo '<p class="form-field sale_price_dates_fields">
|
||||
<label for="_sale_price_dates_from">' . __( 'Sale price dates', 'woocommerce' ) . '</label>
|
||||
|
|
|
@ -125,8 +125,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
'wrapper_class' => 'form-row form-row-last',
|
||||
) );
|
||||
|
||||
$sale_price_dates_from = ( $date = $variation_object->get_date_on_sale_from( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = ( $date = $variation_object->get_date_on_sale_to( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_from = $variation_object->get_date_on_sale_from( 'edit' ) && ( $date = $variation_object->get_date_on_sale_from( 'edit' )->getTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = $variation_object->get_date_on_sale_to( 'edit' ) && ( $date = $variation_object->get_date_on_sale_to( 'edit' )->getTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
|
||||
echo '<div class="form-field sale_price_dates_fields hidden">
|
||||
<p class="form-row form-row-first">
|
||||
|
|
|
@ -153,45 +153,49 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
|
|||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$data = array(
|
||||
'id' => $object->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( $object->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified() ),
|
||||
'description' => $object->get_description(),
|
||||
'permalink' => $object->get_permalink(),
|
||||
'sku' => $object->get_sku(),
|
||||
'price' => $object->get_price(),
|
||||
'regular_price' => $object->get_regular_price(),
|
||||
'sale_price' => $object->get_sale_price(),
|
||||
'date_on_sale_from' => $object->get_date_on_sale_from() ? date( 'Y-m-d', $object->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $object->get_date_on_sale_to() ? date( 'Y-m-d', $object->get_date_on_sale_to() ) : '',
|
||||
'on_sale' => $object->is_on_sale(),
|
||||
'visible' => $object->is_visible(),
|
||||
'purchasable' => $object->is_purchasable(),
|
||||
'virtual' => $object->is_virtual(),
|
||||
'downloadable' => $object->is_downloadable(),
|
||||
'downloads' => $this->get_downloads( $object ),
|
||||
'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
|
||||
'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
|
||||
'tax_status' => $object->get_tax_status(),
|
||||
'tax_class' => $object->get_tax_class(),
|
||||
'manage_stock' => $object->managing_stock(),
|
||||
'stock_quantity' => $object->get_stock_quantity(),
|
||||
'in_stock' => $object->is_in_stock(),
|
||||
'backorders' => $object->get_backorders(),
|
||||
'backorders_allowed' => $object->backorders_allowed(),
|
||||
'backordered' => $object->is_on_backorder(),
|
||||
'weight' => $object->get_weight(),
|
||||
'dimensions' => array(
|
||||
'length' => $object->get_length(),
|
||||
'width' => $object->get_width(),
|
||||
'height' => $object->get_height(),
|
||||
'id' => $object->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ),
|
||||
'description' => $object->get_description(),
|
||||
'permalink' => $object->get_permalink(),
|
||||
'sku' => $object->get_sku(),
|
||||
'price' => $object->get_price(),
|
||||
'regular_price' => $object->get_regular_price(),
|
||||
'sale_price' => $object->get_sale_price(),
|
||||
'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ),
|
||||
'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ),
|
||||
'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ),
|
||||
'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ),
|
||||
'on_sale' => $object->is_on_sale(),
|
||||
'visible' => $object->is_visible(),
|
||||
'purchasable' => $object->is_purchasable(),
|
||||
'virtual' => $object->is_virtual(),
|
||||
'downloadable' => $object->is_downloadable(),
|
||||
'downloads' => $this->get_downloads( $object ),
|
||||
'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
|
||||
'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
|
||||
'tax_status' => $object->get_tax_status(),
|
||||
'tax_class' => $object->get_tax_class(),
|
||||
'manage_stock' => $object->managing_stock(),
|
||||
'stock_quantity' => $object->get_stock_quantity(),
|
||||
'in_stock' => $object->is_in_stock(),
|
||||
'backorders' => $object->get_backorders(),
|
||||
'backorders_allowed' => $object->backorders_allowed(),
|
||||
'backordered' => $object->is_on_backorder(),
|
||||
'weight' => $object->get_weight(),
|
||||
'dimensions' => array(
|
||||
'length' => $object->get_length(),
|
||||
'width' => $object->get_width(),
|
||||
'height' => $object->get_height(),
|
||||
),
|
||||
'shipping_class' => $object->get_shipping_class(),
|
||||
'shipping_class_id' => $object->get_shipping_class_id(),
|
||||
'image' => $this->get_images( $object ),
|
||||
'attributes' => $this->get_attributes( $object ),
|
||||
'menu_order' => $object->get_menu_order(),
|
||||
'meta_data' => $object->get_meta_data(),
|
||||
'shipping_class' => $object->get_shipping_class(),
|
||||
'shipping_class_id' => $object->get_shipping_class_id(),
|
||||
'image' => $this->get_images( $object ),
|
||||
'attributes' => $this->get_attributes( $object ),
|
||||
'menu_order' => $object->get_menu_order(),
|
||||
'meta_data' => $object->get_meta_data(),
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
|
|
|
@ -369,26 +369,30 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
|
||||
$images[] = array(
|
||||
'id' => (int) $attachment_id,
|
||||
'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date_gmt ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified_gmt ),
|
||||
'src' => current( $attachment ),
|
||||
'name' => get_the_title( $attachment_id ),
|
||||
'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
|
||||
'position' => (int) $position,
|
||||
'id' => (int) $attachment_id,
|
||||
'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
|
||||
'src' => current( $attachment ),
|
||||
'name' => get_the_title( $attachment_id ),
|
||||
'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
|
||||
'position' => (int) $position,
|
||||
);
|
||||
}
|
||||
|
||||
// Set a placeholder image if the product has no images set.
|
||||
if ( empty( $images ) ) {
|
||||
$images[] = array(
|
||||
'id' => 0,
|
||||
'date_created' => wc_rest_prepare_date_response( current_time( 'mysql' ) ), // Default to now.
|
||||
'date_modified' => wc_rest_prepare_date_response( current_time( 'mysql' ) ),
|
||||
'src' => wc_placeholder_img_src(),
|
||||
'name' => __( 'Placeholder', 'woocommerce' ),
|
||||
'alt' => __( 'Placeholder', 'woocommerce' ),
|
||||
'position' => 0,
|
||||
'id' => 0,
|
||||
'date_created' => wc_rest_prepare_date_response( current_time( 'mysql' ), false ), // Default to now.
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ), // Default to now.
|
||||
'date_modified' => wc_rest_prepare_date_response( current_time( 'mysql' ), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ),
|
||||
'src' => wc_placeholder_img_src(),
|
||||
'name' => __( 'Placeholder', 'woocommerce' ),
|
||||
'alt' => __( 'Placeholder', 'woocommerce' ),
|
||||
'position' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -528,8 +532,10 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'name' => $product->get_name(),
|
||||
'slug' => $product->get_slug(),
|
||||
'permalink' => $product->get_permalink(),
|
||||
'date_created' => wc_rest_prepare_date_response( $product->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $product->get_date_modified() ),
|
||||
'date_created' => wc_rest_prepare_date_response( $product->get_date_created(), false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $product->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $product->get_date_modified(), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $product->get_date_modified() ),
|
||||
'type' => $product->get_type(),
|
||||
'status' => $product->get_status(),
|
||||
'featured' => $product->is_featured(),
|
||||
|
@ -540,8 +546,10 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'price' => $product->get_price(),
|
||||
'regular_price' => $product->get_regular_price(),
|
||||
'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '',
|
||||
'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to() ) : '',
|
||||
'date_on_sale_from' => wc_rest_prepare_date_response( $product->get_date_on_sale_from(), false ),
|
||||
'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_from() ),
|
||||
'date_on_sale_to' => wc_rest_prepare_date_response( $product->get_date_on_sale_to(), false ),
|
||||
'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_to() ),
|
||||
'price_html' => $product->get_price_html(),
|
||||
'on_sale' => $product->is_on_sale(),
|
||||
'purchasable' => $product->is_purchasable(),
|
||||
|
@ -1354,12 +1362,24 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the product was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the product was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( "The date the product was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __( 'Product type.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
@ -1753,12 +1773,24 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the image was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( "The date the image was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'src' => array(
|
||||
'description' => __( 'Image URL.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
|
|
@ -1049,17 +1049,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( isset( $data['sale_price_dates_from'] ) ) {
|
||||
$date_from = $data['sale_price_dates_from'];
|
||||
} else {
|
||||
$date_from = ( $product->get_date_on_sale_from() ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_from = $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( isset( $data['sale_price_dates_to'] ) ) {
|
||||
$date_to = $data['sale_price_dates_to'];
|
||||
} else {
|
||||
$date_to = ( $product->get_date_on_sale_to() ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
$date_to = $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( $date_to && ! $date_from ) {
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$product->set_date_on_sale_to( $date_to );
|
||||
|
|
|
@ -1534,17 +1534,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( isset( $data['sale_price_dates_from'] ) ) {
|
||||
$date_from = $data['sale_price_dates_from'];
|
||||
} else {
|
||||
$date_from = ( $product->get_date_on_sale_from() ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_from = $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( isset( $data['sale_price_dates_to'] ) ) {
|
||||
$date_to = $data['sale_price_dates_to'];
|
||||
} else {
|
||||
$date_to = ( $product->get_date_on_sale_to() ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
$date_to = $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( $date_to && ! $date_from ) {
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$product->set_date_on_sale_to( $date_to );
|
||||
|
|
|
@ -475,8 +475,8 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'price' => $product->get_price(),
|
||||
'regular_price' => $product->get_regular_price(),
|
||||
'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '',
|
||||
'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to() ) : '',
|
||||
'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '',
|
||||
'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '',
|
||||
'price_html' => $product->get_price_html(),
|
||||
'on_sale' => $product->is_on_sale(),
|
||||
'purchasable' => $product->is_purchasable(),
|
||||
|
@ -553,8 +553,8 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'price' => $variation->get_price(),
|
||||
'regular_price' => $variation->get_regular_price(),
|
||||
'sale_price' => $variation->get_sale_price(),
|
||||
'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() ) : '',
|
||||
'date_on_sale_from' => $variation->get_date_on_sale_from() ? date( 'Y-m-d', $variation->get_date_on_sale_from()->getTimestamp() ) : '',
|
||||
'date_on_sale_to' => $variation->get_date_on_sale_to() ? date( 'Y-m-d', $variation->get_date_on_sale_to()->getTimestamp() ) : '',
|
||||
'on_sale' => $variation->is_on_sale(),
|
||||
'purchasable' => $variation->is_purchasable(),
|
||||
'visible' => $variation->is_visible(),
|
||||
|
|
Loading…
Reference in New Issue