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