Permalink
Browse files

variations solid individually handling

  • Loading branch information...
1 parent b38f043 commit aa2bf617ab31d78fc66260c6cbb0c5daf29478ab @mikejolley mikejolley committed May 11, 2012
Showing with 21 additions and 9 deletions.
  1. +8 −3 assets/js/woocommerce.js
  2. +1 −1 assets/js/woocommerce.min.js
  3. +9 −3 classes/class-wc-cart.php
  4. +1 −0 readme.txt
  5. +2 −1 woocommerce-template.php
  6. +0 −1 woocommerce.php
View
@@ -411,20 +411,25 @@ jQuery(document).ready(function($) {
$('.product_meta').find('.sku').text('');
}
+ $('.single_variation_wrap').find('.quantity').show();
+
if (variation.min_qty) {
$('.single_variation_wrap').find('input[name=quantity]').attr('data-min', variation.min_qty).val(variation.min_qty);
} else {
$('.single_variation_wrap').find('input[name=quantity]').removeAttr('data-min');
}
- if (variation.max_qty) {
+ if ( variation.max_qty ) {
$('.single_variation_wrap').find('input[name=quantity]').attr('data-max', variation.max_qty);
} else {
$('.single_variation_wrap').find('input[name=quantity]').removeAttr('data-max');
}
- if (variation.is_virtual=='yes' && variation.is_downloadable=='yes' && woocommerce_params.option_limit_download_qty=='yes') {
- $('.single_variation_wrap').find('input[name=quantity]').attr('data-max', 1);
+ alert(variation.is_sold_individually);
+
+ if ( variation.is_sold_individually == 'yes' ) {
+ $('.single_variation_wrap').find('input[name=quantity]').val('1');
+ $('.single_variation_wrap').find('.quantity').hide();
}
$('.single_variation_wrap').slideDown('200').trigger('variationWrapShown').trigger('show_variation'); // depreciated variationWrapShown

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -615,6 +615,10 @@ function add_to_cart( $product_id, $quantity = 1, $variation_id = '', $variation
else
$product_data = new WC_Product( $product_id );
+ // Force quantity to 1 if sold individually
+ if ( $product_data->is_sold_individually() )
+ $quantity = 1;
+
// Type/Exists check
if ( $product_data->is_type('external') || ! $product_data->exists() ) {
$woocommerce->add_error( __('This product cannot be purchased.', 'woocommerce') );
@@ -637,9 +641,11 @@ function add_to_cart( $product_id, $quantity = 1, $variation_id = '', $variation
}
// Downloadable/virtual qty check
- if ( get_option('woocommerce_limit_downloadable_product_qty')=='yes' && $product_data->is_downloadable() && $product_data->is_virtual() ) {
- $qty = ( $cart_item_key ) ? $this->cart_contents[$cart_item_key]['quantity'] + $quantity : $quantity;
- if ( $qty > 1 ) {
+ if ( $product_data->is_sold_individually() ) {
+ $in_cart_quantity = ( $cart_item_key ) ? $this->cart_contents[$cart_item_key]['quantity'] + $quantity : $quantity;
+
+ // If its greater than 1, its already in the cart
+ if ( $in_cart_quantity > 1 ) {
$woocommerce->add_error( sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), __('You already have this item in your cart.', 'woocommerce') ) );
return false;
}
View
@@ -150,6 +150,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
= 1.5.6 =
* Tweak - When the count of available shipping methods changes, reset to default
* Tweak - Optimisations to monthly and product reports
+* Tweak - Individually sold variation handling
= 1.5.5 - 10/05/2012 =
* Feature - New 'default' sorting order using menu_order, with drag and drop sorting (based on http://wordpress.org/extend/plugins/simple-page-ordering/)
View
@@ -353,7 +353,8 @@ function woocommerce_variable_add_to_cart() {
'min_qty' => 1,
'max_qty' => $variation->stock,
'is_downloadable' => $variation->is_downloadable() ,
- 'is_virtual' => $variation->is_virtual()
+ 'is_virtual' => $variation->is_virtual(),
+ 'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
) , $product, $variation );
}
}
View
@@ -985,7 +985,6 @@ function frontend_scripts() {
'update_order_review_nonce' => wp_create_nonce("update-order-review"),
'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"),
'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'),
- 'option_limit_download_qty' => get_option('woocommerce_limit_downloadable_product_qty'),
'checkout_url' => add_query_arg( 'action', 'woocommerce-checkout', $this->ajax_url() ),
'option_ajax_add_to_cart' => get_option('woocommerce_enable_ajax_add_to_cart'),
'is_checkout' => ( is_page(woocommerce_get_page_id('checkout')) ) ? 1 : 0,

0 comments on commit aa2bf61

Please sign in to comment.