Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REGISTER #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* 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
*/

package com.liferay.commerce.order.content.web.internal.info.item.provider;

import com.liferay.commerce.model.CommerceOrder;
import com.liferay.commerce.service.CommerceOrderLocalService;
import com.liferay.info.item.InfoItemFormVariation;
import com.liferay.info.item.provider.InfoItemFormVariationsProvider;
import com.liferay.info.localized.InfoLocalizedValue;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.security.auth.CompanyThreadLocal;
import com.liferay.portal.kernel.util.Portal;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* @author Jorge Ferrer
*/
@Component(service = InfoItemFormVariationsProvider.class)
public class CommerceOrderInfoItemFormVariationsProvider
implements InfoItemFormVariationsProvider<CommerceOrder> {

@Override
public InfoItemFormVariation getInfoItemFormVariation(
long groupId, String formVariationKey) {

String value = formVariationKey.equals("1") ? "open" : "closed";

try {
return new InfoItemFormVariation(
0,
formVariationKey,
InfoLocalizedValue.<String>builder(
).value(_portal.getSiteDefaultLocale(groupId),
value
).build());
}
catch (PortalException e) {
throw new RuntimeException(e);
}
}

@Override
public InfoItemFormVariation
getInfoItemFormVariationByExternalReferenceCode(
String externalReferenceCode, long groupId) {

try {
return new InfoItemFormVariation(
0,
"1",
InfoLocalizedValue.<String>builder(
).value(_portal.getSiteDefaultLocale(groupId),
"open"
).build());
}
catch (PortalException e) {
throw new RuntimeException(e);
}
}

@Override
public Collection<InfoItemFormVariation> getInfoItemFormVariations(
long groupId) {

return getInfoItemFormVariations(new long[]{groupId});
}

@Override
public Collection<InfoItemFormVariation> getInfoItemFormVariations(
long[] groupIds) {

List<InfoItemFormVariation> infoItemFormVariations = new ArrayList<>();

try {
infoItemFormVariations.add(new InfoItemFormVariation(
0,
"1",
InfoLocalizedValue.<String>builder(
).value(_portal.getSiteDefaultLocale(groupIds[0]),
"open"
).build()));

infoItemFormVariations.add(new InfoItemFormVariation(
0,
"0",
InfoLocalizedValue.<String>builder(
).value(_portal.getSiteDefaultLocale(groupIds[0]),
"closed"
).build()));
}
catch (PortalException e) {
throw new RuntimeException(e);
}

return infoItemFormVariations;
}

@Reference
private CommerceOrderLocalService _commerceOrderLocalService;

@Reference
private Portal _portal;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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
*/

package com.liferay.commerce.order.content.web.internal.info.item.provider;

import com.liferay.commerce.model.CommerceOrder;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.info.item.provider.InfoItemObjectVariationProvider;
import com.liferay.journal.model.JournalArticle;
import com.liferay.portal.kernel.language.Language;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import java.util.Locale;

/**
* @author Eudaldo Alonso
*/
@Component(service = InfoItemObjectVariationProvider.class)
public class CommerceOrderInfoItemObjectVariationProvider
implements InfoItemObjectVariationProvider<CommerceOrder> {

@Override
public String getInfoItemFormVariationKey(CommerceOrder commerceOrder) {
if (commerceOrder == null) {
return null;
}

return String.valueOf(commerceOrder.isOpen() ? 1 : 0);
}

@Override
public String getInfoItemFormVariationLabel(
CommerceOrder commerceOrder, Locale locale) {

if (commerceOrder.isOpen()) {
return _language.get(locale, "open");
}

return _language.get(locale, "closed");
}

@Reference
private Language _language;
}