init
This commit is contained in:
@@ -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;
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user