Skip to content

Commit

Permalink
Fixed detect changes in custom options section (product edit) (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano authored Sep 26, 2022
1 parent a5286c9 commit 4a952b0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ Bundle.Selection.prototype = {
}
);
}

var inputs = $$('#bundle_option_' + data.parentIndex + ' input');
inputs.each(function(el) { Event.observe(el, 'change', el.setHasChanges.bind(el)); } )
var inputs = $$('#bundle_option_' + data.parentIndex + ' button.delete');
inputs.each(function(el) { Event.observe(el, 'click', el.setHasChanges.bind(el)); } )
},

bindScopeCheckbox : function(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ var productOption = {
}
<?php else: ?>
inputs.each(function(el) { Event.observe(el, 'change', el.setHasChanges.bind(el)); } )
var inputs = $$('div.product-custom-options button');
inputs.each(function(el) { Event.observe(el, 'click', el.setHasChanges.bind(el)); } )
<?php endif ?>
}
}
Expand Down Expand Up @@ -316,8 +318,6 @@ if($('option_panel')){
$('option_panel').remove();
}

productOption.bindRemoveButtons();

if($('<?php echo $this->getAddButtonId() ?>')){
Event.observe('<?php echo $this->getAddButtonId() ?>', 'click', productOption.add.bind(productOption));
}
Expand All @@ -337,6 +337,8 @@ Validation.addAllThese([
productOptionType.addDataToValues(<?php echo $_value->toJson() ?>);
<?php endforeach ?>

productOption.bindRemoveButtons();

//bind scope checkboxes
productOptionScope.bindScopeCheckbox();
//]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ selectOptionType = {
templateSyntax : /(^|.|\r|\n)({{(\w+)}})/,
templateText : OptionTemplateSelectRow,
add : function(data) {

this.template = new Template(this.templateText, this.templateSyntax);

if (data.target || data.srcElement) {//data is Event (work in IE and Firefox)
Expand All @@ -86,6 +85,11 @@ selectOptionType = {

Element.insert($(this.div+'_'+data.id), {'bottom':this.template.evaluate(data)});

var inputs = $$('#product_option_'+data.id+'_select_'+data.select_id+' input', '#product_option_'+data.id+'_select_'+data.select_id+' select', '#product_option_'+data.id+'_select_'+data.select_id+' textarea');
inputs.each(function(el) { Event.observe(el, 'change', el.setHasChanges.bind(el)); });
var inputs = $$('#product_option_'+data.id+'_select_'+data.select_id+' button');
inputs.each(function(el) { Event.observe(el, 'click', el.setHasChanges.bind(el)); });

if (data.checkboxScopeTitle) {
//set disabled
if ($('product_option_'+data.id+'_select_'+data.select_id+'_title') && data.scopeTitleDisabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ var groupPriceControl = {
$('<?php echo $_htmlId; ?>_container').select('input', 'select').each(function(element) {
Event.observe(element, 'change', element.setHasChanges.bind(element));
});
$('<?php echo $_htmlId; ?>_container').select('button.delete').each(function(element) {
Event.observe(element, 'click', element.setHasChanges.bind(element));
});
<?php endif ?>
},
disableElement: function(element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ var tierPriceControl = {
$('<?php echo $_htmlId ?>_container').up('table').select('button').each(this.disableElement);
<?php else: ?>
$('<?php echo $_htmlId ?>_container').select('input', 'select').each(function(el){ Event.observe(el, 'change', el.setHasChanges.bind(el)); });
$('<?php echo $_htmlId ?>_container').select('button.delete').each(function(el){ Event.observe(el, 'click', el.setHasChanges.bind(el)); });
<?php endif ?>
},
disableElement: function(el) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

<script type="text/javascript">
//<![CDATA[
var linkTemplate = '<tr>'+
var linkTemplate = '<tr id="downloadable_link_{{id}}">'+
'<td>'+
'<input type="hidden" class="__delete__" name="downloadable[link][{{id}}][is_delete]" value="" />'+
'<input type="hidden" name="downloadable[link][{{id}}][link_id]" value="{{link_id}}" />'+
Expand Down Expand Up @@ -310,6 +310,11 @@ var linkItems = {
this.itemCount++;
this.togglePriceFields();
this.bindRemoveButtons();

var inputs = $$('#downloadable_link_' + data.id + ' input');
inputs.each(function(el) { Event.observe(el, 'change', el.setHasChanges.bind(el)); } )
var inputs = $$('#downloadable_link_' + data.id + ' button.delete');
inputs.each(function(el) { Event.observe(el, 'click', el.setHasChanges.bind(el)); } )
},
remove : function(event){
var element = $(Event.findElement(event, 'tr'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</div>
<script type="text/javascript">
//<![CDATA[>
var sampleTemplate = '<tr>'+
var sampleTemplate = '<tr id="downloadable_sample_{{id}}">'+
'<td>'+
'<input type="hidden" class="__delete__" name="downloadable[sample][{{id}}][is_delete]" value="" />'+
'<input type="hidden" name="downloadable[sample][{{id}}][sample_id]" value="{{sample_id}}" />'+
Expand Down Expand Up @@ -176,13 +176,20 @@ var sampleItems = {

this.itemCount++;
this.bindRemoveButtons();

var inputs = $$('#downloadable_sample_' + data.id + ' input');
inputs.each(function(el) { Event.observe(el, 'change', el.setHasChanges.bind(el)); } )
var inputs = $$('#downloadable_sample_' + data.id + ' button.delete');
inputs.each(function(el) { Event.observe(el, 'click', el.setHasChanges.bind(el)); } )
},
remove : function(event){
var element = $(Event.findElement(event, 'tr'));
alertAlreadyDisplayed = false;
if(element){
element.down('input[type="hidden"].__delete__').value = '1';
element.down('div.flex').remove();
Element.select(element, 'div.flex').each(function(elm){
elm.remove();
});
element.addClassName('no-display');
element.addClassName('ignore-validate');
element.hide();
Expand Down
13 changes: 11 additions & 2 deletions js/mage/adminhtml/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,17 @@ Product.Configurable.prototype = {
this.updateSaveInput();
},
updateSaveInput : function() {
$(this.idPrefix + 'save_attributes').value = Object.toJSON(this.attributes);
$(this.idPrefix + 'save_links').value = Object.toJSON(this.links);
var oldSaveAttributesValue = $(this.idPrefix + 'save_attributes').value;
var oldSaveLinksValue = $(this.idPrefix + 'save_links').value;
var newSaveAttributesValue = Object.toJSON(this.attributes);
var newSaveLinksValue = Object.toJSON(this.links);
$(this.idPrefix + 'save_attributes').value = newSaveAttributesValue;
$(this.idPrefix + 'save_links').value = newSaveLinksValue;
if (oldSaveAttributesValue != newSaveAttributesValue || oldSaveLinksValue != newSaveLinksValue) {
try {
document.getElementById('configurable_save_attributes').setHasChanges();
} catch (e) {}
}
},
initializeAdvicesForSimpleForm : function() {
if ($(this.idPrefix + 'simple_form').advicesInited) {
Expand Down

0 comments on commit 4a952b0

Please sign in to comment.