diff --git a/assets/js/frontend/add-to-cart-variation.js b/assets/js/frontend/add-to-cart-variation.js index 7bbcbf338c4..8e24492401d 100644 --- a/assets/js/frontend/add-to-cart-variation.js +++ b/assets/js/frontend/add-to-cart-variation.js @@ -528,7 +528,7 @@ $product_img_wrap = $product.find( '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:eq(0)' ), $product_img = $product.find( '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:eq(0) .wp-post-image' ); - if ( variation && variation.image && variation.image.src.length > 1 ) { + if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) { $product_img.wc_set_variation_attr( 'src', variation.image.src ); $product_img.wc_set_variation_attr( 'height', variation.image.src_h ); $product_img.wc_set_variation_attr( 'width', variation.image.src_w ); diff --git a/assets/js/frontend/add-to-cart-variation.min.js b/assets/js/frontend/add-to-cart-variation.min.js index 2081a5b2218..cc4220f6017 100644 --- a/assets/js/frontend/add-to-cart-variation.min.js +++ b/assets/js/frontend/add-to-cart-variation.min.js @@ -1 +1 @@ -!function(a,b,c,d){var e=function(a){this.$form=a,this.$attributeFields=a.find(".variations select"),this.$singleVariation=a.find(".single_variation"),this.$singleVariationWrap=a.find(".single_variation_wrap"),this.$resetVariations=a.find(".reset_variations"),this.$product=a.closest(".product"),this.variationData=a.data("product_variations"),this.useAjax=!1===this.variationData,this.xhr=!1,this.$singleVariationWrap.show(),this.$form.unbind("check_variations update_variation_values found_variation"),this.$resetVariations.unbind("click"),this.$attributeFields.unbind("change "),this.getChosenAttributes=this.getChosenAttributes.bind(this),this.findMatchingVariations=this.findMatchingVariations.bind(this),this.isMatch=this.isMatch.bind(this),this.toggleResetLink=this.toggleResetLink.bind(this),a.on("click",".reset_variations",{variationForm:this},this.onReset),a.on("reload_product_variations",{variationForm:this},this.onReload),a.on("hide_variation",{variationForm:this},this.onHide),a.on("show_variation",{variationForm:this},this.onShow),a.on("click","single_add_to_cart_button",{variationForm:this},this.onAddToCart),a.on("reset_data",{variationForm:this},this.onResetDisplayedVariation),a.on("reset_image",{variationForm:this},this.onResetImage),a.on("change",".variations select",{variationForm:this},this.onChange),a.on("found_variation",{variationForm:this},this.onFoundVariation),a.on("check_variations",{variationForm:this},this.onFindVariation),a.on("update_variation_values",{variationForm:this},this.onUpdateAttributes),a.trigger("check_variations"),a.trigger("wc_variation_form")};e.prototype.onReset=function(a){a.preventDefault(),a.data.variationForm.$attributeFields.val("").change(),a.data.variationForm.$form.trigger("reset_data")},e.prototype.onReload=function(a){var b=a.data.variationForm;b.variationData=b.$form.data("product_variations"),b.useAjax=!1===b.variationData,b.$form.trigger("check_variations")},e.prototype.onHide=function(a){a.preventDefault(),a.data.variationForm.$form.find(".single_add_to_cart_button").removeClass("wc-variation-is-unavailable").addClass("disabled wc-variation-selection-needed"),a.data.variationForm.$form.find(".woocommerce-variation-add-to-cart").removeClass("woocommerce-variation-add-to-cart-enabled").addClass("woocommerce-variation-add-to-cart-disabled")},e.prototype.onShow=function(a,b,c){a.preventDefault(),c?(a.data.variationForm.$form.find(".single_add_to_cart_button").removeClass("disabled wc-variation-selection-needed wc-variation-is-unavailable"),a.data.variationForm.$form.find(".woocommerce-variation-add-to-cart").removeClass("woocommerce-variation-add-to-cart-disabled").addClass("woocommerce-variation-add-to-cart-enabled")):(a.data.variationForm.$form.find(".single_add_to_cart_button").removeClass("wc-variation-selection-needed").addClass("disabled wc-variation-is-unavailable"),a.data.variationForm.$form.find(".woocommerce-variation-add-to-cart").removeClass("woocommerce-variation-add-to-cart-enabled").addClass("woocommerce-variation-add-to-cart-disabled"))},e.prototype.onAddToCart=function(c){a(this).is(".disabled")&&(c.preventDefault(),a(this).is(".wc-variation-is-unavailable")?b.alert(wc_add_to_cart_variation_params.i18n_unavailable_text):a(this).is(".wc-variation-selection-needed")&&b.alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text))},e.prototype.onResetDisplayedVariation=function(a){var b=a.data.variationForm;b.$product.find(".product_meta").find(".sku").wc_reset_content(),b.$product.find(".product_weight").wc_reset_content(),b.$product.find(".product_dimensions").wc_reset_content(),b.$form.trigger("reset_image"),b.$singleVariation.slideUp(200).trigger("hide_variation")},e.prototype.onResetImage=function(a){a.data.variationForm.$form.wc_variations_image_update(!1)},e.prototype.onFindVariation=function(a){var c=a.data.variationForm;if(!c.useAjax){c.$form.trigger("update_variation_values");var d=c.getChosenAttributes(),e=c.findMatchingVariations(c.variationData,d.data);if(d.count===d.chosenCount){var f=e.shift();f?c.$form.trigger("found_variation",[f]):(b.alert(wc_add_to_cart_variation_params.i18n_no_matching_variations_text),c.$form.trigger("reset_data"))}else c.$form.trigger("reset_data"),c.$singleVariation.slideUp(200).trigger("hide_variation");c.toggleResetLink(d.chosenCount>0)}},e.prototype.onFoundVariation=function(b,c){var d=b.data.variationForm,e=d.$product.find(".product_meta").find(".sku"),f=d.$product.find(".product_weight"),g=d.$product.find(".product_dimensions"),h=d.$singleVariationWrap.find(".quantity"),i=!0,j="",k=!1,l="";c.sku?e.wc_set_content(c.sku):e.wc_reset_content(),c.weight?f.wc_set_content(c.weight):f.wc_reset_content(),c.dimensions?g.wc_set_content(c.dimensions):g.wc_reset_content(),d.$form.wc_variations_image_update(c),c.variation_is_visible?(k=wp.template("variation-template"),j=c.variation_id):k=wp.template("unavailable-variation-template"),l=k({variation:c}),l=l.replace("/**/",""),d.$singleVariation.html(l),d.$form.find('input[name="variation_id"], input.variation_id').val(c.variation_id).change(),"yes"===c.is_sold_individually?(h.find("input.qty").val("1").attr("min","1").attr("max",""),h.hide()):(h.find("input.qty").attr("min",c.min_qty).attr("max",c.max_qty),h.show()),c.is_purchasable&&c.is_in_stock&&c.variation_is_visible||(i=!1),a.trim(d.$singleVariation.text())?d.$singleVariation.slideDown(200).trigger("show_variation",[c,i]):d.$singleVariation.show().trigger("show_variation",[c,i])},e.prototype.onChange=function(b){var c=b.data.variationForm;if(c.$form.find('input[name="variation_id"], input.variation_id').val("").change(),c.$form.find(".wc-no-matching-variations").remove(),c.useAjax){c.xhr&&c.xhr.abort();var d=c.getChosenAttributes(),e=d.data;d.count===d.chosenCount?(c.$form.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.product_id=parseInt(c.$form.data("product_id"),10),e.custom_data=c.$form.data("custom_data"),c.xhr=a.ajax({url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_variation"),type:"POST",data:e,success:function(a){a?c.$form.trigger("found_variation",[a]):(c.$form.trigger("reset_data"),c.$form.find(".single_variation").after('

'+wc_add_to_cart_variation_params.i18n_no_matching_variations_text+"

"),c.$form.find(".wc-no-matching-variations").slideDown(200))},complete:function(){c.$form.unblock()}})):c.$form.trigger("reset_data"),c.toggleResetLink(d.chosenCount>0)}else c.$form.trigger("woocommerce_variation_select_change"),c.$form.trigger("check_variations"),a(this).blur();a(".product.has-default-attributes > .images").fadeTo(200,1),c.$form.trigger("woocommerce_variation_has_changed")},e.prototype.onUpdateAttributes=function(b){var c=b.data.variationForm,d=c.getChosenAttributes(),e=d.data;c.useAjax||(c.$attributeFields.each(function(b,d){var f=a(d),g=f.data("attribute_name")||f.attr("name"),h=a(d).data("show_option_none"),i=":gt(0)",j=0,k=a(""),l=f.val()||"",m=!0;if(!f.data("attribute_html")){var n=f.clone();n.find("option").removeAttr("disabled attached").removeAttr("selected"),f.data("attribute_options",n.find("option"+i).get()),f.data("attribute_html",n.html())}k.html(f.data("attribute_html"));var o=a.extend(!0,{},e);o[g]="";var p=c.findMatchingVariations(c.variationData,o);for(var q in p)if("undefined"!=typeof p[q]){var r=p[q].attributes;for(var s in r)if(r.hasOwnProperty(s)){var t=r[s],u="";s===g&&(p[q].variation_is_active&&(u="enabled"),t?(t=a("
").html(t).text(),t=t.replace(/'/g,"\\'"),t=t.replace(/"/g,'\\"'),k.find('option[value="'+t+'"]').addClass("attached "+u)):k.find("option:gt(0)").addClass("attached "+u))}}j=k.find("option.attached").length,!l||0!==j&&0!==k.find('option.attached.enabled[value="'+l+'"]').length||(m=!1),j>0&&l&&m&&"no"===h&&(k.find("option:first").remove(),i=""),k.find("option"+i+":not(.attached)").remove(),f.html(k.html()),f.find("option"+i+":not(.enabled)").prop("disabled",!0),l&&(m?f.val(l):f.val("").change())}),c.$form.trigger("woocommerce_update_variation_values"))},e.prototype.getChosenAttributes=function(){var b={},c=0,d=0;return this.$attributeFields.each(function(){var e=a(this).data("attribute_name")||a(this).attr("name"),f=a(this).val()||"";f.length>0&&d++,c++,b[e]=f}),{count:c,chosenCount:d,data:b}},e.prototype.findMatchingVariations=function(a,b){for(var c=[],d=0;d1?(h.wc_set_variation_attr("src",c.image.src),h.wc_set_variation_attr("height",c.image.src_h),h.wc_set_variation_attr("width",c.image.src_w),h.wc_set_variation_attr("srcset",c.image.srcset),h.wc_set_variation_attr("sizes",c.image.sizes),h.wc_set_variation_attr("title",c.image.title),h.wc_set_variation_attr("alt",c.image.alt),h.wc_set_variation_attr("data-large-image",c.image.full_src),h.wc_set_variation_attr("data-large-image-width",c.image.full_src_w),h.wc_set_variation_attr("data-large-image-height",c.image.full_src_h),g.wc_set_variation_attr("data-thumb",c.image.src)):(g.wc_reset_variation_attr("data-thumb"),h.wc_reset_variation_attr("large-image"),h.wc_reset_variation_attr("src"),h.wc_reset_variation_attr("width"),h.wc_reset_variation_attr("height"),h.wc_reset_variation_attr("srcset"),h.wc_reset_variation_attr("sizes"),h.wc_reset_variation_attr("title"),h.wc_reset_variation_attr("alt"),f.wc_reset_variation_attr("src"),h.wc_reset_variation_attr("data-large-image"),h.wc_reset_variation_attr("data-large-image-width"),h.wc_reset_variation_attr("data-large-image-height"),b.setTimeout(function(){a(b).trigger("resize")},10)),a("body").trigger("woocommerce_init_gallery")},a(function(){"undefined"!=typeof wc_add_to_cart_variation_params&&a(".variations_form").each(function(){a(this).wc_variation_form()})})}(jQuery,window,document); \ No newline at end of file