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,7 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Esun_CustomerCoupon::css/customer-select.css"/>
</head>
</page>
@@ -0,0 +1,5 @@
var config = {
deps: [
'Esun_CustomerCoupon/js/form/customer-select-bootstrap'
]
};
@@ -0,0 +1,40 @@
<?php
/** @var \Esun\CustomerCoupon\Block\Adminhtml\Form\CustomerSelect $block */
/** @var \Magento\Framework\Escaper $escaper */
?>
<div class="esun-customer-coupon-select">
<div data-role="esun-customer-coupon-scope" data-bind="scope: 'esunCustomerCouponSelect'">
<input type="hidden" name="customer_ids" data-bind="value: value"/>
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
</div>
<script type="text/x-magento-init">
{
".esun-customer-coupon-select": {
"Magento_Ui/js/core/app": {
"components": {
"esunCustomerCouponSelect": {
"component": "Esun_CustomerCoupon/js/form/element/customer-select",
"dataScope": "customer_ids",
"template": "ui/grid/filters/elements/ui-select",
"disableLabel": true,
"multiple": true,
"showCheckbox": true,
"showPath": false,
"chipsEnabled": true,
"filterOptions": true,
"searchOptions": true,
"searchUrl": "<?= $escaper->escapeJs($escaper->escapeUrl($block->getSearchUrl())) ?>",
"filterPlaceholder": "<?= $escaper->escapeJs(__('Search by name, email, or customer ID')) ?>",
"selectedPlaceholders": {
"defaultPlaceholder": "<?= $escaper->escapeJs(__('Search and select customers')) ?>",
"lotPlaceholders": "<?= $escaper->escapeJs(__('customers selected')) ?>"
},
"pageLimit": 20,
"options": []
}
}
}
}
}
</script>
@@ -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');
}
}
}
});
});