META-INF.resources.checkout_step.address.jsp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.commerce.checkout.web
Show all versions of com.liferay.commerce.checkout.web
Liferay Commerce Checkout Web
<%--
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
--%>
<%@ include file="/init.jsp" %>
<%
CommerceContext commerceContext = (CommerceContext)request.getAttribute(CommerceWebKeys.COMMERCE_CONTEXT);
AccountEntry accountEntry = commerceContext.getAccountEntry();
CommerceOrder commerceOrder = commerceContext.getCommerceOrder();
BaseAddressCheckoutStepDisplayContext baseAddressCheckoutStepDisplayContext = (BaseAddressCheckoutStepDisplayContext)request.getAttribute(CommerceCheckoutWebKeys.COMMERCE_CHECKOUT_STEP_DISPLAY_CONTEXT);
List commerceAddresses = baseAddressCheckoutStepDisplayContext.getCommerceAddresses();
long commerceAddressId = baseAddressCheckoutStepDisplayContext.getCommerceAddressId(request);
CommerceAddress currentCommerceAddress = baseAddressCheckoutStepDisplayContext.getCommerceAddress(commerceAddressId);
boolean hasManageAddressesPermission = baseAddressCheckoutStepDisplayContext.hasPermission(permissionChecker, accountEntry, AccountActionKeys.MANAGE_ADDRESSES);
String paramName = baseAddressCheckoutStepDisplayContext.getParamName();
%>
<%
for (CommerceAddress commerceAddress : commerceAddresses) {
%>
<%
}
%>
1
Liferay.provide(
window,
' addStreetAddress',
function addStreetAddress() {
const addStreetFields = document.querySelector('.add-street-fields');
const addStreetLink = document.querySelector('.add-street-link');
if (addStreetFields) {
addStreetFields.classList.remove('hide');
}
if (addStreetLink) {
addStreetLink.classList.add('hide');
}
},
['aui-base']
);
Liferay.provide(
window,
' clearAddressFields',
function clearAddressFields() {
const addressFieldsInputs = document.querySelectorAll(
'.address-fields input'
);
const addressFieldsSelect = document.querySelectorAll(
'.address-fields select'
);
addressFieldsInputs.forEach((input) => {
input.value = '';
});
addressFieldsSelect.forEach((select) => {
select.selectedIndex = 0;
});
const useAsBillingField = document.getElementById(
' use-as-billing'
);
if (useAsBillingField) {
useAsBillingField.checked =
<%= baseAddressCheckoutStepDisplayContext.isShippingUsedAsBilling() %>;
}
},
['aui-base']
);
Liferay.provide(
window,
' selectAddress',
function selectAddress() {
const commerceAddress = document.getElementById(
' commerceAddress'
);
const commerceAddressParamName = document.getElementById(
'<%= liferayPortletResponse.getNamespace() + paramName %>'
);
const newAddress = document.getElementById(
' newAddress'
);
if (newAddress && commerceAddress && commerceAddressParamName) {
const commerceAddressVal = commerceAddress.value;
if (commerceAddressVal === '0') {
clearAddressFields();
if (<%= hasManageAddressesPermission %>) {
toggleAddressFields(false);
}
}
else {
updateAddressFields(
commerceAddress.selectedIndex
);
Liferay.Form.get(
' fm'
).formValidator.validate();
}
commerceAddressParamName.value = commerceAddressVal;
newAddress.value = Number(commerceAddressVal === '0');
}
},
['aui-base']
);
Liferay.provide(
window,
' toggleAddressFields',
function toggleAddressFields(state) {
Liferay.Util.toggleDisabled(
document.querySelectorAll('.address-fields input'),
state
);
Liferay.Util.toggleDisabled(
document.querySelectorAll('.address-fields select'),
state
);
const commerceRegionIdInput = document.getElementById(
' commerceRegionIdInput'
);
const commerceRegionIdName = document.getElementById(
' commerceRegionIdName'
);
const commerceRegionIdSelect = document.getElementById(
' regionId'
);
commerceRegionIdInput.name = 'commerceRegionIdInputDisabled';
commerceRegionIdName.name = 'commerceRegionIdInputDisabled';
commerceRegionIdSelect.name = ' regionId';
commerceRegionIdInput.parentElement.classList.add('d-none');
commerceRegionIdName.parentElement.classList.add('d-none');
commerceRegionIdSelect.parentElement.classList.remove('d-none');
},
['aui-base']
);
Liferay.provide(
window,
' updateAddressFields',
function updateAddressFields(selectedVal) {
if (!selectedVal || selectedVal === '0') {
return;
}
const commerceAddress = document.getElementById(
' commerceAddress'
);
if (commerceAddress) {
addStreetAddress();
toggleAddressFields(true);
const city = document.getElementById(' city');
const countryId = document.getElementById(
' countryId'
);
const commerceRegionIdInput = document.getElementById(
' commerceRegionIdInput'
);
const commerceRegionIdName = document.getElementById(
' commerceRegionIdName'
);
const commerceRegionIdSelect = document.getElementById(
' regionId'
);
const name = document.getElementById(' name');
const phoneNumber = document.getElementById(
' phoneNumber'
);
const street1 = document.getElementById(
' street1'
);
const street2 = document.getElementById(
' street2'
);
const street3 = document.getElementById(
' street3'
);
const zip = document.getElementById(' zip');
if (
city &&
countryId &&
commerceRegionIdInput &&
commerceRegionIdSelect &&
commerceRegionIdName &&
name &&
phoneNumber &&
street1 &&
street2 &&
street3 &&
zip
) {
const selectedOption =
commerceAddress.options[commerceAddress.selectedIndex];
city.value = selectedOption.dataset.city;
commerceRegionIdInput.value = selectedOption.dataset.region;
countryId.value = selectedOption.dataset.country;
name.value = selectedOption.dataset.name;
phoneNumber.value = selectedOption.dataset.phoneNumber;
street1.value = selectedOption.dataset['street-1'];
street2.value = selectedOption.dataset['street-2'];
street3.value = selectedOption.dataset['street-3'];
zip.value = selectedOption.dataset.zip;
commerceRegionIdInput.name = ' regionId';
commerceRegionIdName.name = 'commerceRegionIdNameIgnore';
commerceRegionIdSelect.name = 'commerceRegionIdSelectIgnore';
commerceRegionIdInput.parentElement.classList.add('d-none');
commerceRegionIdName.parentElement.classList.remove('d-none');
commerceRegionIdSelect.parentElement.classList.add('d-none');
Liferay.Service(
'/region/get-regions',
{
active: true,
countryId: parseInt(selectedOption.dataset.country, 10),
},
function setUIOnlyInputRegionName(regions) {
for (let i = 0; i < regions.length; i++) {
if (
regions[i].regionId ===
selectedOption.dataset.region
) {
commerceRegionIdName.value = regions[i].name;
break;
}
}
}
);
}
}
},
['aui-base']
);
Liferay.component(
' countrySelects',
new Liferay.DynamicSelect([
{
select: ' countryId',
selectData: function (callback) {
function injectCountryPlaceholder(list) {
const callbackList = [
{
countryId: '0',
nameCurrentValue:
'- ',
},
];
list.forEach((listElement) => {
callbackList.push(listElement);
});
callback(callbackList);
}
Liferay.Service(
'/commerce.commercecountrymanagerimpl/<%= baseAddressCheckoutStepDisplayContext.getCommerceCountrySelectionMethodName() %>-by-channel-id',
{
channelId:
<%= commerceContext.getCommerceChannelId() %>,
end: -1,
start: -1,
},
injectCountryPlaceholder
);
},
selectDesc: 'nameCurrentValue',
selectId: 'countryId',
selectNullable: <%= false %>,
selectSort: '<%= true %>',
selectVal:
'<%= BeanParamUtil.getLong(currentCommerceAddress, request, "countryId", 0) %>',
},
{
select: ' regionId',
selectData: function (callback, selectKey) {
function injectRegionPlaceholder(list) {
const callbackList = [
{
regionId: '0',
name: '- ',
nameCurrentValue:
'- ',
},
];
list.forEach((listElement) => {
callbackList.push(listElement);
});
callback(callbackList);
}
Liferay.Service(
'/region/get-regions',
{
active: true,
countryId: Number(selectKey),
},
injectRegionPlaceholder
);
},
selectDesc: 'name',
selectId: 'regionId',
selectNullable: <%= false %>,
selectVal:
'<%= BeanParamUtil.getLong(currentCommerceAddress, request, "regionId", 0) %>',
},
])
);
© 2015 - 2025 Weber Informatics LLC | Privacy Policy