Skip to content

Commit

Permalink
fresh fix for 14677 (without unnecessary commit history)
Browse files Browse the repository at this point in the history
  • Loading branch information
faisal-alvi authored and mikejolley committed Jun 6, 2017
1 parent 4138b2b commit 1863446
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions assets/js/frontend/add-to-cart-variation.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,11 @@
$form.attr( 'current-image', new_image_id );

if ( reset_slide_position ) {
$product_gallery.trigger( 'woocommerce_gallery_reset_slide_position' );
if( variation && $('.flex-control-nav li img[src="'+variation.image.thumb_src+'"]').length > 0 ) {
$('.flex-control-nav li img[src="'+variation.image.thumb_src+'"]').trigger('click');
} else {
$product_gallery.trigger( 'woocommerce_gallery_reset_slide_position' );
}
}
};

Expand All @@ -552,20 +556,24 @@
$product_link = $product_img_wrap.find( 'a' ).eq( 0 );

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 );
$product_img.wc_set_variation_attr( 'srcset', variation.image.srcset );
$product_img.wc_set_variation_attr( 'sizes', variation.image.sizes );
$product_img.wc_set_variation_attr( 'title', variation.image.title );
$product_img.wc_set_variation_attr( 'alt', variation.image.alt );
$product_img.wc_set_variation_attr( 'data-src', variation.image.full_src );
$product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src );
$product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w );
$product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h );
$product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src );
$gallery_img.wc_set_variation_attr( 'src', variation.image.thumb_src );
$product_link.wc_set_variation_attr( 'href', variation.image.full_src );
if( $('.flex-control-nav li img[src="'+variation.image.thumb_src+'"]').length > 0 ) {
$gallery_img = $('.flex-control-nav li img[src="'+variation.image.thumb_src+'"]');
} else {
$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 );
$product_img.wc_set_variation_attr( 'srcset', variation.image.srcset );
$product_img.wc_set_variation_attr( 'sizes', variation.image.sizes );
$product_img.wc_set_variation_attr( 'title', variation.image.title );
$product_img.wc_set_variation_attr( 'alt', variation.image.alt );
$product_img.wc_set_variation_attr( 'data-src', variation.image.full_src );
$product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src );
$product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w );
$product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h );
$product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src );
$gallery_img.wc_set_variation_attr( 'src', variation.image.thumb_src );
$product_link.wc_set_variation_attr( 'href', variation.image.full_src );
}
} else {
$product_img.wc_reset_variation_attr( 'src' );
$product_img.wc_reset_variation_attr( 'width' );
Expand Down

0 comments on commit 1863446

Please sign in to comment.