
com.liferay.commerce.product.internal.events.CPRulesPreAction Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.commerce.product.internal.events;
import com.liferay.commerce.product.model.CPRule;
import com.liferay.commerce.product.service.CPRuleLocalService;
import com.liferay.commerce.product.util.CPRulesThreadLocal;
import com.liferay.commerce.user.segment.util.CommerceUserSegmentHelper;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.LifecycleAction;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.util.Portal;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Andrea Di Giorgi
*/
@Component(
property = "key=servlet.service.events.pre", service = LifecycleAction.class
)
public class CPRulesPreAction extends Action {
@Override
public void run(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
throws ActionException {
try {
long groupId = _portal.getScopeGroupId(httpServletRequest);
long[] commerceUserSegmentEntryIds =
_commerceUserSegmentHelper.getCommerceUserSegmentIds(
httpServletRequest);
List cpRules = _cpRuleLocalService.getCPRules(
groupId, commerceUserSegmentEntryIds);
CPRulesThreadLocal.setCPRules(cpRules);
}
catch (PortalException pe) {
throw new ActionException(pe);
}
}
@Reference
private CommerceUserSegmentHelper _commerceUserSegmentHelper;
@Reference
private CPRuleLocalService _cpRuleLocalService;
@Reference
private Portal _portal;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy