init
This commit is contained in:
@@ -0,0 +1,276 @@
|
||||
.customer-coupons {
|
||||
padding: 4px 0 40px;
|
||||
}
|
||||
|
||||
.customer-coupons__tabs {
|
||||
display: flex;
|
||||
gap: 34px;
|
||||
margin-bottom: 28px;
|
||||
border-bottom: 1px solid #d9dddf;
|
||||
}
|
||||
|
||||
.customer-coupons__tab {
|
||||
position: relative;
|
||||
padding: 12px 0 14px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #777;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.customer-coupons__tab:hover,
|
||||
.customer-coupons__tab:focus,
|
||||
.customer-coupons__tab:active {
|
||||
border: 0 !important;
|
||||
background: transparent !important;
|
||||
color: #777;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.customer-coupons__tab.is-active:hover,
|
||||
.customer-coupons__tab.is-active:focus,
|
||||
.customer-coupons__tab.is-active:active {
|
||||
color: #18a957;
|
||||
}
|
||||
|
||||
.customer-coupons__tab.is-active {
|
||||
color: #18a957;
|
||||
}
|
||||
|
||||
.customer-coupons__tab.is-active::after {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: -1px;
|
||||
left: 0;
|
||||
height: 3px;
|
||||
background: #18a957;
|
||||
content: "";
|
||||
}
|
||||
|
||||
.customer-coupons__grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.customer-coupons__panel[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.customer-coupon-card {
|
||||
display: grid;
|
||||
grid-template-columns: 150px minmax(0, 1fr);
|
||||
border: 1px solid #dce1e3;
|
||||
border-radius: 12px;
|
||||
background: #fff;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.customer-coupon-card__discount {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px 16px;
|
||||
background: #18a957;
|
||||
color: #fff;
|
||||
font-size: 23px;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.customer-coupon-card.is-unavailable {
|
||||
opacity: .68;
|
||||
}
|
||||
|
||||
.customer-coupon-card.is-unavailable .customer-coupon-card__discount {
|
||||
background: #8d9498;
|
||||
}
|
||||
|
||||
.customer-coupon-card__body {
|
||||
min-width: 0;
|
||||
padding: 22px 24px;
|
||||
}
|
||||
|
||||
.customer-coupon-card__body h3 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
.customer-coupon-card__code {
|
||||
margin-bottom: 12px;
|
||||
color: #18a957;
|
||||
font-family: monospace;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.customer-coupon-card__body ul {
|
||||
margin: 0 0 14px 12px;
|
||||
color: #666;
|
||||
padding-inline-start: 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.customer-coupon-card__body ul li{
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.customer-coupon-card__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 8px 16px;
|
||||
color: #747a7d;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.customer-coupon-card__meta strong {
|
||||
color: #b23b3b;
|
||||
}
|
||||
|
||||
.customer-coupons__empty {
|
||||
display: flex;
|
||||
min-height: 330px;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #8a9093;
|
||||
}
|
||||
|
||||
.customer-coupons__empty-icon {
|
||||
display: flex;
|
||||
width: 92px;
|
||||
height: 62px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 8px;
|
||||
background: #e3e5e6;
|
||||
color: #aeb3b5;
|
||||
font-size: 36px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.customer-coupons__grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.customer-coupon-card {
|
||||
grid-template-columns: 110px minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.customer-coupon-card__discount {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.customer-coupon-picker-modal .modal-inner-wrap {
|
||||
width: calc(100% - 40px);
|
||||
max-width: 960px;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__loading,
|
||||
.customer-coupon-picker__empty,
|
||||
.customer-coupon-picker__message {
|
||||
padding: 34px 12px;
|
||||
color: #6e7477;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__message.is-error {
|
||||
color: #b3261e;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item {
|
||||
width: 100%;
|
||||
grid-template-columns: 110px minmax(0, 1fr);
|
||||
cursor: pointer;
|
||||
transition: border-color .2s ease, box-shadow .2s ease, opacity .2s ease;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item .customer-coupon-card__discount {
|
||||
padding: 20px 12px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item .customer-coupon-card__body {
|
||||
padding: 18px 16px;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item .customer-coupon-card__body h3 {
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item:not(.is-applied):hover,
|
||||
.customer-coupon-picker__item:not(.is-applied):focus {
|
||||
border-color: #18a957;
|
||||
box-shadow: 0 4px 14px rgb(24 169 87 / 16%);
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item.is-applied {
|
||||
cursor: default;
|
||||
opacity: .72;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item.is-applied .customer-coupon-card__meta strong {
|
||||
color: #168b4b;
|
||||
}
|
||||
|
||||
.customer-coupon-picker__item.is-loading {
|
||||
cursor: wait;
|
||||
opacity: .55;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.customer-coupon-picker__list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-coupon__picker-button {
|
||||
flex: 0 0 auto;
|
||||
min-width: 108px;
|
||||
height: 40px;
|
||||
padding: 0 14px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #168b4b;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
text-decoration: underline;
|
||||
white-space: nowrap;
|
||||
box-shadow: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.esun-coupon__picker-button:hover,
|
||||
.esun-coupon__picker-button:focus,
|
||||
.esun-coupon__picker-button:active {
|
||||
border: 0 !important;
|
||||
background: transparent !important;
|
||||
color: #168b4b;
|
||||
box-shadow: none !important;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.checkout-cart-index .esun-coupon__picker-button {
|
||||
height: 46px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.esun-coupon__applied .esun-coupon__picker-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
define(['jquery'], function ($) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $root = $(element);
|
||||
|
||||
$root.on('click', '[data-coupon-tab]', function () {
|
||||
var status = $(this).attr('data-coupon-tab');
|
||||
|
||||
$root.find('[data-coupon-tab]')
|
||||
.removeClass('is-active')
|
||||
.attr('aria-selected', 'false');
|
||||
$(this).addClass('is-active').attr('aria-selected', 'true');
|
||||
$root.find('[data-coupon-panel]').removeClass('is-active').prop('hidden', true);
|
||||
$root.find('[data-coupon-panel="' + status + '"]')
|
||||
.addClass('is-active')
|
||||
.prop('hidden', false);
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Ui/js/modal/modal',
|
||||
'Esun_Cart/js/model/coupon-service',
|
||||
'mage/translate'
|
||||
], function ($, modal, couponService) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $modal = $(element),
|
||||
$list = $modal.find('[data-role="coupon-picker-list"]'),
|
||||
$loading = $modal.find('[data-role="coupon-picker-loading"]'),
|
||||
$empty = $modal.find('[data-role="coupon-picker-empty"]'),
|
||||
$message = $modal.find('[data-role="coupon-picker-message"]');
|
||||
|
||||
modal({
|
||||
type: 'popup',
|
||||
title: $.mage.__('My Coupons'),
|
||||
modalClass: 'customer-coupon-picker-modal',
|
||||
responsive: true,
|
||||
innerScroll: true,
|
||||
buttons: []
|
||||
}, $modal);
|
||||
|
||||
$(document).on('click.esunCustomerCoupon', '[data-role="open-coupon-picker"]', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$modal.modal('openModal');
|
||||
loadCoupons();
|
||||
});
|
||||
|
||||
$modal.on('click', '[data-role="apply-customer-coupon"]', function () {
|
||||
applyCoupon($(this));
|
||||
});
|
||||
|
||||
$modal.on('keydown', '[data-role="apply-customer-coupon"]', function (event) {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault();
|
||||
applyCoupon($(this));
|
||||
}
|
||||
});
|
||||
|
||||
function applyCoupon($item) {
|
||||
var code = String($item.attr('data-coupon-code') || '');
|
||||
|
||||
if (!code || $item.attr('aria-disabled') === 'true' || $item.hasClass('is-loading')) {
|
||||
return;
|
||||
}
|
||||
$item.addClass('is-loading').attr('aria-busy', 'true');
|
||||
showMessage('', false);
|
||||
couponService.apply(code).done(function (response) {
|
||||
if (!response || !response.success) {
|
||||
showMessage(response && response.message
|
||||
? response.message
|
||||
: $.mage.__('We could not apply this coupon.'), true);
|
||||
return;
|
||||
}
|
||||
$modal.modal('closeModal');
|
||||
$(document).trigger('esun:customerCouponApplied', [response]);
|
||||
}).fail(function (xhr) {
|
||||
var response = xhr.responseJSON || {};
|
||||
showMessage(response.message || $.mage.__('We could not apply this coupon.'), true);
|
||||
}).always(function () {
|
||||
$item.removeClass('is-loading').removeAttr('aria-busy');
|
||||
});
|
||||
}
|
||||
|
||||
function loadCoupons() {
|
||||
$list.empty();
|
||||
$empty.prop('hidden', true);
|
||||
showMessage('', false);
|
||||
$loading.prop('hidden', false);
|
||||
|
||||
$.ajax({url: config.listUrl, type: 'get', dataType: 'json', cache: false})
|
||||
.done(function (response) {
|
||||
var coupons = response && response.coupons ? response.coupons : [],
|
||||
currentCouponCode = String(response && response.current_coupon_code || '');
|
||||
|
||||
if (!coupons.length) {
|
||||
$empty.prop('hidden', false);
|
||||
return;
|
||||
}
|
||||
$.each(coupons, function (index, coupon) {
|
||||
$list.append(renderCoupon(coupon, currentCouponCode));
|
||||
});
|
||||
})
|
||||
.fail(function (xhr) {
|
||||
var response = xhr.responseJSON || {};
|
||||
|
||||
if (xhr.status === 401) {
|
||||
window.location.href = config.loginUrl;
|
||||
return;
|
||||
}
|
||||
showMessage(response.message || $.mage.__('We could not load your coupons.'), true);
|
||||
})
|
||||
.always(function () {
|
||||
$loading.prop('hidden', true);
|
||||
});
|
||||
}
|
||||
|
||||
function renderCoupon(coupon, currentCouponCode) {
|
||||
var $item,
|
||||
$body = $('<div></div>', {'class': 'customer-coupon-card__body'}),
|
||||
$conditions = $('<ul></ul>'),
|
||||
$meta = $('<div></div>', {'class': 'customer-coupon-card__meta'}),
|
||||
isApplied = String(coupon.code) === currentCouponCode;
|
||||
|
||||
$item = $('<article></article>', {
|
||||
'class': 'customer-coupon-card customer-coupon-picker__item is-available' +
|
||||
(isApplied ? ' is-applied' : ''),
|
||||
role: 'button',
|
||||
tabindex: isApplied ? '-1' : '0',
|
||||
'aria-disabled': isApplied ? 'true' : 'false',
|
||||
'data-role': 'apply-customer-coupon',
|
||||
'data-coupon-code': coupon.code
|
||||
});
|
||||
$('<div></div>', {'class': 'customer-coupon-card__discount'})
|
||||
.text(coupon.discount_label).appendTo($item);
|
||||
$('<h3></h3>').text(coupon.rule_name).appendTo($body);
|
||||
$('<div></div>', {'class': 'customer-coupon-card__code'})
|
||||
.text(coupon.code).appendTo($body);
|
||||
$.each(coupon.conditions || [], function (index, condition) {
|
||||
$('<li></li>').text(condition).appendTo($conditions);
|
||||
});
|
||||
if ($conditions.children().length) {
|
||||
$conditions.appendTo($body);
|
||||
}
|
||||
$('<span></span>')
|
||||
.text(coupon.expires_at
|
||||
? $.mage.__('Valid through') + ' ' + coupon.expires_at
|
||||
: $.mage.__('No expiration date'))
|
||||
.appendTo($meta);
|
||||
if (isApplied) {
|
||||
$('<strong></strong>').text($.mage.__('Applied')).appendTo($meta);
|
||||
}
|
||||
$meta.appendTo($body);
|
||||
$body.appendTo($item);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
function showMessage(text, isError) {
|
||||
$message
|
||||
.text(text)
|
||||
.toggleClass('is-error', Boolean(isError))
|
||||
.prop('hidden', !text);
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user