From 81b984d5b4129625da02c77c70ec452e913bb35b Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 18 Nov 2011 00:38:46 +0000 Subject: [PATCH] Sales logic fix, clear cache on upgrade --- admin/admin-install.php | 8 +++++--- classes/product.class.php | 7 ++++--- classes/product_variation.class.php | 4 ++-- classes/woocommerce.class.php | 2 +- readme.txt | 6 +++++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/admin/admin-install.php b/admin/admin-install.php index e141ad348e0..5f5b73d1366 100644 --- a/admin/admin-install.php +++ b/admin/admin-install.php @@ -25,7 +25,7 @@ function activate_woocommerce() { * Install woocommerce */ function install_woocommerce() { - global $woocommerce_settings; + global $woocommerce_settings, $woocommerce; // Do install woocommerce_default_options(); @@ -52,6 +52,9 @@ function install_woocommerce() { endif; endif; + // Clear cache + $woocommerce->clear_product_transients(); + // Update version update_option( "woocommerce_db_version", WOOCOMMERCE_VERSION ); } @@ -61,11 +64,10 @@ function install_woocommerce() { */ add_action('admin_init', 'install_woocommerce_redirect'); function install_woocommerce_redirect() { - global $pagenow, $woocommerce; + global $pagenow; if ( is_admin() && isset( $_GET['activate'] ) && ($_GET['activate'] == true) && $pagenow == 'plugins.php' && get_option( "woocommerce_installed" ) == 1 ) : - $woocommerce->clear_product_transients(); update_option( "woocommerce_installed", 0 ); flush_rewrite_rules( false ); wp_redirect(admin_url('admin.php?page=woocommerce&installed=true')); diff --git a/classes/product.class.php b/classes/product.class.php index c8d1ad66502..dd7df4d7b50 100644 --- a/classes/product.class.php +++ b/classes/product.class.php @@ -161,7 +161,7 @@ class woocommerce_product { if ( false === ( $this->children = get_transient( $transient_name ) ) ) : - $this->children = get_posts( 'post_parent='.$this->id.'&post_type='.$child_post_type.'&orderby=menu_order&order=ASC&fields=ids&post_status=any&numberposts=-1' ); + $this->children = get_posts( 'post_parent=' . $this->id . '&post_type=' . $child_post_type . '&orderby=menu_order&order=ASC&fields=ids&post_status=any&numberposts=-1' ); set_transient( $transient_name, $this->children ); @@ -456,8 +456,9 @@ class woocommerce_product { if ( $this->has_child() ) : foreach ($this->get_children() as $child_id) : - $sale_price = get_post_meta( $child_id, 'sale_price', true); - if ( $sale_price > 0 && $sale_price == $this->price ) return true; + $sale_price = get_post_meta( $child_id, 'sale_price', true ); + $regular_price = get_post_meta( $child_id, 'price', true ); + if ( $sale_price > 0 && $sale_price < $regular_price ) return true; endforeach; else : diff --git a/classes/product_variation.class.php b/classes/product_variation.class.php index 0066f4f55bb..2cb5bfb0a42 100644 --- a/classes/product_variation.class.php +++ b/classes/product_variation.class.php @@ -49,8 +49,8 @@ class woocommerce_product_variation extends woocommerce_product { // Define the data we're going to load from the parent: Key => Default value $load_data = array( 'sku' => $this->id, - 'downloadable' => 'no', - 'virtual' => 'no', + //'downloadable' => 'no', + //'virtual' => 'no', 'price' => 0, 'visibility' => 'hidden', 'stock' => 0, diff --git a/classes/woocommerce.class.php b/classes/woocommerce.class.php index 1606be2f7e4..8d8a0bd5c64 100644 --- a/classes/woocommerce.class.php +++ b/classes/woocommerce.class.php @@ -326,7 +326,7 @@ class woocommerce { /** * Clear Product Transients */ - function clear_product_transients( $post_id = null ) { + function clear_product_transients( $post_id = 0 ) { global $wpdb; delete_transient('woocommerce_products_onsale'); diff --git a/readme.txt b/readme.txt index 10815ccb253..fd882c5b528 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sh Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@woothemes.com&item_name=Donation+for+WooCommerce Requires at least: 3.1 Tested up to: 3.3 -Stable tag: 1.2.2 +Stable tag: 1.2.3 An e-commerce toolkit that helps you sell anything. Beautifully. @@ -82,6 +82,10 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo == Changelog == += 1.2.4 - 18/11/2011 = +* More sale price logic fixes for variations. Now correctly compares variation's prices. +* Clear cache on upgrade + = 1.2.3 - 17/11/2011 = * Fix for sale price logic * Related products array_diff fix