Search in sources :

Example 51 with Customer

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);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 52 with Customer

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;
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 53 with Customer

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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 54 with Customer

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);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 55 with Customer

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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)98 Order (org.broadleafcommerce.core.order.domain.Order)41 Transactional (org.springframework.transaction.annotation.Transactional)34 Test (org.testng.annotations.Test)33 Address (org.broadleafcommerce.profile.core.domain.Address)14 Rollback (org.springframework.test.annotation.Rollback)11 HashMap (java.util.HashMap)9 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)9 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)6 ArrayList (java.util.ArrayList)5 Money (org.broadleafcommerce.common.money.Money)5 Category (org.broadleafcommerce.core.catalog.domain.Category)5 Product (org.broadleafcommerce.core.catalog.domain.Product)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)5 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)3