Search in sources :

Example 1 with OfferAudit

use of org.broadleafcommerce.core.offer.domain.OfferAudit in project BroadleafCommerce by BroadleafCommerce.

the class RecordOfferUsageActivity method saveOfferIds.

/**
 * Persists each of the offers to the database as {@link OfferAudit}s.
 *
 * @return the {@link OfferAudit}s that were persisted
 */
protected List<OfferAudit> saveOfferIds(Set<Offer> offers, Map<Offer, OfferCode> offerToCodeMapping, Order order) {
    List<OfferAudit> audits = new ArrayList<>(offers.size());
    for (Offer offer : offers) {
        OfferAudit audit = offerAuditService.create();
        audit.setCustomerId(order.getCustomer().getId());
        audit.setOfferId(offer.getId());
        audit.setOrderId(order.getId());
        // add the code that was used to obtain the offer to the audit context
        OfferCode codeUsedToRetrieveOffer = offerToCodeMapping.get(offer);
        if (codeUsedToRetrieveOffer != null) {
            audit.setOfferCodeId(codeUsedToRetrieveOffer.getId());
        }
        audit.setRedeemedDate(SystemTime.asDate());
        audit = offerAuditService.save(audit);
        audits.add(audit);
    }
    return audits;
}
Also used : OfferAudit(org.broadleafcommerce.core.offer.domain.OfferAudit) Offer(org.broadleafcommerce.core.offer.domain.Offer) ArrayList(java.util.ArrayList) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 2 with OfferAudit

use of org.broadleafcommerce.core.offer.domain.OfferAudit in project BroadleafCommerce by BroadleafCommerce.

the class RecordOfferUsageActivity method execute.

@Override
public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context) throws Exception {
    Order order = context.getSeedData().getOrder();
    Set<Offer> appliedOffers = offerService.getUniqueOffersFromOrder(order);
    Map<Offer, OfferCode> offerToCodeMapping = offerService.getOffersRetrievedFromCodes(order.getAddedOfferCodes(), appliedOffers);
    List<OfferAudit> audits = saveOfferIds(appliedOffers, offerToCodeMapping, order);
    Map<String, Object> state = new HashMap<>();
    state.put(SAVED_AUDITS, audits);
    ActivityStateManagerImpl.getStateManager().registerState(this, context, getRollbackHandler(), state);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OfferAudit(org.broadleafcommerce.core.offer.domain.OfferAudit) Offer(org.broadleafcommerce.core.offer.domain.Offer) HashMap(java.util.HashMap) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 3 with OfferAudit

use of org.broadleafcommerce.core.offer.domain.OfferAudit in project BroadleafCommerce by BroadleafCommerce.

the class OfferAuditDaoImpl method delete.

@Override
public void delete(final OfferAudit offerAudit) {
    OfferAudit loa = offerAudit;
    if (!em.contains(loa)) {
        loa = readAuditById(offerAudit.getId());
    }
    em.remove(loa);
}
Also used : OfferAudit(org.broadleafcommerce.core.offer.domain.OfferAudit)

Aggregations

OfferAudit (org.broadleafcommerce.core.offer.domain.OfferAudit)3 Offer (org.broadleafcommerce.core.offer.domain.Offer)2 OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Order (org.broadleafcommerce.core.order.domain.Order)1