Fix comparison for is_on_sale and remove download_type from WC_Product.

This commit is contained in:
Justin Shreve 2016-10-28 08:13:46 -07:00 committed by Mike Jolley
parent 37c8e62fcf
commit 1985620f33
3 changed files with 37 additions and 62 deletions

View File

@ -328,6 +328,9 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
case 'product_type' : // @todo What do we do with 3rd party use of product_type now it's hardcoded?
$value = $this->get_type();
break;
case 'download_type' :
return 'standard';
break;
case 'product_image_gallery' :
$value = $this->get_gallery_attachment_ids();
break;

View File

@ -72,7 +72,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
'gallery_attachment_ids' => array(),
'download_limit' => -1,
'download_expiry' => -1,
'download_type' => 'standard',
);
/**
@ -545,16 +544,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
return $this->data['virtual'];
}
/**
* Get downloadable.
*
* @since 2.7.0
* @return bool
*/
public function get_downloadable() {
return $this->data['downloadable'];
}
/**
* Returns the gallery attachment ids.
*
@ -564,16 +553,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
return apply_filters( 'woocommerce_product_gallery_attachment_ids', array_filter( array_filter( $this->data['gallery_attachment_ids'] ), 'wp_attachment_is_image' ), $this );
}
/**
* Get download limit.
*
* @since 2.7.0
* @return int
*/
public function get_download_limit() {
return $this->data['download_limit'];
}
/**
* Get shipping class ID.
*
@ -605,13 +584,23 @@ class WC_Product extends WC_Abstract_Legacy_Product {
}
/**
* Get download type.
* Get downloadable.
*
* @since 2.7.0
* @return string
* @return bool
*/
public function get_download_type() {
return $this->data['download_type'];
public function get_downloadable() {
return $this->data['downloadable'];
}
/**
* Get download limit.
*
* @since 2.7.0
* @return int
*/
public function get_download_limit() {
return $this->data['download_limit'];
}
/**
@ -1068,16 +1057,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
$this->data['virtual'] = wc_string_to_bool( $virtual );
}
/**
* Set if the product is downloadable.
*
* @since 2.7.0
* @param bool|string
*/
public function set_downloadable( $downloadable ) {
$this->data['downloadable'] = wc_string_to_bool( $downloadable );
}
/**
* Set shipping class ID.
*
@ -1088,6 +1067,16 @@ class WC_Product extends WC_Abstract_Legacy_Product {
$this->data['shipping_class_id'] = absint( $id );
}
/**
* Set if the product is downloadable.
*
* @since 2.7.0
* @param bool|string
*/
public function set_downloadable( $downloadable ) {
$this->data['downloadable'] = wc_string_to_bool( $downloadable );
}
/**
* Set downloads.
*
@ -1153,16 +1142,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
}
}
/**
* Set gallery attachment ids.
*
* @since 2.7.0
* @param array $gallery_ids
*/
public function set_gallery_attachment_ids( $gallery_ids ) {
$this->data['gallery_attachment_ids'] = $gallery_ids;
}
/**
* Set download limit.
*
@ -1184,13 +1163,13 @@ class WC_Product extends WC_Abstract_Legacy_Product {
}
/**
* Set download type.
* Set gallery attachment ids.
*
* @since 2.7.0
* @param string $download_type
* @param array $gallery_ids
*/
public function set_download_type( $download_type ) {
$this->data['download_type'] = $download_type;
public function set_gallery_attachment_ids( $gallery_ids ) {
$this->data['gallery_attachment_ids'] = $gallery_ids;
}
/**
@ -1309,7 +1288,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
'gallery_attachment_ids' => array_filter( explode( ',', get_post_meta( $id, '_product_image_gallery', true ) ) ),
'download_limit' => get_post_meta( $id, '_download_limit', true ),
'download_expiry' => get_post_meta( $id, '_download_expiry', true ),
'download_type' => get_post_meta( $id, '_download_type', true ),
'thumbnail_id' => get_post_thumbnail_id( $id ),
) );
if ( $this->is_on_sale() ) {
@ -1475,7 +1453,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
update_post_meta( $id, '_product_image_gallery', implode( ',', $this->get_gallery_attachment_ids() ) );
update_post_meta( $id, '_download_limit', $this->get_download_limit() );
update_post_meta( $id, '_download_expiry', $this->get_download_expiry() );
update_post_meta( $id, '_download_type', $this->get_download_type() );
if ( update_post_meta( $id, '_featured', $this->get_featured() ) ) {
delete_transient( 'wc_featured_products' );
@ -1661,14 +1638,14 @@ class WC_Product extends WC_Abstract_Legacy_Product {
* @return bool
*/
public function is_on_sale() {
if ( ! empty( $this->get_sale_price() ) && $this->get_regular_price() > $this->get_sale_price() ) {
if ( '' !== (string) $this->get_sale_price() && $this->get_regular_price() > $this->get_sale_price() ) {
$onsale = true;
if ( ! empty( $this->get_date_on_sale_from() ) && $this->get_date_on_sale_from() > strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
if ( '' !== (string) $this->get_date_on_sale_from() && $this->get_date_on_sale_from() > strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
$onsale = false;
}
if ( ! empty( $this->get_date_on_sale_to() ) && $this->get_date_on_sale_to() < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
if ( '' !== (string) $this->get_date_on_sale_to() && $this->get_date_on_sale_to() < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
$onsale = false;
}
} else {

View File

@ -513,7 +513,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'downloads' => $this->get_downloads( $product ),
'download_limit' => $product->get_download_limit(),
'download_expiry' => $product->get_download_expiry(),
'download_type' => $product->get_download_type(),
'download_type' => 'standard',
'external_url' => $product->is_type( 'external' ) ? $product->get_product_url() : '',
'button_text' => $product->is_type( 'external' ) ? $product->get_button_text() : '',
'tax_status' => $product->get_tax_status(),
@ -1392,11 +1392,6 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
if ( isset( $request['download_expiry'] ) ) {
$product->set_download_expiry( $request['download_expiry'] );
}
// Download type.
if ( isset( $request['download_type'] ) ) {
$product->set_download_type( $request['download_type'] );
}
}
// Product url and button text for external products.
@ -2159,8 +2154,8 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'description' => __( 'Download type, this controls the schema on the front-end.', 'woocommerce' ),
'type' => 'string',
'default' => 'standard',
'enum' => array( 'standard', 'application', 'music' ),
'context' => array( 'view', 'edit' ),
'enum' => array( 'standard' ),
'context' => array( 'view' ),
),
'external_url' => array(
'description' => __( 'Product external URL. Only for external products.', 'woocommerce' ),