This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,9 @@
.admin__scope-old #coupons_customer_ids.control-value {
display: block;
padding-top: 0;
width: 100%;
}
.esun-customer-coupon-select {
width: 100%;
}
@@ -0,0 +1,60 @@
define([
'ko',
'mage/apply/main',
'Magento_Ui/js/lib/knockout/bootstrap'
], function (ko, mage) {
'use strict';
var selector = '.esun-customer-coupon-select',
initializedAttribute = 'data-esun-customer-coupon-initialized';
function initialize(element) {
var scope;
if (element.hasAttribute(initializedAttribute)) {
return;
}
element.setAttribute(initializedAttribute, 'true');
// The coupons form is inserted through Magento_Ui's `html` binding after
// the normal x-magento-init and Knockout bootstrap passes have completed.
mage.apply(element);
scope = element.querySelector('[data-role="esun-customer-coupon-scope"]');
if (scope) {
ko.applyBindings({}, scope);
}
}
function scan(context) {
var elements = [];
if (context.nodeType !== 1 && context.nodeType !== 9) {
return;
}
if (context.nodeType === 1 && context.matches(selector)) {
elements.push(context);
}
Array.prototype.push.apply(elements, context.querySelectorAll(selector));
elements.forEach(initialize);
}
function start() {
scan(document);
new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
Array.prototype.forEach.call(mutation.addedNodes, scan);
});
}).observe(document.body, {childList: true, subtree: true});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', start);
} else {
start();
}
});
@@ -0,0 +1,101 @@
define([
'Magento_Ui/js/form/element/ui-select'
], function (UiSelect) {
'use strict';
return UiSelect.extend({
defaults: {
// This component is mounted in a legacy form rather than under a UI form provider.
dataScope: 'customer_ids',
showPath: false
},
initialize: function () {
this.selectedOptionsByValue = {};
this._super();
this.value.subscribe(this.syncQuantity, this);
this.syncQuantity(this.value());
return this;
},
/**
* Keep the complete option objects independently from the current AJAX
* result set. Magento replaces cacheOptions.plain for every new search.
*/
toggleOptionSelected: function (option) {
var key = String(option.value);
if (this.isSelected(option.value)) {
delete this.selectedOptionsByValue[key];
} else {
this.selectedOptionsByValue[key] = option;
}
return this._super(option);
},
removeSelected: function (value, data, event) {
delete this.selectedOptionsByValue[String(value)];
return this._super(value, data, event);
},
getSelected: function () {
var values = this.value(),
availableOptions = this.cacheOptions && this.cacheOptions.plain || [],
selectedOptions = [],
optionsByValue = this.selectedOptionsByValue || {};
values = Array.isArray(values) ? values : values ? [values] : [];
values.forEach(function (value) {
var key = String(value),
option = optionsByValue[key];
if (!option) {
availableOptions.some(function (candidate) {
if (String(candidate.value) === key) {
option = candidate;
optionsByValue[key] = candidate;
return true;
}
return false;
});
}
if (option) {
selectedOptions.push(option);
}
});
return selectedOptions;
},
syncQuantity: function (value) {
var quantity = Array.isArray(value) ? value.length : 0,
input = document.getElementById('coupons_qty');
if (!input) {
return;
}
if (quantity > 0) {
if (!input.hasAttribute('data-esun-original-qty')) {
input.setAttribute('data-esun-original-qty', input.value || '');
}
input.value = quantity;
input.readOnly = true;
input.dispatchEvent(new Event('change', {bubbles: true}));
} else {
input.readOnly = false;
if (input.hasAttribute('data-esun-original-qty')) {
input.value = input.getAttribute('data-esun-original-qty');
input.removeAttribute('data-esun-original-qty');
}
}
}
});
});