Skip to content

Commit 3ae311d

Browse files
commerce order status override reusable component added
1 parent e75a608 commit 3ae311d

17 files changed

+1671
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.gradle/
3+
build/
4+
target/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Bundle-Name: commerce-order-status-override
2+
Bundle-SymbolicName: com.liferay.commerce.order.status.override
3+
Bundle-Version: 1.0.0
4+
Export-Package: com.liferay.commerce.order.status.override.constants
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
compileOnly group: "com.liferay.portal", name: "release.dxp.api", version:"2024.q1.1"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.liferay.commerce.order.status.override;
2+
3+
import com.liferay.commerce.constants.CommerceOrderConstants;
4+
import com.liferay.commerce.model.CommerceOrder;
5+
import com.liferay.commerce.order.status.CommerceOrderStatus;
6+
import com.liferay.commerce.service.CommerceOrderService;
7+
import com.liferay.portal.kernel.exception.PortalException;
8+
import com.liferay.portal.kernel.language.LanguageUtil;
9+
import com.liferay.commerce.order.status.override.constants.CommerceOrderStatusOverrideConstants;
10+
11+
import java.util.Locale;
12+
13+
import org.osgi.service.component.annotations.Component;
14+
import org.osgi.service.component.annotations.Reference;
15+
16+
/**
17+
* @author Payal
18+
*/
19+
@Component(property = {
20+
"commerce.order.status.key=" + CommerceOrderStatusOverrideConstants.ORDER_STATUS_AWAITING_PAYMENT,
21+
"commerce.order.status.priority:Integer=" + AwaitingPaymentOrderStatusOverride.PRIORITY,
22+
"service.ranking:Integer=100" }, service = CommerceOrderStatus.class)
23+
24+
public class AwaitingPaymentOrderStatusOverride implements CommerceOrderStatus {
25+
26+
public static final int PRIORITY = 50;
27+
28+
/**
29+
* Called on transition change for order status
30+
*
31+
* @param commerceOrder
32+
* @param userId
33+
* @return commerceOrder
34+
*/
35+
@Override
36+
public CommerceOrder doTransition(CommerceOrder commerceOrder, long userId, boolean secure) throws PortalException {
37+
38+
commerceOrder.setOrderStatus(CommerceOrderStatusOverrideConstants.ORDER_STATUS_AWAITING_PAYMENT);
39+
return commerceOrderService.updateCommerceOrder(commerceOrder);
40+
}
41+
42+
43+
/**
44+
* Get key
45+
*
46+
* @return key in int
47+
*/
48+
@Override
49+
public int getKey() {
50+
return CommerceOrderStatusOverrideConstants.ORDER_STATUS_AWAITING_PAYMENT;
51+
}
52+
53+
/**
54+
* Get Label
55+
*
56+
* @param locale
57+
* @return order status label
58+
*/
59+
@Override
60+
public String getLabel(Locale locale) {
61+
return LanguageUtil.get(locale, CommerceOrderStatusOverrideConstants.ORDER_STATUS_AWAITING_PAYMENT_LABEL);
62+
}
63+
64+
/**
65+
* Get priority
66+
*
67+
* @return priority in int
68+
*/
69+
@Override
70+
public int getPriority() {
71+
return PRIORITY;
72+
}
73+
74+
/**
75+
* verify the order is in complete state or not
76+
*
77+
* @param commerceOrder
78+
* @return true or false
79+
*/
80+
@Override
81+
public boolean isComplete(CommerceOrder commerceOrder) {
82+
boolean isComplete = Boolean.FALSE;
83+
84+
if (!commerceOrder.isOpen() && commerceOrder.isApproved()
85+
&& (commerceOrder.getOrderStatus() != CommerceOrderConstants.ORDER_STATUS_PROCESSING)) {
86+
isComplete = Boolean.TRUE;
87+
}
88+
89+
90+
return isComplete;
91+
92+
}
93+
94+
/**
95+
* Check transition criteria met or not based on next status will be enable
96+
*
97+
* @param commerceOrder
98+
* @return true or false
99+
*/
100+
@Override
101+
public boolean isTransitionCriteriaMet(CommerceOrder commerceOrder) throws PortalException {
102+
boolean isTransitionMet = Boolean.FALSE;
103+
104+
if (commerceOrder.getOrderStatus() == CommerceOrderStatusOverrideConstants.ORDER_STATUS_PLACED) {
105+
isTransitionMet = Boolean.TRUE;
106+
}
107+
108+
return isTransitionMet;
109+
110+
}
111+
112+
113+
@Reference
114+
private CommerceOrderService commerceOrderService;
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.liferay.commerce.order.status.override;
2+
3+
import com.liferay.commerce.constants.CommerceOrderConstants;
4+
import com.liferay.commerce.model.CommerceOrder;
5+
import com.liferay.commerce.order.status.CommerceOrderStatus;
6+
import com.liferay.commerce.service.CommerceOrderService;
7+
import com.liferay.portal.kernel.exception.PortalException;
8+
import com.liferay.portal.kernel.language.LanguageUtil;
9+
import com.liferay.commerce.order.status.override.constants.CommerceOrderStatusOverrideConstants;
10+
11+
import java.util.Locale;
12+
13+
import org.osgi.service.component.annotations.Component;
14+
import org.osgi.service.component.annotations.Reference;
15+
16+
/**
17+
* @author Payal
18+
*/
19+
@Component(property = { "commerce.order.status.key=" + CancelledOrderStatusOverride.KEY,
20+
"commerce.order.status.priority:Integer=" + CancelledOrderStatusOverride.PRIORITY,
21+
"service.ranking:Integer=100" }, service = CommerceOrderStatus.class)
22+
public class CancelledOrderStatusOverride implements CommerceOrderStatus {
23+
24+
public static final int KEY = CommerceOrderConstants.ORDER_STATUS_CANCELLED;
25+
26+
public static final int PRIORITY = 54;
27+
28+
/**
29+
* Called on transition change for order status
30+
*
31+
* @param commerceOrder
32+
* @param userId
33+
* @return commerceOrder
34+
*/
35+
@Override
36+
public CommerceOrder doTransition(CommerceOrder commerceOrder, long userId, boolean secure) throws PortalException {
37+
38+
commerceOrder.setOrderStatus(KEY);
39+
40+
return commerceOrderService.updateCommerceOrder(commerceOrder);
41+
}
42+
43+
/**
44+
* Get key
45+
*
46+
* @return key in int
47+
*/
48+
@Override
49+
public int getKey() {
50+
return KEY;
51+
}
52+
53+
/**
54+
* Get Label
55+
*
56+
* @param locale
57+
* @return order status label
58+
*/
59+
@Override
60+
public String getLabel(Locale locale) {
61+
return LanguageUtil.get(locale, CommerceOrderConstants.getOrderStatusLabel(KEY));
62+
}
63+
64+
/**
65+
* Get priority
66+
*
67+
* @return priority in int
68+
*/
69+
@Override
70+
public int getPriority() {
71+
return PRIORITY;
72+
}
73+
74+
/**
75+
* Check transition criteria met or not based on next status will be enable
76+
*
77+
* @param commerceOrder
78+
* @return true or false
79+
*/
80+
@Override
81+
public boolean isTransitionCriteriaMet(CommerceOrder commerceOrder) throws PortalException {
82+
boolean isTransitionMet = Boolean.FALSE;
83+
84+
if ((commerceOrder.getOrderStatus() == CommerceOrderStatusOverrideConstants.ORDER_STATUS_PENDING_CANCELLATION)) {
85+
isTransitionMet = Boolean.TRUE;
86+
}
87+
return isTransitionMet;
88+
89+
}
90+
91+
/**
92+
* Check the status is valid for current status
93+
*
94+
* @param commerceOrder
95+
* @return true or false
96+
*/
97+
@Override
98+
public boolean isValidForOrder(CommerceOrder commerceOrder) throws PortalException {
99+
boolean isValid = Boolean.FALSE;
100+
101+
if (commerceOrder.getOrderStatus() == CommerceOrderStatusOverrideConstants.ORDER_STATUS_PENDING_CANCELLATION
102+
|| commerceOrder.getOrderStatus() == CommerceOrderConstants.ORDER_STATUS_CANCELLED) {
103+
isValid = Boolean.TRUE;
104+
}
105+
return isValid;
106+
107+
}
108+
109+
@Reference
110+
private CommerceOrderService commerceOrderService;
111+
112+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.liferay.commerce.order.status.override;
2+
3+
import com.liferay.commerce.constants.CommerceOrderConstants;
4+
import com.liferay.commerce.model.CommerceOrder;
5+
import com.liferay.commerce.order.status.CommerceOrderStatus;
6+
import com.liferay.commerce.service.CommerceOrderService;
7+
import com.liferay.commerce.util.CommerceShippingHelper;
8+
import com.liferay.portal.kernel.exception.PortalException;
9+
import com.liferay.commerce.order.status.override.constants.CommerceOrderStatusOverrideConstants;
10+
11+
import java.util.Locale;
12+
13+
import org.osgi.service.component.annotations.Component;
14+
import org.osgi.service.component.annotations.Reference;
15+
16+
@Component(property = { "commerce.order.status.key=" + CommerceOrderConstants.ORDER_STATUS_COMPLETED,
17+
"commerce.order.status.priority:Integer=" + CompletedOrderStatusOverride.PRIORITY,
18+
"service.ranking:Integer=100" }, service = CommerceOrderStatus.class)
19+
public class CompletedOrderStatusOverride implements CommerceOrderStatus {
20+
21+
public static final int KEY = CommerceOrderConstants.ORDER_STATUS_COMPLETED;
22+
23+
public static final int PRIORITY = 70;
24+
25+
/**
26+
* Called on transition change for order status
27+
*
28+
* @param commerceOrder
29+
* @param userId
30+
* @return commerceOrder
31+
*/
32+
@Override
33+
public CommerceOrder doTransition(CommerceOrder commerceOrder, long userId, boolean secure) throws PortalException {
34+
35+
commerceOrder.setOrderStatus(KEY);
36+
37+
return commerceOrderService.updateCommerceOrder(commerceOrder);
38+
}
39+
40+
/**
41+
* Get key
42+
*
43+
* @return key in int
44+
*/
45+
@Override
46+
public int getKey() {
47+
return KEY;
48+
}
49+
50+
/**
51+
* Get Label
52+
*
53+
* @param locale
54+
* @return order status label
55+
*/
56+
@Override
57+
public String getLabel(Locale locale) {
58+
return CommerceOrderStatusOverrideConstants.ORDER_STATUS_COMPLETED_LABEL;
59+
}
60+
61+
/**
62+
* Get priority
63+
*
64+
* @return priority in int
65+
*/
66+
@Override
67+
public int getPriority() {
68+
return PRIORITY;
69+
}
70+
71+
/**
72+
* Check transition criteria met or not based on next status will be enable
73+
*
74+
* @param commerceOrder
75+
* @return true or false
76+
*/
77+
@Override
78+
public boolean isTransitionCriteriaMet(CommerceOrder commerceOrder) throws PortalException {
79+
boolean isTransitionMet = Boolean.FALSE;
80+
81+
if ((commerceOrder.getOrderStatus() == CommerceOrderConstants.ORDER_STATUS_SHIPPED)
82+
|| ((commerceOrder.getOrderStatus() == CommerceOrderConstants.ORDER_STATUS_PROCESSING)
83+
&& !commerceShippingHelper.isShippable(commerceOrder))) {
84+
isTransitionMet = Boolean.TRUE;
85+
}
86+
87+
return isTransitionMet;
88+
89+
}
90+
91+
/**
92+
* Check the status is valid for current status
93+
*
94+
* @param commerceOrder
95+
* @return true or false
96+
*/
97+
@Override
98+
public boolean isValidForOrder(CommerceOrder commerceOrder) throws PortalException {
99+
boolean isValid = Boolean.TRUE;
100+
101+
if (commerceOrder.getOrderStatus() == CommerceOrderConstants.ORDER_STATUS_CANCELLED || commerceOrder
102+
.getOrderStatus() == CommerceOrderStatusOverrideConstants.ORDER_STATUS_PENDING_CANCELLATION) {
103+
isValid = Boolean.FALSE;
104+
}
105+
return isValid;
106+
107+
}
108+
109+
@Reference
110+
private CommerceOrderService commerceOrderService;
111+
112+
@Reference
113+
private CommerceShippingHelper commerceShippingHelper;
114+
}

0 commit comments

Comments
 (0)