Search in sources :

Example 1 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutTest method testCheckout.

@Test(groups = { "checkout" }, dependsOnGroups = { "createCartForCustomer", "testShippingInsert" }, dataProvider = "USCurrency", dataProviderClass = BroadleafCurrencyProvider.class)
@Transactional
public void testCheckout(BroadleafCurrency usCurrency) throws Exception {
    HashMap currencyConsiderationContext = new HashMap();
    currencyConsiderationContext.put("aa", "bb");
    CurrencyConversionContext.setCurrencyConversionContext(currencyConsiderationContext);
    CurrencyConversionContext.setCurrencyConversionService(new CurrencyConversionService() {

        @Override
        public Money convertCurrency(Money source, Currency destinationCurrency, int destinationScale) {
            return source;
        }
    });
    String userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    Order order = orderService.createNewCartForCustomer(customer);
    usCurrency = currencyService.save(usCurrency);
    order.setCurrency(usCurrency);
    Address address = buildAddress();
    FulfillmentGroup group = buildFulfillmentGroup(order, address);
    addSampleItemToOrder(order, group);
    order.setTotalShipping(new Money(0D));
    addPaymentToOrder(order, address);
    // execute pricing for this order
    orderService.save(order, true);
    CheckoutResponse response = checkoutService.performCheckout(order);
    assert (order.getTotal().greaterThan(order.getSubTotal()));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Address(org.broadleafcommerce.profile.core.domain.Address) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer) Currency(java.util.Currency) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) CurrencyConversionService(org.broadleafcommerce.common.money.CurrencyConversionService) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class OfferTest method testOfferDelete.

@Test(groups = { "testOfferDelete" }, dependsOnGroups = { "testFulfillmentGroupOffers" })
@Transactional
public void testOfferDelete() throws Exception {
    CustomerOffer customerOffer = customerOfferDao.create();
    Customer customer = createCustomer();
    Long customerId = customer.getId();
    customerOffer.setCustomer(customerService.saveCustomer(customer));
    Offer offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    offer = offerService.save(offer);
    Long offerId = offer.getId();
    offerDao.delete(offer);
    Offer deletedOffer = offerDao.readOfferById(offerId);
    assert ((OfferImpl) deletedOffer).getArchived() == 'Y';
    offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    offer = offerService.save(offer);
    customerOffer.setOffer(offer);
    customerOffer = customerOfferDao.save(customerOffer);
    Long customerOfferId = customerOffer.getId();
    customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId);
    assert (customerOffer != null);
    Customer customer2 = createCustomer();
    customerOffer.setCustomer(customerService.saveCustomer(customer2));
    customerOffer = customerOfferDao.save(customerOffer);
    assert !customerOffer.getCustomer().getId().equals(customerId);
    customerOfferDao.delete(customerOffer);
    customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId);
    assert customerOffer == null || ((OfferImpl) customerOffer).getArchived() == 'Y';
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) CustomerOfferImpl(org.broadleafcommerce.core.offer.domain.CustomerOfferImpl) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerDaoImpl method readCustomersByIds.

@Override
public List<Customer> readCustomersByIds(List<Long> ids) {
    if (ids == null || ids.size() == 0) {
        return null;
    }
    if (ids.size() > 100) {
        LOG.warn("Not recommended to use the readCustomersByIds method for long lists of customerIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "customer ids was (" + ids.size() + ") in length.");
    }
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
    Root<CustomerImpl> customer = criteria.from(CustomerImpl.class);
    criteria.select(customer);
    // We only want results that match the customer IDs
    criteria.where(customer.get("id").as(Long.class).in(ids));
    TypedQuery<Customer> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl)

Example 4 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerDaoImpl method readCustomerByExternalId.

@Override
public Customer readCustomerByExternalId(String id) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
    Root<? extends Customer> customer = criteria.from(entityConfiguration.lookupEntityClass(Customer.class.getName(), Customer.class));
    criteria.select(customer);
    criteria.where(builder.equal(customer.get("externalId"), id));
    TypedQuery<Customer> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, false);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Customer");
    List<Customer> resultList = query.getResultList();
    return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 5 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerDaoImpl method readBatchCustomers.

@Override
public List<Customer> readBatchCustomers(int start, int pageSize) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
    Root<CustomerImpl> customer = criteria.from(CustomerImpl.class);
    criteria.select(customer);
    TypedQuery<Customer> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(pageSize);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Customer");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl)

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