Search in sources :

Example 1 with OfferInfo

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;
}
Also used : HashMap(java.util.HashMap) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) OfferInfo(org.broadleafcommerce.core.offer.domain.OfferInfo)

Example 2 with OfferInfo

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;
}
Also used : OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) CandidateOrderOffer(org.broadleafcommerce.core.offer.domain.CandidateOrderOffer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) Map(java.util.Map) HashMap(java.util.HashMap) AdminPresentationMap(org.broadleafcommerce.common.presentation.AdminPresentationMap) OfferInfo(org.broadleafcommerce.core.offer.domain.OfferInfo) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)

Example 3 with OfferInfo

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));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) OfferInfo(org.broadleafcommerce.core.offer.domain.OfferInfo) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)3 OfferInfo (org.broadleafcommerce.core.offer.domain.OfferInfo)3 HashMap (java.util.HashMap)2 Money (org.broadleafcommerce.common.money.Money)2 Map (java.util.Map)1 AdminPresentationMap (org.broadleafcommerce.common.presentation.AdminPresentationMap)1 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)1 CandidateOrderOffer (org.broadleafcommerce.core.offer.domain.CandidateOrderOffer)1 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 Order (org.broadleafcommerce.core.order.domain.Order)1 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)1 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Test (org.testng.annotations.Test)1