sku tweak. Closes #1479.

This commit is contained in:
Mike Jolley 2012-10-08 13:54:31 +01:00
parent bf1d80151d
commit 79324412d4
5 changed files with 20 additions and 9 deletions

View File

@ -9,6 +9,11 @@ jQuery(document).ready(function($) {
.on( 'click', '.reset_variations', function( event ) {
$(this).closest('form.variations_form').find('.variations select').val('').change();
var $sku = $(this).closest('.product').find('.sku');
if ( $sku.attr( 'data-o_sku' ) )
$sku.text( $sku.attr( 'data-o_sku' ) );
return false;
} )
@ -270,11 +275,17 @@ jQuery(document).ready(function($) {
}
var $single_variation_wrap = $variation_form.find('.single_variation_wrap');
if ( variation.sku )
$product.find('.product_meta').find('.sku').text( variation.sku );
else
$product.find('.product_meta').find('.sku').text('');
var $sku = $product.find('.product_meta').find('.sku');
if ( ! $sku.attr( 'data-o_sku' ) )
$sku.attr( 'data-o_sku', $sku.text() );
if ( variation.sku ) {
$sku.text( variation.sku );
} else {
$sku.text( $sku.attr( 'data-o_sku' ) );
}
$single_variation_wrap.find('.quantity').show();

View File

@ -1 +1 @@
jQuery(document).ready(function(e){function t(e,t){var r=[];for(var i=0;i<e.length;i++){var s=e[i],o=s.variation_id;n(s.attributes,t)&&r.push(s)}return r}function n(e,t){var n=!0;for(attr_name in e){var r=e[attr_name],i=t[attr_name];r!==undefined&&i!==undefined&&r.length!=0&&i.length!=0&&r!=i&&(n=!1)}return n}e("form.variations_form").on("click",".reset_variations",function(t){e(this).closest("form.variations_form").find(".variations select").val("").change();return!1}).on("change",".variations select",function(t){$variation_form=e(this).closest("form.variations_form");$variation_form.find("input[name=variation_id]").val("").change();$variation_form.trigger("woocommerce_variation_select_change").trigger("check_variations",["",!1]);e(this).blur();e().uniform&&e.isFunction(e.uniform.update)&&e.uniform.update()}).on("focusin",".variations select",function(t){$variation_form=e(this).closest("form.variations_form");$variation_form.trigger("woocommerce_variation_select_focusin").trigger("check_variations",[e(this).attr("name"),!0])}).on("check_variations",function(n,r,i){var s=!0,o=!1,u=!1,a={},f=e(this),l=f.find(".reset_variations");f.find(".variations select").each(function(){e(this).val().length==0?s=!1:o=!0;if(r&&e(this).attr("name")==r){s=!1;a[e(this).attr("name")]=""}else{value=e(this).val().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/</g,"&lt;").replace(/>/g,"&gt;");a[e(this).attr("name")]=value}});var c=parseInt(f.attr("data-product_id")),h=window["product_variations_"+c];h||(h=window.product_variations);var p=t(h,a);if(s){var d=p.pop();if(d){f.find("input[name=variation_id]").val(d.variation_id).change();f.trigger("found_variation",[d])}else{f.find(".variations select").val("");i||f.trigger("reset_image")}}else{f.trigger("update_variation_values",[p]);i||f.trigger("reset_image");r||f.find(".single_variation_wrap").slideUp("200")}o?l.css("visibility")=="hidden"&&l.css("visibility","visible").hide().fadeIn():l.css("visibility","hidden")}).on("reset_image",function(t){var n=e(this).closest(".product"),r=n.find("div.images img:eq(0)"),i=n.find("div.images a.zoom:eq(0)"),s=r.attr("data-o_src"),o=r.attr("data-o_title"),u=i.attr("data-o_href");if(s&&u&&o){r.attr("src",s).attr("alt",o).attr("title",o);i.attr("href",u).attr("title",o)}}).on("update_variation_values",function(t,n){$variation_form=e(this).closest("form.variations_form");$variation_form.find(".variations select").each(function(t,r){current_attr_select=e(r);current_attr_select.find("option:gt(0)").attr("disabled","disabled");var i=current_attr_select.attr("name");for(num in n){var s=n[num].attributes;for(attr_name in s){var o=s[attr_name];if(attr_name==i)if(o){o=e("<div/>").html(o).text();o=o.replace(/'/g,"\\'");o=o.replace(/"/g,'\\"');current_attr_select.find('option[value="'+o+'"]').removeAttr("disabled")}else current_attr_select.find("option").removeAttr("disabled")}}});$variation_form.trigger("woocommerce_update_variation_values")}).on("found_variation",function(t,n){var r=e(this),i=e(this).closest(".product"),s=i.find("div.images img:eq(0)"),o=i.find("div.images a.zoom:eq(0)"),u=s.attr("data-o_src"),a=s.attr("data-o_title"),f=o.attr("data-o_href"),l=n.image_src,c=n.image_link,h=n.image_title;r.find(".variations_button").show();r.find(".single_variation").html(n.price_html+n.availability_html);if(!u){u=s.attr("src")?s.attr("src"):"";s.attr("data-o_src",u)}if(!f){f=o.attr("href")?o.attr("href"):"";o.attr("data-o_href",f)}if(!a){a=s.attr("title")?s.attr("title"):"";s.attr("data-o_title",a)}if(l&&l.length>1){s.attr("src",l).attr("alt",h).attr("title",h);o.attr("href",c).attr("title",h)}else{s.attr("src",u).attr("alt",a).attr("title",a);o.attr("href",f).attr("title",a)}var p=r.find(".single_variation_wrap");n.sku?i.find(".product_meta").find(".sku").text(n.sku):i.find(".product_meta").find(".sku").text("");p.find(".quantity").show();!n.is_in_stock&&!n.backorders_allowed&&r.find(".variations_button").hide();n.min_qty?p.find("input[name=quantity]").attr("data-min",n.min_qty).val(n.min_qty):p.find("input[name=quantity]").removeAttr("data-min");n.max_qty?p.find("input[name=quantity]").attr("data-max",n.max_qty):p.find("input[name=quantity]").removeAttr("data-max");if(n.is_sold_individually=="yes"){p.find("input[name=quantity]").val("1");p.find(".quantity").hide()}p.slideDown("200").trigger("show_variation",[n])});e("form.variations_form .variations select").change()});
jQuery(document).ready(function(e){function t(e,t){var r=[];for(var i=0;i<e.length;i++){var s=e[i],o=s.variation_id;n(s.attributes,t)&&r.push(s)}return r}function n(e,t){var n=!0;for(attr_name in e){var r=e[attr_name],i=t[attr_name];r!==undefined&&i!==undefined&&r.length!=0&&i.length!=0&&r!=i&&(n=!1)}return n}e("form.variations_form").on("click",".reset_variations",function(t){e(this).closest("form.variations_form").find(".variations select").val("").change();var n=e(this).closest(".product").find(".sku");n.attr("data-o_sku")&&n.text(n.attr("data-o_sku"));return!1}).on("change",".variations select",function(t){$variation_form=e(this).closest("form.variations_form");$variation_form.find("input[name=variation_id]").val("").change();$variation_form.trigger("woocommerce_variation_select_change").trigger("check_variations",["",!1]);e(this).blur();e().uniform&&e.isFunction(e.uniform.update)&&e.uniform.update()}).on("focusin",".variations select",function(t){$variation_form=e(this).closest("form.variations_form");$variation_form.trigger("woocommerce_variation_select_focusin").trigger("check_variations",[e(this).attr("name"),!0])}).on("check_variations",function(n,r,i){var s=!0,o=!1,u=!1,a={},f=e(this),l=f.find(".reset_variations");f.find(".variations select").each(function(){e(this).val().length==0?s=!1:o=!0;if(r&&e(this).attr("name")==r){s=!1;a[e(this).attr("name")]=""}else{value=e(this).val().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/</g,"&lt;").replace(/>/g,"&gt;");a[e(this).attr("name")]=value}});var c=parseInt(f.attr("data-product_id")),h=window["product_variations_"+c];h||(h=window.product_variations);var p=t(h,a);if(s){var d=p.pop();if(d){f.find("input[name=variation_id]").val(d.variation_id).change();f.trigger("found_variation",[d])}else{f.find(".variations select").val("");i||f.trigger("reset_image")}}else{f.trigger("update_variation_values",[p]);i||f.trigger("reset_image");r||f.find(".single_variation_wrap").slideUp("200")}o?l.css("visibility")=="hidden"&&l.css("visibility","visible").hide().fadeIn():l.css("visibility","hidden")}).on("reset_image",function(t){var n=e(this).closest(".product"),r=n.find("div.images img:eq(0)"),i=n.find("div.images a.zoom:eq(0)"),s=r.attr("data-o_src"),o=r.attr("data-o_title"),u=i.attr("data-o_href");if(s&&u&&o){r.attr("src",s).attr("alt",o).attr("title",o);i.attr("href",u).attr("title",o)}}).on("update_variation_values",function(t,n){$variation_form=e(this).closest("form.variations_form");$variation_form.find(".variations select").each(function(t,r){current_attr_select=e(r);current_attr_select.find("option:gt(0)").attr("disabled","disabled");var i=current_attr_select.attr("name");for(num in n){var s=n[num].attributes;for(attr_name in s){var o=s[attr_name];if(attr_name==i)if(o){o=e("<div/>").html(o).text();o=o.replace(/'/g,"\\'");o=o.replace(/"/g,'\\"');current_attr_select.find('option[value="'+o+'"]').removeAttr("disabled")}else current_attr_select.find("option").removeAttr("disabled")}}});$variation_form.trigger("woocommerce_update_variation_values")}).on("found_variation",function(t,n){var r=e(this),i=e(this).closest(".product"),s=i.find("div.images img:eq(0)"),o=i.find("div.images a.zoom:eq(0)"),u=s.attr("data-o_src"),a=s.attr("data-o_title"),f=o.attr("data-o_href"),l=n.image_src,c=n.image_link,h=n.image_title;r.find(".variations_button").show();r.find(".single_variation").html(n.price_html+n.availability_html);if(!u){u=s.attr("src")?s.attr("src"):"";s.attr("data-o_src",u)}if(!f){f=o.attr("href")?o.attr("href"):"";o.attr("data-o_href",f)}if(!a){a=s.attr("title")?s.attr("title"):"";s.attr("data-o_title",a)}if(l&&l.length>1){s.attr("src",l).attr("alt",h).attr("title",h);o.attr("href",c).attr("title",h)}else{s.attr("src",u).attr("alt",a).attr("title",a);o.attr("href",f).attr("title",a)}var p=r.find(".single_variation_wrap"),d=i.find(".product_meta").find(".sku");d.attr("data-o_sku")||d.attr("data-o_sku",d.text());n.sku?d.text(n.sku):d.text(d.attr("data-o_sku"));p.find(".quantity").show();!n.is_in_stock&&!n.backorders_allowed&&r.find(".variations_button").hide();n.min_qty?p.find("input[name=quantity]").attr("data-min",n.min_qty).val(n.min_qty):p.find("input[name=quantity]").removeAttr("data-min");n.max_qty?p.find("input[name=quantity]").attr("data-max",n.max_qty):p.find("input[name=quantity]").removeAttr("data-max");if(n.is_sold_individually=="yes"){p.find("input[name=quantity]").val("1");p.find(".quantity").hide()}p.slideDown("200").trigger("show_variation",[n])});e("form.variations_form .variations select").change()});

File diff suppressed because one or more lines are too long

View File

@ -1539,7 +1539,7 @@ class WC_Product {
'image_title' => $image_title,
'price_html' => $this->min_variation_price != $this->max_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
'availability_html' => $availability_html,
'sku' => __( 'SKU:', 'woocommerce' ) . ' ' . $variation->get_sku(),
'sku' => $variation->get_sku(),
'min_qty' => 1,
'max_qty' => $this->backorders_allowed() ? '' : $variation->stock,
'backorders_allowed' => $this->backorders_allowed(),

View File

@ -14,7 +14,7 @@ global $post, $product;
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( $product->is_type( array( 'simple', 'variable' ) ) && get_option('woocommerce_enable_sku') == 'yes' && $product->get_sku() ) : ?>
<span itemprop="productID" class="sku"><?php _e('SKU:', 'woocommerce'); ?> <?php echo $product->get_sku(); ?>.</span>
<span itemprop="productID" class="sku_wrapper"><?php _e('SKU:', 'woocommerce'); ?> <span class="sku"><?php echo $product->get_sku(); ?></span>.</span>
<?php endif; ?>
<?php echo $product->get_categories( ', ', ' <span class="posted_in">'.__('Category:', 'woocommerce').' ', '.</span>'); ?>