@@ -424,7 +424,9 @@ define([
424
424
*/
425
425
_replaceImage : function ( oldFile , newFile , imageData ) {
426
426
var tmpNewFile = newFile ,
427
+ tmpOldImage ,
427
428
newImageId ,
429
+ oldNewFilePosition ,
428
430
fc ,
429
431
suff ,
430
432
searchsuff ,
@@ -433,6 +435,7 @@ define([
433
435
434
436
oldFile = this . __prepareFilename ( oldFile ) ;
435
437
newFile = this . __prepareFilename ( newFile ) ;
438
+ tmpOldImage = this . _images [ oldFile ] ;
436
439
437
440
if ( newFile === oldFile ) {
438
441
this . _images [ newFile ] = imageData ;
@@ -444,26 +447,36 @@ define([
444
447
this . _removeImage ( oldFile ) ;
445
448
this . _setImage ( newFile , imageData ) ;
446
449
447
- if ( oldFile && imageData . oldFile ) {
448
- newImageId = this . findElementId ( tmpNewFile ) ;
449
- fc = $ ( this . _itemIdSelector ) . val ( ) ;
450
+ if ( ! oldFile || ! imageData . oldFile ) {
451
+ return null ;
452
+ }
450
453
451
- suff = 'product[media_gallery][images]' + fc ;
454
+ newImageId = this . findElementId ( tmpNewFile ) ;
455
+ fc = $ ( this . _itemIdSelector ) . val ( ) ;
452
456
453
- searchsuff = 'input[name="' + suff + '[value_id]"]' ;
454
- key = $ ( searchsuff ) . val ( ) ;
457
+ suff = 'product[media_gallery][images]' + fc ;
455
458
456
- if ( ! key ) {
457
- return null ;
458
- }
459
+ searchsuff = 'input[name="' + suff + '[value_id]"]' ;
460
+ key = $ ( searchsuff ) . val ( ) ;
459
461
460
- oldValIdElem = document . createElement ( 'input' ) ;
461
- $ ( 'form[data-form="edit-product"]' ) . append ( oldValIdElem ) ;
462
- $ ( oldValIdElem ) . attr ( {
463
- type : 'hidden' ,
464
- name : 'product[media_gallery][images][' + newImageId + '][save_data_from]'
465
- } ) . val ( key ) ;
462
+ if ( ! key ) {
463
+ return null ;
466
464
}
465
+
466
+ oldValIdElem = document . createElement ( 'input' ) ;
467
+ $ ( 'form[data-form="edit-product"]' ) . append ( oldValIdElem ) ;
468
+ $ ( oldValIdElem ) . attr ( {
469
+ type : 'hidden' ,
470
+ name : 'product[media_gallery][images][' + newImageId + '][save_data_from]'
471
+ } ) . val ( key ) ;
472
+
473
+ oldNewFilePosition = parseInt ( tmpOldImage . position ) ;
474
+ imageData . position = oldNewFilePosition ;
475
+
476
+ $ ( this . _imageWidgetSelector ) . trigger ( 'setPosition' , {
477
+ imageData : imageData ,
478
+ position : oldNewFilePosition
479
+ } ) ;
467
480
} ,
468
481
469
482
/**
0 commit comments