use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class CreateOfferUtility method createOfferCode.
public OfferCode createOfferCode(String offerCodeName, String offerName, OfferType offerType, OfferDiscountType discountType, double value, String orderRule, boolean stackable, boolean combinable, int priority, String qualifierRule) {
OfferCode offerCode = offerCodeDao.create();
Offer offer = createOffer(offerName, offerType, discountType, value, orderRule, stackable, combinable, priority, qualifierRule);
offerCode.setOffer(offer);
offerCode.setOfferCode(offerCodeName);
offerCode = offerService.saveOfferCode(offerCode);
return offerCode;
}
use of org.broadleafcommerce.core.offer.domain.OfferCode 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.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testOfferCodeDao.
@Test(groups = { "testOfferCodeDao" }, dependsOnGroups = { "testReadAllOffers" })
@Transactional
public void testOfferCodeDao() throws Exception {
String offerCodeString = "AJ's Code";
OfferCode offerCode = createOfferUtility.createOfferCode("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10);
offerCode.setOfferCode(offerCodeString);
offerCode = offerService.saveOfferCode(offerCode);
Long offerCodeId = offerCode.getId();
assert offerCode.getOfferCode().equals(offerCodeString);
Offer offer = offerCode.getOffer();
Offer storedOffer = offerService.lookupOfferByCode(offerCodeString);
assert offer.getId().equals(storedOffer.getId());
OfferCode newOfferCode = offerCodeDao.readOfferCodeById(offerCodeId);
assert newOfferCode.getOfferCode().equals(offerCode.getOfferCode());
newOfferCode = offerCodeDao.readOfferCodeByCode(offerCodeString);
assert newOfferCode.getOfferCode().equals(offerCode.getOfferCode());
offerCodeId = newOfferCode.getId();
offerCodeDao.delete(newOfferCode);
OfferCode deletedOfferCode = offerCodeDao.readOfferCodeById(offerCodeId);
assert deletedOfferCode == null;
}
use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class PricingTest method createOfferCode.
private OfferCode createOfferCode(String offerName, OfferType offerType, OfferDiscountType discountType, double value, String customerRule, String orderRule) {
OfferCode offerCode = new OfferCodeImpl();
Offer offer = createOffer(offerName, offerType, discountType, value, customerRule, orderRule);
offerCode.setOffer(offer);
offerCode.setOfferCode("OPRAH");
offerCode = offerService.saveOfferCode(offerCode);
return offerCode;
}
use of org.broadleafcommerce.core.offer.domain.OfferCode 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;
}
Aggregations