So what's probably happening here is that within Liferay, the correct events are not being invoked. Specifically, the MergeCartProcessor is probably not being called on successful login. In a normal Spring web application, this gets invoked when a user is logged in.
To provide the correct functionality in Liferay, you will need to throw in a hook point to execute right when a user is changed from anonymous to authenticated. I'm not sure off the top of my head of how to do this with Liferay, especially since you will need to do this within the context of the Broadleaf portlet application so that you can inject the blMergeCartService and invoke it from there.
An example of how we do this in core Broadleaf is the BroadleafRegisterController. Here's the block of code that does it:
Code: Select all
@Resource(name="blMergeCartProcessor")
protected MergeCartProcessor mergeCartProcessor;
...
registerCustomerValidator.validate(registerCustomerForm, errors, useEmailForLogin);
if (!errors.hasErrors()) {
Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(),
registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
assert(newCustomer != null);
Authentication auth = loginService.loginCustomer(registerCustomerForm.getCustomer());
mergeCartProcessor.execute(request, response, auth);
String redirectUrl = registerCustomerForm.getRedirectUrl();
if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
redirectUrl = null;
}
return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
} else {
return getRegisterView();
}
In 2.2 versions of Broadleaf and above, 'mergeCart' is a bit of a misnomer as it doesn't actually merge anything. It just takes the cart that was previously saved in the database for the Customer and sets that to a named cart (a wish list) and then sets whatever cart they have as a guest to the current cart. No merge of cart items actually takes place.