This commit is contained in:
Manos Psychogyiopoulos 2012-07-10 20:15:04 +03:00
commit ceb286fee2
11 changed files with 123 additions and 40 deletions

View File

@ -240,10 +240,10 @@ jQuery( function($){
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var size = $('table.woocommerce_order_items tbody tr.item').size();
$.each( add_item_ids, function( index, value ) { $.each( add_item_ids, function( index, value ) {
var size = $('table.woocommerce_order_items tbody tr.item').size();
var data = { var data = {
action: 'woocommerce_add_order_item', action: 'woocommerce_add_order_item',
item_to_add: value, item_to_add: value,
@ -266,6 +266,8 @@ jQuery( function($){
$('table.woocommerce_order_items').unblock(); $('table.woocommerce_order_items').unblock();
} }
}); });
size++;
}); });

File diff suppressed because one or more lines are too long

View File

@ -116,7 +116,13 @@ class WC_Coupon {
/** Increase usage count */ /** Increase usage count */
function inc_usage_count() { function inc_usage_count() {
$this->usage_count++; $this->usage_count++;
update_post_meta($this->id, 'usage_count', $this->usage_count); update_post_meta( $this->id, 'usage_count', $this->usage_count );
}
/** Decrease usage count */
function dcr_usage_count() {
$this->usage_count--;
update_post_meta( $this->id, 'usage_count', $this->usage_count );
} }
/** /**

View File

@ -688,21 +688,35 @@ class WC_Order {
$old_status = get_term_by( 'slug', sanitize_title( $this->status ), 'shop_order_status'); $old_status = get_term_by( 'slug', sanitize_title( $this->status ), 'shop_order_status');
$new_status = get_term_by( 'slug', sanitize_title( $new_status_slug ), 'shop_order_status'); $new_status = get_term_by( 'slug', sanitize_title( $new_status_slug ), 'shop_order_status');
if ($new_status) { if ($new_status) {
wp_set_object_terms($this->id, array( $new_status->slug ), 'shop_order_status', false); wp_set_object_terms($this->id, array( $new_status->slug ), 'shop_order_status', false);
if ( $this->status != $new_status->slug ) { if ( $this->status != $new_status->slug ) {
// Status was changed // Status was changed
do_action( 'woocommerce_order_status_' . $new_status->slug , $this->id ); do_action( 'woocommerce_order_status_' . $new_status->slug , $this->id );
do_action( 'woocommerce_order_status_' . $this->status . '_to_' . $new_status->slug, $this->id ); do_action( 'woocommerce_order_status_' . $this->status . '_to_' . $new_status->slug, $this->id );
$this->add_order_note( $note . sprintf( __('Order status changed from %s to %s.', 'woocommerce'), __($old_status->name, 'woocommerce'), __($new_status->name, 'woocommerce') ) );
// Date
if ($new_status->slug=='completed') update_post_meta( $this->id, '_completed_date', current_time('mysql') );
// Sales $this->add_order_note( $note . sprintf( __('Order status changed from %s to %s.', 'woocommerce'), __( $old_status->name, 'woocommerce' ), __( $new_status->name, 'woocommerce' ) ) );
if ($new_status->slug=='processing' || $new_status->slug=='completed' || $new_status->slug=='on-hold') $this->record_product_sales();
// Record the completed date of the order
if ( $new_status->slug == 'completed' )
update_post_meta( $this->id, '_completed_date', current_time('mysql') );
if ( $new_status->slug == 'processing' || $new_status->slug == 'completed' || $new_status->slug == 'on-hold' ) {
// Record the sales
$this->record_product_sales();
// Increase coupon usage counts
$this->increase_coupon_usage_counts();
}
// If the order is cancelled, restore used coupons
if ( $new_status->slug == 'cancelled' )
$this->decrease_coupon_usage_counts();
} }
@ -785,20 +799,77 @@ class WC_Order {
*/ */
function record_product_sales() { function record_product_sales() {
if ( get_post_meta( $this->id, '_recorded_sales', true )=='yes' ) return; if ( get_post_meta( $this->id, '_recorded_sales', true ) == 'yes' )
return;
if (sizeof($this->get_items())>0) foreach ($this->get_items() as $item) : if ( sizeof( $this->get_items() ) > 0 ) {
if ($item['id']>0) : foreach ( $this->get_items() as $item ) {
$sales = (int) get_post_meta( $item['id'], 'total_sales', true ); if ( $item['id'] > 0 ) {
$sales += (int) $item['qty']; $sales = (int) get_post_meta( $item['id'], 'total_sales', true );
if ($sales) update_post_meta( $item['id'], 'total_sales', $sales ); $sales += (int) $item['qty'];
endif; if ( $sales )
endforeach; update_post_meta( $item['id'], 'total_sales', $sales );
}
}
}
update_post_meta( $this->id, '_recorded_sales', 'yes' ); update_post_meta( $this->id, '_recorded_sales', 'yes' );
}
/**
* Increase applied coupon counts
*/
function get_used_coupons() {
$coupons = get_post_meta( $this->id, 'coupons', true );
return array_map( 'trim', explode( ',', $coupons ) );
} }
/**
* Increase applied coupon counts
*/
function increase_coupon_usage_counts() {
global $woocommerce;
if ( get_post_meta( $this->id, '_recorded_coupon_usage_counts', true ) == 'yes' )
return;
if ( sizeof( $this->get_used_coupons() ) > 0 ) {
foreach ( $this->get_used_coupons() as $code ) {
if ( ! $code )
continue;
$coupon = $woocommerce->coupon( $code );
$coupon->inc_usage_count();
}
}
update_post_meta( $this->id, '_recorded_coupon_usage_counts', 'yes' );
}
/**
* Decrease applied coupon counts
*/
function decrease_coupon_usage_counts() {
global $woocommerce;
if ( get_post_meta( $this->id, '_recorded_coupon_usage_counts', true ) != 'yes' )
return;
if ( sizeof( $this->get_used_coupons() ) > 0 ) {
foreach ( $this->get_used_coupons() as $code ) {
if ( ! $code )
continue;
$coupon = $woocommerce->coupon( $code );
$coupon->dcr_usage_count();
}
}
delete_post_meta( $this->id, '_recorded_coupon_usage_counts' );
}
/** /**
* Reduce stock levels * Reduce stock levels
*/ */

View File

@ -152,12 +152,14 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
= 1.xxxx - xx/xx/2012 = = 1.xxxx - xx/xx/2012 =
* Feature - Support for ounces * Feature - Support for ounces
* Feature - Restore coupon usage count after order cancellation
* Tweak - Better WC_Product::get_image() function. Fixed instances where we were not echo'ing. * Tweak - Better WC_Product::get_image() function. Fixed instances where we were not echo'ing.
* Tweak - Pass valuable object data to woocommerce_email_headers and woocommerce_email_attachments filters. * Tweak - Pass valuable object data to woocommerce_email_headers and woocommerce_email_attachments filters.
* Tweak - Cart.php tweak: Disable hyperlinks for hidden products. * Tweak - Cart.php tweak: Disable hyperlinks for hidden products.
* Tweak - Cart widget filters added and renamed for consistency. * Tweak - Cart widget filters added and renamed for consistency.
* Tweak - Payment gateway API tweaks - get_title, get_icon, get_description * Tweak - Payment gateway API tweaks - get_title, get_icon, get_description
* Tweak - Price filter widgets takes you back to page 1. * Tweak - Price filter widgets takes you back to page 1.
* Tweak - Changed microdata for offers/product so its picked up by google
* Fix - Widget init function conflict with widget logic * Fix - Widget init function conflict with widget logic
* Fix - PLN currency code * Fix - PLN currency code
* Fix - Variation get shipping class ID * Fix - Variation get shipping class ID
@ -170,6 +172,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Fix - Conflict with WPML joins * Fix - Conflict with WPML joins
* Fix - IPN check with PayPal redesign * Fix - IPN check with PayPal redesign
* Fix - When showing attributes, check taxonomies exist * Fix - When showing attributes, check taxonomies exist
* Fix - When adding multiple items to an order, saving lost all by the first
* Localization - LI and CH address locales * Localization - LI and CH address locales
* Localization - Switch fields in array if postcode_before_city is set * Localization - Switch fields in array if postcode_before_city is set

View File

@ -17,11 +17,7 @@ if( $product->get_price() === '') return;
endif; endif;
?> ?>
<?php if (!$product->is_in_stock()) : ?> <?php if ( $product->is_in_stock() ) : ?>
<link itemprop="availability" href="http://schema.org/OutOfStock">
<?php else : ?>
<link itemprop="availability" href="http://schema.org/InStock">
<?php do_action('woocommerce_before_add_to_cart_form'); ?> <?php do_action('woocommerce_before_add_to_cart_form'); ?>

View File

@ -1,8 +1,14 @@
<?php <?php
/** /**
* Single Product Price * Single Product Price, including microdata for SEO
*/ */
global $post, $product; global $post, $product;
?> ?>
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p> <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>

View File

@ -127,17 +127,6 @@ function woocommerce_update_catalog_ordering() {
if (isset($_REQUEST['sort']) && $_REQUEST['sort'] != '') $_SESSION['orderby'] = esc_attr($_REQUEST['sort']); if (isset($_REQUEST['sort']) && $_REQUEST['sort'] != '') $_SESSION['orderby'] = esc_attr($_REQUEST['sort']);
} }
/**
* Increase coupon usage count
*/
function woocommerce_increase_coupon_counts() {
global $woocommerce;
if ($applied_coupons = $woocommerce->cart->get_applied_coupons()) foreach ($applied_coupons as $code) :
$coupon = new WC_Coupon( $code );
$coupon->inc_usage_count();
endforeach;
}
/** /**
* Remove from cart/update * Remove from cart/update
**/ **/

View File

@ -142,7 +142,6 @@ add_action( 'wp_head', 'woocommerce_products_rss_feed' );
/* Order actions */ /* Order actions */
add_action( 'init', 'woocommerce_cancel_order' ); add_action( 'init', 'woocommerce_cancel_order' );
add_action( 'init', 'woocommerce_order_again' ); add_action( 'init', 'woocommerce_order_again' );
add_action( 'woocommerce_new_order', 'woocommerce_increase_coupon_counts' );
/* Star Ratings */ /* Star Ratings */
add_action( 'comment_post', 'woocommerce_add_comment_rating', 1 ); add_action( 'comment_post', 'woocommerce_add_comment_rating', 1 );

View File

@ -86,7 +86,7 @@ if ( ! function_exists( 'woocommerce_single_product_content' ) ) {
<?php do_action( 'woocommerce_before_single_product_summary' ); ?> <?php do_action( 'woocommerce_before_single_product_summary' ); ?>
<div class="summary" itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <div class="summary">
<?php do_action( 'woocommerce_single_product_summary' ); ?> <?php do_action( 'woocommerce_single_product_summary' ); ?>
@ -493,7 +493,7 @@ if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {
$defaults = array( $defaults = array(
'delimiter' => ' &rsaquo; ', 'delimiter' => ' &rsaquo; ',
'wrap_before' => '<div id="breadcrumb">', 'wrap_before' => '<div id="breadcrumb" itemprop="breadcrumb">',
'wrap_after' => '</div>', 'wrap_after' => '</div>',
'before' => '', 'before' => '',
'after' => '', 'after' => '',

View File

@ -1057,15 +1057,26 @@ class Woocommerce {
if ( ! class_exists('WC_Validation') ) include( 'classes/class-wc-validation.php' ); if ( ! class_exists('WC_Validation') ) include( 'classes/class-wc-validation.php' );
return new WC_Validation(); return new WC_Validation();
} }
/**
* Init a coupon
*/
function coupon( $code ) {
if ( ! class_exists('WC_Coupon') ) include( 'classes/class-wc-coupon.php' );
return new WC_Coupon( $code );
}
/** /**
* Email Class * Init the mailer and call the notifications for the current filter
*/ */
function send_transactional_email( $args = array() ) { function send_transactional_email( $args = array() ) {
$this->mailer(); $this->mailer();
do_action( current_filter() . '_notification' , $args ); do_action( current_filter() . '_notification' , $args );
} }
/**
* Email Class
*/
function mailer() { function mailer() {
// Init mail class // Init mail class
if ( ! class_exists('WC_Email') ) { if ( ! class_exists('WC_Email') ) {