use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class DefaultPaymentGatewayCheckoutService method initiateCheckout.
@Override
public String initiateCheckout(Long orderId) throws Exception {
Order order = orderService.findOrderById(orderId, true);
if (order == null || order instanceof NullOrderImpl) {
throw new IllegalArgumentException("Could not order with id " + orderId);
}
CheckoutResponse response;
try {
response = checkoutService.performCheckout(order);
} catch (CheckoutException e) {
throw new Exception(e);
}
if (response.getOrder().getOrderNumber() == null) {
LOG.error("Order Number for Order ID: " + order.getId() + " is null.");
}
return response.getOrder().getOrderNumber();
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafRegisterController method processRegister.
public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException {
if (useEmailForLogin) {
Customer customer = registerCustomerForm.getCustomer();
customer.setUsername(customer.getEmailAddress());
}
registerCustomerValidator.validate(registerCustomerForm, errors, useEmailForLogin);
if (!errors.hasErrors()) {
Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
assert (newCustomer != null);
// The next line needs to use the customer from the input form and not the customer returned after registration
// so that we still have the unencoded password for use by the authentication mechanism.
loginService.loginCustomer(registerCustomerForm.getCustomer());
// Need to ensure that the Cart on CartState is owned by the newly registered customer.
Order cart = CartState.getCart();
if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) {
cart.setEmailAddress(newCustomer.getEmailAddress());
orderService.save(cart, false);
}
String redirectUrl = registerCustomerForm.getRedirectUrl();
if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
redirectUrl = null;
}
return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
} else {
return getRegisterView();
}
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method addPromo.
/**
* Attempts to add provided Offer to Cart
*
* @param request
* @param response
* @param model
* @param customerOffer
* @return the return view
* @throws IOException
* @throws PricingException
* @throws OfferMaxUseExceededException
*/
public String addPromo(HttpServletRequest request, HttpServletResponse response, Model model, String customerOffer) throws IOException, PricingException {
Order cart = CartState.getCart();
Boolean promoAdded = false;
String exception = "";
if (cart != null && !(cart instanceof NullOrderImpl)) {
List<OfferCode> offerCodes = offerService.lookupAllOfferCodesByCode(customerOffer);
if (CollectionUtils.isNotEmpty(offerCodes)) {
for (OfferCode offerCode : offerCodes) {
if (offerCode != null) {
try {
orderService.addOfferCode(cart, offerCode, false);
promoAdded = true;
} catch (OfferException e) {
if (e instanceof OfferMaxUseExceededException) {
exception = "Use Limit Exceeded";
} else if (e instanceof OfferExpiredException) {
exception = "Offer Has Expired";
} else if (e instanceof OfferAlreadyAddedException) {
exception = "Offer Has Already Been Added";
} else {
exception = "An Unknown Offer Error Has Occurred";
}
}
} else {
exception = "Invalid Code";
}
}
cart = orderService.save(cart, true);
} else {
exception = "Unknown Code";
}
} else {
exception = "Invalid Cart";
}
if (isAjaxRequest(request)) {
Map<String, Object> extraData = new HashMap<>();
extraData.put("promoAdded", promoAdded);
extraData.put("exception", exception);
model.addAttribute("blcextradata", new ObjectMapper().writeValueAsString(extraData));
} else {
model.addAttribute("exception", exception);
}
return isCheckoutContext(request) ? getCheckoutView() : getCartView();
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class OnePageCheckoutProcessor method populateFulfillmentOptionsAndEstimationOnModel.
/**
* A helper method to retrieve all fulfillment options for the cart and estimate the cost of applying
* fulfillment options on the first shippable fulfillment group.
*/
protected void populateFulfillmentOptionsAndEstimationOnModel(Map<String, Object> localVars) {
List<FulfillmentOption> fulfillmentOptions = fulfillmentOptionService.readAllFulfillmentOptions();
Order cart = CartState.getCart();
if (!(cart instanceof NullOrderImpl) && cart.getFulfillmentGroups().size() > 0 && hasPopulatedShippingAddress(cart)) {
Set<FulfillmentOption> options = new HashSet<>();
options.addAll(fulfillmentOptions);
FulfillmentEstimationResponse estimateResponse = null;
try {
estimateResponse = fulfillmentPricingService.estimateCostForFulfillmentGroup(fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart), options);
} catch (FulfillmentPriceException e) {
}
localVars.put("estimateResponse", estimateResponse);
}
localVars.put("fulfillmentOptions", fulfillmentOptions);
}
use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafSocialRegisterController method processRegister.
// Calls ProviderSignInUtils.handlePostSignUp() after a successful registration
public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException {
if (isUseEmailForLogin()) {
Customer customer = registerCustomerForm.getCustomer();
customer.setUsername(customer.getEmailAddress());
}
registerCustomerValidator.validate(registerCustomerForm, errors, isUseEmailForLogin());
if (!errors.hasErrors()) {
Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
assert (newCustomer != null);
ProviderSignInUtils.handlePostSignUp(newCustomer.getUsername(), new ServletWebRequest(request));
// The next line needs to use the customer from the input form and not the customer returned after registration
// so that we still have the unencoded password for use by the authentication mechanism.
loginService.loginCustomer(registerCustomerForm.getCustomer());
// Need to ensure that the Cart on CartState is owned by the newly registered customer.
Order cart = CartState.getCart();
if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) {
cart.setEmailAddress(newCustomer.getEmailAddress());
orderService.save(cart, false);
}
String redirectUrl = registerCustomerForm.getRedirectUrl();
if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
redirectUrl = null;
}
return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
} else {
return getRegisterView();
}
}
Aggregations