Backorder handling. Closes #835.

This commit is contained in:
Mike Jolley 2012-07-17 19:11:14 +01:00
parent 6fe7e831b2
commit 1be0b9f8f2
6 changed files with 49 additions and 29 deletions

View File

@ -353,7 +353,7 @@ class WC_Checkout {
// Cart items
$order_items = array();
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) :
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
@ -363,25 +363,30 @@ class WC_Checkout {
$item_meta->new_order_item( $values );
// Store variation data in meta so admin can view it
if ($values['variation'] && is_array($values['variation'])) :
foreach ($values['variation'] as $key => $value) :
$item_meta->add( esc_attr(str_replace('attribute_', '', $key)), $value );
endforeach;
endif;
if ( $values['variation'] && is_array( $values['variation'] ) ) {
foreach ( $values['variation'] as $key => $value ) {
$item_meta->add( esc_attr( str_replace( 'attribute_', '', $key ) ), $value );
}
}
$order_items[] = apply_filters('new_order_item', array(
// Store backorder status
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) )
$item_meta->add( __( 'Backordered', 'woocommerce' ), $values['quantity'] - max( 0, $_product->get_total_stock() ) );
$order_items[] = apply_filters( 'new_order_item', array(
'id' => $values['product_id'],
'variation_id' => $values['variation_id'],
'name' => $_product->get_title(),
'qty' => (int) $values['quantity'],
'item_meta' => $item_meta->meta,
'line_subtotal' => rtrim(rtrim(number_format($values['line_subtotal'], 4, '.', ''), '0'), '.'), // Line subtotal (before discounts)
'line_subtotal_tax' => rtrim(rtrim(number_format($values['line_subtotal_tax'], 4, '.', ''), '0'), '.'), // Line tax (before discounts)
'line_total' => rtrim(rtrim(number_format($values['line_total'], 4, '.', ''), '0'), '.'), // Line total (after discounts)
'line_tax' => rtrim(rtrim(number_format($values['line_tax'], 4, '.', ''), '0'), '.'), // Line Tax (after discounts)
'tax_class' => $_product->get_tax_class() // Tax class (adjusted by filters)
), $values);
endforeach;
'line_subtotal' => woocommerce_format_decimal( $values['line_subtotal'] ), // Line subtotal (before discounts)
'line_subtotal_tax' => woocommerce_format_decimal( $values['line_subtotal_tax'] ), // Line tax (before discounts)
'line_total' => woocommerce_format_decimal( $values['line_total'] ), // Line total (after discounts)
'line_tax' => woocommerce_format_decimal( $values['line_tax'] ), // Line Tax (after discounts)
'tax_class' => $_product->get_tax_class() // Tax class (adjusted by filters)
), $values );
}
// Check order items for errors
do_action('woocommerce_check_new_order_items', $order_items);

View File

@ -370,20 +370,19 @@ class WC_Product {
/** Returns whether or not the product is in stock */
function is_in_stock() {
if ($this->managing_stock()) :
if (!$this->backorders_allowed()) :
if ($this->get_total_stock()==0 || $this->get_total_stock()<0) :
if ( $this->managing_stock() ) :
if ( ! $this->backorders_allowed() ) :
if ( $this->get_total_stock() < 1 ) :
return false;
else :
if ($this->stock_status=='instock') return true;
if ( $this->stock_status == 'instock' ) return true;
return false;
endif;
else :
if ($this->stock_status=='instock') return true;
return false;
return true;
endif;
endif;
if ($this->stock_status=='instock') return true;
if ( $this->stock_status == 'instock' ) return true;
return false;
}
@ -399,6 +398,14 @@ class WC_Product {
return false;
}
/**
* is_on_backorder function.
*/
function is_on_backorder( $qty_in_cart = 0 ) {
if ( $this->managing_stock() && $this->backorders_allowed() && ( $this->get_total_stock() - $qty_in_cart ) < 0 ) return true;
return false;
}
/**
* Returns number of items available for sale.
*

View File

@ -3,8 +3,8 @@ Contributors: woothemes, mikejolley, jameskoster, CoenJacobs
Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, affiliate, store, sales, sell, shop, shopping, cart, checkout, configurable, variable, widgets, reports, download, downloadable, digital, inventory, stock, reports, shipping, tax
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@woothemes.com&item_name=Donation+for+WooCommerce
Requires at least: 3.3
Tested up to: 3.4
Stable tag: 1.5.8
Tested up to: 3.4.1
Stable tag: 1.6.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@ -150,7 +150,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
== Changelog ==
= 1.6 - xx/xx/2012 =
= 1.6.0 - 17/07/2012 =
* Feature - Support for ounces
* Feature - Restore coupon usage count after order cancellation
* Feature - Added bulk actions to bulk change order status to processing or completed
@ -176,6 +176,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - woocommerce_sortable_taxonomies filter
* Tweak - Split up frontend scripts so they can be loaded when needed.
* Tweak - Set session_name to avoid conflicting sessions across installs.
* Tweak - Tweaked backorder handling to allow out of stock to be bought, and show 'backorder' notification is cart qty > stock
* Fix - Widget init function conflict with widget logic
* Fix - PLN currency code
* Fix - Variation get shipping class ID

View File

@ -58,7 +58,7 @@ global $woocommerce;
echo $woocommerce->cart->get_item_data( $values );
// Backorder notification
if ( $_product->backorders_require_notification() && $_product->get_total_stock() < 1 )
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) )
echo '<p class="backorder_notification">' . __('Available on backorder', 'woocommerce') . '</p>';
?>
</td>

View File

@ -403,12 +403,19 @@ function woocommerce_price( $price, $args = array() ) {
}
/**
* Trim trailing zeros
* Trim trailing zeros off prices
**/
function woocommerce_trim_zeros( $price ) {
return preg_replace('/'.preg_quote(get_option('woocommerce_price_decimal_sep'), '/').'0++$/', '', $price);
}
/**
* Formal decimal numbers - format to 4 dp and remove trailing zeros
**/
function woocommerce_format_decimal( $number ) {
return rtrim( rtrim( number_format( $number, 4, '.', '' ), '0' ), '.' );
}
/**
* Clean variables
**/

View File

@ -3,11 +3,11 @@
* Plugin Name: WooCommerce
* Plugin URI: http://www.woothemes.com/woocommerce/
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
* Version: 1.6.0 beta1
* Version: 1.6.0
* Author: WooThemes
* Author URI: http://woothemes.com
* Requires at least: 3.3
* Tested up to: 3.4
* Tested up to: 3.4.1
*
* Text Domain: woocommerce
* Domain Path: /languages/
@ -32,7 +32,7 @@ class Woocommerce {
/** Version ***************************************************************/
var $version = '1.5.8';
var $version = '1.6.0';
/** URLS ******************************************************************/