use of org.broadleafcommerce.core.offer.domain.OfferInfo in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method mergeOfferCodes.
protected Order mergeOfferCodes(Order anonymousCart, Order customerCart) {
// add all offers from anonymous order
Map<String, OfferCode> customerOffersMap = new HashMap<String, OfferCode>();
for (OfferCode customerOffer : customerCart.getAddedOfferCodes()) {
customerOffersMap.put(customerOffer.getOfferCode(), customerOffer);
}
for (OfferCode anonymousOffer : anonymousCart.getAddedOfferCodes()) {
if (!customerOffersMap.containsKey(anonymousOffer.getOfferCode())) {
OfferCode transferredCode = offerService.lookupOfferCodeByCode(anonymousOffer.getOfferCode());
OfferInfo info = anonymousCart.getAdditionalOfferInformation().get(anonymousOffer.getOffer());
OfferInfo offerInfo = offerDao.createOfferInfo();
for (String key : info.getFieldValues().keySet()) {
offerInfo.getFieldValues().put(key, info.getFieldValues().get(key));
}
customerCart.getAdditionalOfferInformation().put(transferredCode.getOffer(), offerInfo);
customerCart.addOfferCode(transferredCode);
}
}
return customerCart;
}
use of org.broadleafcommerce.core.offer.domain.OfferInfo in project BroadleafCommerce by BroadleafCommerce.
the class OrderImpl method createOrRetrieveCopyInstance.
@Override
public <G extends Order> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException {
CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this);
if (createResponse.isAlreadyPopulated()) {
return createResponse;
}
Order cloned = createResponse.getClone();
cloned.setCurrency(getCurrency());
cloned.setEmailAddress(emailAddress);
cloned.setLocale(getLocale());
cloned.setName(name);
cloned.setOrderNumber(orderNumber);
cloned.setTotalTax(getTotalTax());
cloned.setSubmitDate(submitDate);
cloned.setCustomer(customer);
cloned.setStatus(getStatus());
cloned.setTotalFulfillmentCharges(getTotalFulfillmentCharges());
cloned.setSubTotal(getSubTotal());
cloned.setTaxOverride(taxOverride == null ? null : taxOverride);
for (OrderItem entry : orderItems) {
OrderItem clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
clonedEntry.setOrder(cloned);
cloned.getOrderItems().add(clonedEntry);
}
for (Map.Entry<Offer, OfferInfo> entry : additionalOfferInformation.entrySet()) {
Offer clonedOffer = entry.getKey().createOrRetrieveCopyInstance(context).getClone();
OfferInfo clonedEntry = entry.getValue().createOrRetrieveCopyInstance(context).getClone();
cloned.getAdditionalOfferInformation().put(clonedOffer, clonedEntry);
}
for (Map.Entry<String, OrderAttribute> entry : orderAttributes.entrySet()) {
OrderAttribute clonedAttribute = entry.getValue().createOrRetrieveCopyInstance(context).getClone();
clonedAttribute.setOrder(cloned);
cloned.getOrderAttributes().put(entry.getKey(), clonedAttribute);
}
for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
FulfillmentGroup fg = fulfillmentGroup.createOrRetrieveCopyInstance(context).getClone();
fg.setOrder(cloned);
cloned.getFulfillmentGroups().add(fg);
}
for (OrderPayment orderPayment : payments) {
if (orderPayment.isActive()) {
OrderPayment payment = orderPayment.createOrRetrieveCopyInstance(context).getClone();
payment.setOrder(cloned);
cloned.getPayments().add(payment);
}
}
for (OfferCode entry : addedOfferCodes) {
// We do not want to clone the offer code since that will cascade through offer. We only want to create
// the new relationship between this cloned order and the existing offer code.
cloned.getAddedOfferCodes().add(entry);
}
cloned.setTotal(total == null ? null : new Money(total));
return createResponse;
}
use of org.broadleafcommerce.core.offer.domain.OfferInfo in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testOfferLowerSalePriceWithNotCombinableOfferAndInformation.
@Test(groups = { "testOfferLowerSalePriceWithNotCombinableOfferAndInformation" }, dependsOnGroups = { "testOfferLowerSalePriceWithNotCombinableOffer" })
@Transactional
public void testOfferLowerSalePriceWithNotCombinableOfferAndInformation() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
order.addOrderItem(createDiscreteOrderItem(sku1, 100D, 50D, true, 2, order));
order.addOrderItem(createDiscreteOrderItem(sku2, 100D, null, true, 2, order));
OfferCode offerCode1 = createOfferUtility.createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, null, true, true, 1);
OfferCode offerCode2 = createOfferUtility.createOfferCode("30 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 30, null, true, false, 1);
order.addOfferCode(offerCode1);
order.addOfferCode(offerCode2);
OfferInfo info1 = offerDao.createOfferInfo();
info1.getFieldValues().put("key1", "value1");
order.getAdditionalOfferInformation().put(offerCode1.getOffer(), info1);
OfferInfo info2 = offerDao.createOfferInfo();
info2.getFieldValues().put("key2", "value2");
order.getAdditionalOfferInformation().put(offerCode2.getOffer(), info2);
order = orderService.save(order, true);
assert (order.getSubTotal().equals(new Money(180D)));
order = orderService.findOrderById(order.getId());
assert (order.getAdditionalOfferInformation().get(offerCode1.getOffer()).equals(info1));
}
Aggregations