Scheduled on sale ignored from sale widget

This commit is contained in:
Mike Jolley 2012-06-27 12:00:24 +01:00
parent 57bf97230d
commit 57fe4db23c
3 changed files with 30 additions and 19 deletions

View File

@ -1105,38 +1105,38 @@ class WC_Product {
* Checks sale data to see if the product is due to go on sale/sale has expired, and updates the main price
*/
function check_sale_price() {
global $woocommerce;
if ($this->sale_price_dates_from && $this->sale_price_dates_from < current_time('timestamp')) :
if ( $this->sale_price_dates_from && $this->sale_price_dates_from < current_time('timestamp') ) {
if ($this->sale_price && $this->price!==$this->sale_price) :
if ( $this->sale_price && $this->price !== $this->sale_price ) {
// Update price
$this->price = $this->sale_price;
update_post_meta($this->id, '_price', $this->price);
update_post_meta( $this->id, '_price', $this->price );
// Grouped product prices and sale status are affected by children
$this->grouped_product_sync();
endif;
}
endif;
}
if ($this->sale_price_dates_to && $this->sale_price_dates_to < current_time('timestamp')) :
if ( $this->sale_price_dates_to && $this->sale_price_dates_to < current_time('timestamp') ) {
if ($this->regular_price && $this->price!==$this->regular_price) :
if ( $this->regular_price && $this->price !== $this->regular_price ) {
$this->price = $this->regular_price;
update_post_meta($this->id, '_price', $this->price);
update_post_meta( $this->id, '_price', $this->price );
// Sale has expired - clear the schedule boxes
update_post_meta($this->id, '_sale_price', '');
update_post_meta($this->id, '_sale_price_dates_from', '');
update_post_meta($this->id, '_sale_price_dates_to', '');
update_post_meta( $this->id, '_sale_price', '' );
update_post_meta( $this->id, '_sale_price_dates_from', '' );
update_post_meta( $this->id, '_sale_price_dates_to', '' );
// Grouped product prices and sale status are affected by children
$this->grouped_product_sync();
endif;
}
endif;
}
}
/**

View File

@ -153,6 +153,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Fix - Widget init function conflict with widget logic
* Fix - PLN currency code
* Fix - Variation get shipping class ID
* Fix - Scheduled on sale ignored from sale widget
= 1.5.8 - 21/06/2012 =
* Tweak - Textarea for notes and enabled HTML

View File

@ -60,9 +60,10 @@ class WooCommerce_Widget_On_Sale extends WP_Widget {
$number = 15;
// Get products on sale
if ( false === ( $product_ids_on_sale = get_transient( 'wc_products_onsale' ) ) ) :
if ( false === ( $product_ids_on_sale = get_transient( 'wc_products_onsale' ) ) ) {
$meta_query = array();
$meta_query[] = array(
'key' => '_sale_price',
'value' => 0,
@ -78,11 +79,19 @@ class WooCommerce_Widget_On_Sale extends WP_Widget {
'fields' => 'id=>parent'
));
$product_ids_on_sale = array_unique(array_merge(array_values($on_sale), array_keys($on_sale)));
$product_ids = array_keys( $on_sale );
$parent_ids = array_values( $on_sale );
// Check for scheduled sales which have not started
foreach ( $product_ids as $key => $id )
if ( get_post_meta( $id, '_sale_price_dates_from', true ) > current_time('timestamp') )
unset( $product_ids[ $key ] );
$product_ids_on_sale = array_unique( array_merge( $product_ids, $parent_ids ) );
set_transient( 'wc_products_onsale', $product_ids_on_sale );
endif;
}
$product_ids_on_sale[] = 0;
@ -95,14 +104,15 @@ class WooCommerce_Widget_On_Sale extends WP_Widget {
'no_found_rows' => 1,
'post_status' => 'publish',
'post_type' => 'product',
'orderby' => 'rand',
'orderby' => 'date',
'order' => 'ASC',
'meta_query' => $meta_query,
'post__in' => $product_ids_on_sale
);
$r = new WP_Query($query_args);
if ($r->have_posts()) :
if ( $r->have_posts() ) :
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>