Skip to content

Commit c39c374

Browse files
author
jefffischer
committed
Merge pull request BroadleafCommerce#79 from BroadleafCommerce/qa-812-punchout2go_4.0.x
Extensions and changes made to CartState and CustomerState to support Punchout2Go
2 parents 2f0b585 + 5459db8 commit c39c374

File tree

6 files changed

+155
-15
lines changed

6 files changed

+155
-15
lines changed

core/broadleaf-framework-web/src/main/java/org/broadleafcommerce/core/web/controller/cart/BroadleafCartController.java

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class BroadleafCartController extends AbstractCartController {
6161
@Value("${solr.index.use.sku}")
6262
protected boolean useSku;
6363

64+
6465
/**
6566
* Renders the cart page.
6667
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* #%L
3+
* BroadleafCommerce Framework Web
4+
* %%
5+
* Copyright (C) 2009 - 2013 Broadleaf Commerce
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package org.broadleafcommerce.core.web.order.security;
21+
22+
import org.broadleafcommerce.common.extension.AbstractExtensionHandler;
23+
import org.broadleafcommerce.common.extension.ExtensionResultHolder;
24+
import org.broadleafcommerce.common.extension.ExtensionResultStatusType;
25+
import org.broadleafcommerce.core.order.domain.Order;
26+
import org.broadleafcommerce.profile.core.domain.Customer;
27+
import org.springframework.web.context.request.WebRequest;
28+
29+
30+
/**
31+
* @author bpolster
32+
*/
33+
public abstract class AbstractCartStateRequestProcessorExtensionHandler extends AbstractExtensionHandler
34+
implements CartStateRequestProcessorExtensionHandler {
35+
36+
/**
37+
* Allows an extension to return a cart skipping the out of box processing that
38+
* normally performs this function.
39+
* @param resultHolder
40+
* @return
41+
*/
42+
@Override
43+
public ExtensionResultStatusType lookupOrCreateCart(WebRequest request, Customer customer, ExtensionResultHolder<Order> resultHolder) {
44+
return ExtensionResultStatusType.NOT_HANDLED;
45+
}
46+
}

core/broadleaf-framework-web/src/main/java/org/broadleafcommerce/core/web/order/security/CartStateRequestProcessor.java

+24-12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
2424
import org.broadleafcommerce.common.crossapp.service.CrossAppAuthService;
25+
import org.broadleafcommerce.common.extension.ExtensionResultHolder;
2526
import org.broadleafcommerce.common.util.BLCRequestUtils;
2627
import org.broadleafcommerce.common.web.AbstractBroadleafWebRequestProcessor;
2728
import org.broadleafcommerce.common.web.BroadleafWebRequestProcessor;
@@ -74,6 +75,9 @@ public class CartStateRequestProcessor extends AbstractBroadleafWebRequestProces
7475

7576
private final String mergeCartResponseKey = "bl_merge_cart_response";
7677

78+
@Resource(name = "blCartStateRequestProcessorExtensionManager")
79+
protected CartStateRequestProcessorExtensionManager extensionManager;
80+
7781
@Resource(name = "blOrderService")
7882
protected OrderService orderService;
7983

@@ -106,21 +110,29 @@ public void process(WebRequest request) {
106110
return;
107111
}
108112

109-
Order cart = getOverrideCart(request);
113+
ExtensionResultHolder<Order> erh = new ExtensionResultHolder<Order>();
114+
extensionManager.getProxy().lookupOrCreateCart(request, customer, erh);
110115

111-
if (cart == null && mergeCartNeeded(customer, request)) {
112-
if (LOG.isDebugEnabled()) {
113-
LOG.debug("Merge cart required, calling mergeCart " + customer.getId());
116+
Order cart;
117+
if (erh.getResult() != null) {
118+
cart = erh.getResult();
119+
} else {
120+
cart = getOverrideCart(request);
121+
122+
if (cart == null && mergeCartNeeded(customer, request)) {
123+
if (LOG.isDebugEnabled()) {
124+
LOG.debug("Merge cart required, calling mergeCart " + customer.getId());
125+
}
126+
cart = mergeCart(customer, request);
127+
} else if (cart == null) {
128+
cart = orderService.findCartForCustomer(customer);
114129
}
115-
cart = mergeCart(customer, request);
116-
} else if (cart == null) {
117-
cart = orderService.findCartForCustomer(customer);
118-
}
119130

120-
if (cart == null) {
121-
cart = orderService.getNullOrder();
122-
} else {
123-
updateCartService.updateAndValidateCart(cart);
131+
if (cart == null) {
132+
cart = orderService.getNullOrder();
133+
} else {
134+
updateCartService.updateAndValidateCart(cart);
135+
}
124136
}
125137

126138
request.setAttribute(cartRequestAttributeName, cart, WebRequest.SCOPE_REQUEST);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* #%L
3+
* BroadleafCommerce Framework Web
4+
* %%
5+
* Copyright (C) 2009 - 2013 Broadleaf Commerce
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package org.broadleafcommerce.core.web.order.security;
22+
23+
import org.broadleafcommerce.common.extension.ExtensionHandler;
24+
import org.broadleafcommerce.common.extension.ExtensionResultHolder;
25+
import org.broadleafcommerce.common.extension.ExtensionResultStatusType;
26+
import org.broadleafcommerce.core.order.domain.Order;
27+
import org.broadleafcommerce.profile.core.domain.Customer;
28+
import org.springframework.web.context.request.WebRequest;
29+
30+
31+
/**
32+
* @author bpolster
33+
*/
34+
public interface CartStateRequestProcessorExtensionHandler extends ExtensionHandler {
35+
36+
/**
37+
* Throws an exception if cart is invalid.
38+
*
39+
* @param cart
40+
* @param customer (the current customer)
41+
* @param resultHolder
42+
* @return
43+
*/
44+
public ExtensionResultStatusType lookupOrCreateCart(WebRequest request, Customer customer, ExtensionResultHolder<Order> resultHolder);
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* #%L
3+
* BroadleafCommerce Framework Web
4+
* %%
5+
* Copyright (C) 2009 - 2013 Broadleaf Commerce
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package org.broadleafcommerce.core.web.order.security;
21+
22+
import org.broadleafcommerce.common.extension.ExtensionManager;
23+
import org.springframework.stereotype.Service;
24+
25+
26+
/**
27+
* @author bpolster
28+
*/
29+
@Service("blCartStateRequestProcessorExtensionManager")
30+
public class CartStateRequestProcessorExtensionManager extends ExtensionManager<CartStateRequestProcessorExtensionHandler> {
31+
32+
public CartStateRequestProcessorExtensionManager() {
33+
super(CartStateRequestProcessorExtensionHandler.class);
34+
}
35+
}

core/broadleaf-profile-web/src/main/java/org/broadleafcommerce/profile/web/core/security/CustomerStateRequestProcessor.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public void process(WebRequest request) {
126126
CustomerLoggedInEvent loggedInEvent = new CustomerLoggedInEvent(customer, this.getClass().getName());
127127
publishEvent(loggedInEvent, request, CustomerLoggedInEvent.class.getName(), userName);
128128
}
129-
} else {
130-
customer = resolveAuthenticatedCustomer(authentication);
131-
}
129+
}
130+
} else {
131+
customer = resolveAuthenticatedCustomer(authentication);
132132
}
133133
}
134134
}

0 commit comments

Comments
 (0)