use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CartStateRequestProcessor method process.
@Override
public void process(WebRequest request) {
Customer customer = CustomerState.getCustomer();
if (customer == null) {
LOG.info("No customer was found on the current request, no cart will be added to the current request. Ensure that the" + " blCustomerStateFilter occurs prior to the blCartStateFilter");
return;
}
ExtensionResultHolder<Order> erh = new ExtensionResultHolder<Order>();
extensionManager.getProxy().lookupOrCreateCart(request, customer, erh);
Order cart;
if (erh.getResult() != null) {
cart = orderService.findCartForCustomerWithEnhancements(customer, erh.getResult());
} else {
cart = getOverrideCart(request);
if (cart == null && mergeCartNeeded(customer, request)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Merge cart required, calling mergeCart " + customer.getId());
}
cart = mergeCart(customer, request);
} else if (cart == null) {
cart = orderService.findCartForCustomerWithEnhancements(customer);
}
if (cart == null) {
cart = orderService.getNullOrder();
} else {
updateCartService.updateAndValidateCart(cart);
}
}
updateCartRequestAttributes(request, cart);
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class RatingsProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
String itemId = String.valueOf(context.parseExpression(tagAttributes.get("itemId")));
RatingSummary ratingSummary = ratingService.readRatingSummary(itemId, RatingType.PRODUCT);
Map<String, Object> newModelVars = new HashMap<>();
if (ratingSummary != null) {
newModelVars.put(getRatingsVar(tagAttributes), ratingSummary);
}
Customer customer = CustomerState.getCustomer();
ReviewDetail reviewDetail = null;
if (!customer.isAnonymous()) {
reviewDetail = ratingService.readReviewByCustomerAndItem(customer, itemId);
}
if (reviewDetail != null) {
newModelVars.put("currentCustomerReview", reviewDetail);
}
return newModelVars;
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance();
adminInstance.setId(customerService.findNextCustomerId());
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective);
adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
if (useEmailForLogin) {
adminInstance.setUsername(adminInstance.getEmailAddress());
}
if (!entity.isPreAdd()) {
Entity errorEntity = validateUniqueUsername(entity, adminInstance);
if (errorEntity != null) {
return errorEntity;
}
}
adminInstance = dynamicEntityDao.merge(adminInstance);
customerService.createRegisteredCustomerRoles(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
LOG.error("Unable to execute persistence activity", e);
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
Long customerId = Long.parseLong(entity.findProperty("id").getValue());
Customer customer = customerService.readCustomerById(customerId);
if (Status.class.isAssignableFrom(customer.getClass())) {
((Status) customer).setArchived('Y');
// If the customer has a conditional weave on ArchiveStatus, nothing triggers the delete so other
// normally-cascaded deletes don't happen (like CustomerAddress)
List<CustomerAddress> addressList = customer.getCustomerAddresses();
for (CustomerAddress address : addressList) {
address.setArchived('Y');
}
customer = customerService.saveCustomer(customer);
return;
}
// Remove the customer roles for the customer since it's not cascaded
roleDao.removeCustomerRolesByCustomerId(customerId);
helper.getCompatibleModule(OperationType.BASIC).remove(persistencePackage);
} catch (Exception e) {
LOG.error("Unable to execute persistence activity", e);
throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
String passwordBefore = adminInstance.getPassword();
adminInstance.setPassword(null);
adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance.setPassword(passwordBefore);
if (useEmailForLogin) {
adminInstance.setUsername(adminInstance.getEmailAddress());
}
adminInstance = customerService.saveCustomer(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
Aggregations