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()));
}
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';
}
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();
}
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);
}
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();
}
Aggregations