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,14 @@
<?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_ProductInquiry::css/product-inquiry.css"/>
</head>
<body>
<referenceContainer name="before.body.end">
<block class="Esun\ProductInquiry\Block\ProductInquiry"
name="esun.product.inquiry.modal"
template="Esun_ProductInquiry::product/inquiry.phtml"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,8 @@
<?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">
<body>
<referenceBlock name="product.info"
template="Esun_ProductInquiry::product/view/form.phtml"/>
</body>
</page>
@@ -0,0 +1,12 @@
var config = {
config: {
mixins: {
'Magento_Swatches/js/swatch-renderer': {
'Esun_ProductInquiry/js/swatch-renderer-mixin': true
},
'Magento_ConfigurableProduct/js/configurable': {
'Esun_ProductInquiry/js/configurable-mixin': true
}
}
}
};
@@ -0,0 +1,87 @@
<?php
/** @var \Esun\ProductInquiry\Block\ProductInquiry $block */
/** @var \Magento\Framework\Escaper $escaper */
if (!$block->canRender()) {
return;
}
?>
<div class="esun-product-inquiry" data-role="product-inquiry-modal" style="display:none">
<form class="esun-product-inquiry__form"
action="<?= $escaper->escapeUrl($block->getUrl('product-inquiry/index/post')) ?>"
method="post"
novalidate>
<?= /* @noEscape */ $block->getBlockHtml('formkey') ?>
<input type="hidden" name="parent_product_id" value="<?= (int)$block->getProduct()->getId() ?>"/>
<input type="hidden" name="product_id" value="" data-role="product-inquiry-product-id"/>
<div class="esun-product-inquiry__status" data-role="product-inquiry-status" role="status" aria-live="polite"></div>
<div class="esun-product-inquiry__product">
<strong data-role="product-inquiry-product-name"></strong>
<span data-role="product-inquiry-product-options"></span>
</div>
<div class="esun-product-inquiry__grid">
<div class="field required">
<label for="product-inquiry-name">
<span><?= $escaper->escapeHtml(__('Name')) ?></span>
<span class="esun-product-inquiry__required" aria-hidden="true">*</span>
</label>
<input class="input-text" id="product-inquiry-name" name="name" type="text"
maxlength="255" autocomplete="name" required data-validate="{required:true}"/>
</div>
<div class="field required">
<label for="product-inquiry-email">
<span><?= $escaper->escapeHtml(__('Email')) ?></span>
<span class="esun-product-inquiry__required" aria-hidden="true">*</span>
</label>
<input class="input-text" id="product-inquiry-email" name="email" type="email"
maxlength="255" autocomplete="email" required
data-validate="{required:true, 'validate-email':true}"/>
</div>
<div class="field required">
<label for="product-inquiry-country">
<span><?= $escaper->escapeHtml(__('Country')) ?></span>
<span class="esun-product-inquiry__required" aria-hidden="true">*</span>
</label>
<select id="product-inquiry-country" name="country_id" required data-validate="{required:true}">
<option value=""><?= $escaper->escapeHtml(__('Please select a country.')) ?></option>
<?php foreach ($block->getCountryOptions() as $country): ?>
<option value="<?= $escaper->escapeHtmlAttr((string)$country['value']) ?>">
<?= $escaper->escapeHtml((string)$country['label']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="field">
<label for="product-inquiry-company"><span><?= $escaper->escapeHtml(__('Company Name')) ?></span></label>
<input class="input-text" id="product-inquiry-company" name="company" type="text"
maxlength="255" autocomplete="organization"/>
</div>
<div class="field">
<label for="product-inquiry-telephone"><span><?= $escaper->escapeHtml(__('Telephone')) ?></span></label>
<input class="input-text" id="product-inquiry-telephone" name="telephone" type="tel"
maxlength="64" autocomplete="tel"/>
</div>
</div>
<div class="field required esun-product-inquiry__message">
<label for="product-inquiry-message">
<span><?= $escaper->escapeHtml(__('Message')) ?></span>
<span class="esun-product-inquiry__required" aria-hidden="true">*</span>
</label>
<textarea id="product-inquiry-message" name="message" rows="6" maxlength="5000"
required data-validate="{required:true}"></textarea>
</div>
<input type="text" name="hideit" class="esun-product-inquiry__trap" tabindex="-1" autocomplete="off"/>
<button type="submit" class="action primary esun-product-inquiry__submit">
<span><?= $escaper->escapeHtml(__('Submit Inquiry')) ?></span>
</button>
</form>
</div>
<script type="text/x-magento-init">
{
"[data-role=product-inquiry-modal]": {
"Esun_ProductInquiry/js/product-inquiry": <?= /* @noEscape */ $block->getJsonConfig() ?>
}
}
</script>
@@ -0,0 +1,56 @@
<?php
/**
* Product view form with configurable options kept visible for inquiry when
* every associated product is out of stock.
*
* @var $block \Magento\Catalog\Block\Product\View
* @var $escaper \Magento\Framework\Escaper
*/
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
$_product = $block->getProduct();
$isConfigurable = $_product->getTypeId()
=== \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE;
$hasOptions = $block->hasOptions() || $isConfigurable;
$canRenderOptions = $_product->isSaleable() || $isConfigurable;
?>
<div class="product-add-form">
<form data-product-sku="<?= $escaper->escapeHtmlAttr($_product->getSku()) ?>"
action="<?= $escaper->escapeUrl($block->getSubmitUrl($_product)) ?>"
method="post"
id="product_addtocart_form"<?php if ($_product->getOptions()): ?>
enctype="multipart/form-data"<?php endif; ?>>
<input type="hidden" name="product" value="<?= (int)$_product->getId() ?>" />
<input type="hidden" name="selected_configurable_option" value="" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
<input type="hidden"
name="return_url"
value="<?= $escaper->escapeUrl(
$block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true])
) ?>" />
<input type="hidden" name="item" value="<?= (int)$block->getRequest()->getParam('id') ?>" />
<?= $block->getBlockHtml('formkey') ?>
<?= $block->getChildHtml('form_top') ?>
<?php if (!$hasOptions): ?>
<?= $block->getChildHtml('product_info_form_content') ?>
<?php elseif ($canRenderOptions && $block->getOptionsContainer() === 'container1'): ?>
<?= $block->getChildChildHtml('options_container') ?>
<?php endif; ?>
<?php if ($canRenderOptions && $hasOptions && $block->getOptionsContainer() === 'container2'): ?>
<?= $block->getChildChildHtml('options_container') ?>
<?php endif; ?>
<?= $block->getChildHtml('form_bottom') ?>
</form>
</div>
<script type="text/x-magento-init">
{
"[data-role=priceBox][data-price-box=product-id-<?= $escaper->escapeHtmlAttr($_product->getId()) ?>]": {
"priceBox": {
"priceConfig": <?= /* @noEscape */ $block->getJsonConfig() ?>
}
}
}
</script>
@@ -0,0 +1,207 @@
.esun-product-inquiry__trigger {
align-items: center;
background: #18a957;
border: 0;
border-radius: 999px;
box-shadow: none;
color: #fff;
display: inline-flex;
font-size: 18px;
font-weight: 700;
justify-content: center;
letter-spacing: 0;
line-height: 1.2;
min-height: 56px;
max-width: 300px;
padding: 0 34px;
text-transform: none;
transition:
background-color 0.16s ease,
opacity 0.16s ease;
width: 100%;
}
.esun-product-inquiry__trigger:hover,
.esun-product-inquiry__trigger:focus {
background: #129347;
border: 0;
color: #fff;
}
.esun-product-inquiry-modal .modal-inner-wrap {
width: min(700px, calc(100% - 32px));
border-radius: 18px;
overflow: hidden;
}
.esun-product-inquiry-modal .modal-header {
padding: 24px 32px;
background: #1e9e5a;
color: #fff;
}
.esun-product-inquiry-modal .modal-title,
.esun-product-inquiry-modal .action-close:before {
color: #fff;
border: none;
padding: 0;
}
.esun-product-inquiry-modal .modal-content {
padding: 28px 32px 34px;
}
.esun-product-inquiry__product {
display: flex;
flex-direction: column;
gap: 4px;
margin-bottom: 24px;
padding: 14px 18px;
border-radius: 10px;
background: #f1f8f4;
}
.esun-product-inquiry__grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
.esun-product-inquiry .field {
margin: 0 0 18px;
}
.esun-product-inquiry input,
.esun-product-inquiry select,
.esun-product-inquiry textarea {
width: 100%;
box-sizing: border-box;
}
.esun-product-inquiry input.input-text,
.esun-product-inquiry select,
.esun-product-inquiry textarea {
border: 1px solid #d9dde1;
background: #fff;
color: #1f2933;
box-shadow: none;
transition:
border-color 0.16s ease,
box-shadow 0.16s ease;
}
.esun-product-inquiry input.input-text,
.esun-product-inquiry select {
height: 48px;
padding: 0 20px;
border-radius: 24px;
}
.esun-product-inquiry select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding-right: 52px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23303030' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 22px center;
background-size: 10px 8px;
}
.esun-product-inquiry textarea {
min-height: 160px;
padding: 16px 20px;
border-radius: 18px;
resize: vertical;
}
.esun-product-inquiry input.input-text:focus,
.esun-product-inquiry select:focus,
.esun-product-inquiry textarea:focus {
border-color: #1e9e5a;
outline: 0;
box-shadow: 0 0 0 3px rgba(30, 158, 90, 0.12);
}
.esun-product-inquiry__message {
margin-top: 2px;
}
.esun-product-inquiry__required {
color: #e02b27;
margin-left: 3px;
}
.esun-product-inquiry .esun-product-inquiry__submit.action.primary {
align-items: center;
background: #18a957;
border: 0;
border-radius: 999px;
box-shadow: none;
color: #fff;
display: flex;
font-size: 18px;
font-weight: 700;
justify-content: center;
letter-spacing: 0;
line-height: 1.2;
margin: 8px 0 0 auto;
max-width: 300px;
min-height: 56px;
padding: 0 34px;
text-transform: none;
transition:
background-color 0.16s ease,
opacity 0.16s ease;
width: 100%;
}
.esun-product-inquiry .esun-product-inquiry__submit.action.primary:hover,
.esun-product-inquiry .esun-product-inquiry__submit.action.primary:focus,
.esun-product-inquiry .esun-product-inquiry__submit.action.primary:active {
background: #129347;
border: 0;
color: #fff;
}
.esun-product-inquiry__status {
display: none;
margin-bottom: 18px;
padding: 12px 16px;
border-radius: 8px;
}
.esun-product-inquiry__status.success,
.esun-product-inquiry__status.error {
display: block;
}
.esun-product-inquiry__status.success {
background: #edf8f2;
color: #167746;
}
.esun-product-inquiry__status.error {
background: #fff1f0;
color: #c62828;
}
.esun-product-inquiry__trap {
position: absolute !important;
left: -10000px !important;
width: 1px !important;
height: 1px !important;
opacity: 0 !important;
}
@media (max-width: 767px) {
.esun-product-inquiry__grid {
grid-template-columns: 1fr;
gap: 0;
}
.esun-product-inquiry-modal .modal-content {
padding: 24px 20px 28px;
}
.esun-product-inquiry .esun-product-inquiry__submit.action.primary {
max-width: none;
}
}
@@ -0,0 +1,30 @@
define(['jquery', 'mage/utils/wrapper'], function ($, wrapper) {
'use strict';
return function (Widget) {
Widget.prototype._fillSelect = wrapper.wrapSuper(Widget.prototype._fillSelect, function (element) {
var config = this.options.spConfig || {},
attributeId = element.id.replace(/[a-z]*/, ''),
result;
if (config.canDisplayShowOutOfStockStatus) {
config.salable = config.salable || {};
config.salable[attributeId] = config.salable[attributeId] || {};
}
result = this._super(element);
if (config.canDisplayShowOutOfStockStatus) {
$(element).find('option').each(function () {
var wasDisabled = this.disabled;
if (this.config && this.config.allowedProducts && this.config.allowedProducts.length) {
this.disabled = false;
$(this).toggleClass('esun-out-of-stock-option', wasDisabled);
}
});
}
return result;
});
return Widget;
};
});
@@ -0,0 +1,221 @@
define([
'jquery',
'Magento_Ui/js/modal/modal',
'mage/validation',
'mage/translate'
], function ($, modal, validation, $t) {
'use strict';
return function (config, element) {
var $modal = $(element),
$form = $modal.find('form'),
$trigger = $('[data-role="product-inquiry-trigger"]').first(),
$addToCart = $('#product-addtocart-button'),
$buyNow = $('[data-role="esun-buy-now"]'),
$qty = $('.box-tocart .field.qty'),
$status = $modal.find('[data-role="product-inquiry-status"]'),
$submit = $form.find('[type="submit"]'),
closeTimer = null,
selectedChild = null;
if (!$trigger.length) {
$trigger = $('<button>', {
type: 'button',
'class': 'action primary tocart esun-product-inquiry__trigger',
'data-role': 'product-inquiry-trigger'
}).append($('<span>', {text: $t('Inquiry')})).hide();
if (!$('.esun-product-actions').length) {
$('<div>', {
'class': 'box-tocart esun-product-inquiry-actions'
}).append(
$('<div>', {'class': 'fieldset'}).append(
$('<div>', {'class': 'actions esun-product-actions'})
)
).appendTo($('.product-options-bottom').first().length ?
$('.product-options-bottom').first() : $('#product_addtocart_form'));
}
$('.esun-product-actions').first().append($trigger);
}
modal({
type: 'popup',
responsive: true,
innerScroll: true,
modalClass: 'esun-product-inquiry-modal',
title: $t('Inquiry'),
buttons: []
}, $modal);
$form.validation();
function getSwatchWidget() {
var $swatch = $('.swatch-opt');
return $swatch.data('mageSwatchRenderer') || $swatch.data('mage-SwatchRenderer');
}
function getSelectedProductId() {
var selected = $('[name="selected_configurable_option"]').val(),
widget,
selectedOptions = {},
match = null;
if (selected && config.children[String(selected)]) {
return String(selected);
}
widget = getSwatchWidget();
if (widget && typeof widget.getProductId === 'function') {
selected = widget.getProductId();
if (selected && config.children[String(selected)]) {
return String(selected);
}
}
$('.swatch-attribute').each(function () {
var $attribute = $(this),
attributeId = String($attribute.attr('attribute-id') || $attribute.data('attribute-id') || ''),
optionId = $attribute.find('.swatch-option.selected').attr('option-id') ||
$attribute.find('.swatch-option.selected').data('option-id') ||
$attribute.find('.super-attribute-select').val();
if (attributeId && optionId) {
selectedOptions[attributeId] = String(optionId);
}
});
if (widget && widget.options && widget.options.jsonConfig) {
$.each(widget.options.jsonConfig.index || {}, function (productId, options) {
var matches = Object.keys(selectedOptions).length > 0;
$.each(selectedOptions, function (attributeId, optionId) {
if (String(options[attributeId]) !== optionId) {
matches = false;
return false;
}
});
if (matches && Object.keys(options).length === Object.keys(selectedOptions).length) {
match = String(productId);
return false;
}
});
}
return match;
}
function ensureStickyInquiryButtons() {
$('.esun-sticky-product-bar__actions').each(function () {
var $actions = $(this);
if (!$actions.find('[data-role="esun-sticky-product-inquiry"]').length) {
$('<button>', {
type: 'button',
'class': 'action primary esun-sticky-product-inquiry',
'data-role': 'esun-sticky-product-inquiry',
text: $t('Inquiry')
}).hide().appendTo($actions);
}
});
}
function setInquiryState(enabled) {
ensureStickyInquiryButtons();
$trigger.toggle(enabled);
$addToCart.toggle(!enabled).prop('disabled', enabled);
$buyNow.closest('.esun-buy-now-row').toggle(!enabled);
$qty.toggle(!enabled);
$('[data-role="esun-sticky-add-to-cart"], [data-role="esun-sticky-buy-now"]').toggle(!enabled);
$('[data-role="esun-sticky-product-inquiry"]').toggle(enabled);
}
function refreshState() {
var productId = getSelectedProductId();
selectedChild = productId ? config.children[String(productId)] : null;
setInquiryState(Boolean(selectedChild && selectedChild.requiresInquiry));
}
function fillProductSummary() {
var options = [];
if (!selectedChild) {
return;
}
$.each(selectedChild.options || [], function (index, option) {
if (option.value) {
options.push(option.label + ': ' + option.value);
}
});
$form.find('[data-role="product-inquiry-product-id"]').val(selectedChild.id);
$modal.find('[data-role="product-inquiry-product-name"]').text(
config.parentName
);
$modal.find('[data-role="product-inquiry-product-options"]').text(options.join(' / '));
}
function closeAfterSuccess() {
window.clearTimeout(closeTimer);
closeTimer = window.setTimeout(function () {
$modal.modal('closeModal');
if ($form[0]) {
$form[0].reset();
}
$status.removeClass('success error').empty();
$submit.prop('disabled', false).removeClass('disabled');
}, 2000);
}
$trigger.on('click', function (event) {
event.preventDefault();
refreshState();
if (!selectedChild || !selectedChild.requiresInquiry) {
return;
}
fillProductSummary();
$status.removeClass('success error').empty();
$modal.modal('openModal');
});
$(document).on('click', '[data-role="esun-sticky-product-inquiry"]', function () {
$trigger.trigger('click');
});
$form.on('submit.esunProductInquiry', function (event) {
var closeOnSuccess = false;
event.preventDefault();
event.stopImmediatePropagation();
if (!$form.validation('isValid')) {
return;
}
$submit.prop('disabled', true).addClass('disabled');
$status.removeClass('success error').empty();
$.ajax({
url: config.submitUrl,
type: 'POST',
dataType: 'json',
data: $form.serialize()
}).done(function (response) {
if (response.success) {
if (!response.duplicate) {
$(document).trigger('esun:generateLead', {leadType: 'product_inquiry'});
}
closeOnSuccess = true;
$status.addClass('success').text(response.message);
closeAfterSuccess();
} else {
$status.addClass('error').text(response.message);
}
}).fail(function (xhr) {
var response = xhr.responseJSON || {};
$status.addClass('error').text(response.message || $t('Unable to submit your inquiry.'));
}).always(function () {
if (!closeOnSuccess) {
$submit.prop('disabled', false).removeClass('disabled');
}
});
});
$(document).on(
'click change configurable.initialized swatch.initialized',
'.swatch-option, .super-attribute-select, [name="selected_configurable_option"]',
function () {
window.setTimeout(refreshState, 20);
window.setTimeout(refreshState, 150);
}
);
[0, 100, 300, 800, 1200].forEach(function (delay) {
window.setTimeout(refreshState, delay);
});
};
});
@@ -0,0 +1,56 @@
define(['jquery', 'mage/utils/wrapper'], function ($, wrapper) {
'use strict';
return function (Widget) {
Widget.prototype._RenderControls = wrapper.wrapSuper(Widget.prototype._RenderControls, function () {
var config = this.options.jsonConfig || {},
widget = this,
result;
if (config.canDisplayShowOutOfStockStatus) {
config.salable = config.salable || {};
Object.keys(config.attributes || {}).forEach(function (key) {
var attributeId = config.attributes[key].id || key;
config.salable[attributeId] = config.salable[attributeId] || {};
});
}
result = this._super();
if (config.canDisplayShowOutOfStockStatus) {
Object.keys(config.attributes || {}).forEach(function (key) {
var attribute = config.attributes[key],
attributeId = attribute.id || key;
(attribute.options || []).forEach(function (option) {
if (widget.optionsMap[attributeId] && widget.optionsMap[attributeId][option.id]) {
widget.optionsMap[attributeId][option.id].products = (option.products || []).slice();
}
});
});
this._Rewind(this.element);
}
return result;
});
Widget.prototype.disableSwatchForOutOfStockProducts = function () {
var widget = this,
config = this.options.jsonConfig || {},
container = this.element;
if (!config.canDisplayShowOutOfStockStatus) {
return;
}
Object.keys(config.attributes || {}).forEach(function (key) {
var attributeId = config.attributes[key].id || key,
salable = (config.salable || {})[attributeId] || {};
widget.element.find('[data-attribute-id="' + attributeId + '"] .swatch-option').each(function () {
var option = String($(this).data('option-id'));
$(this).toggleClass('esun-out-of-stock-option', !Object.prototype.hasOwnProperty.call(salable, option));
});
});
};
return Widget;
};
});