public Offer createOffer(
     String offerName,
     OfferType offerType,
     OfferDiscountType discountType,
     double value,
     String customerRule,
     String orderRule,
     boolean stackable,
     boolean combinable,
     int priority) {
   Offer offer = offerDao.create();
   offer.setName(offerName);
   offer.setStartDate(SystemTime.asDate());
   Calendar calendar = Calendar.getInstance();
   calendar.add(Calendar.DATE, -1);
   offer.setStartDate(calendar.getTime());
   calendar.add(Calendar.DATE, 2);
   offer.setEndDate(calendar.getTime());
   offer.setType(offerType);
   offer.setDiscountType(discountType);
   offer.setValue(BigDecimal.valueOf(value));
   offer.setDeliveryType(OfferDeliveryType.CODE);
   offer.setStackable(stackable);
   offer.setAppliesToOrderRules(orderRule);
   offer.setAppliesToCustomerRules(customerRule);
   offer.setCombinableWithOtherOffers(combinable);
   offer.setPriority(priority);
   offer = offerService.save(offer);
   offer.setMaxUses(50);
   return offer;
 }
  private SandBox determineSandbox(HttpServletRequest request, Site site) {
    SandBox currentSandbox = null;
    if (!sandBoxPreviewEnabled) {
      if (LOG.isTraceEnabled()) {
        LOG.trace("Sandbox preview disabled. Setting sandbox to production");
      }
      request.setAttribute(SANDBOX_VAR, currentSandbox);
    } else {
      Long sandboxId = null;
      if (request.getParameter("blSandboxDateTimeRibbonProduction") == null) {
        sandboxId = lookupSandboxId(request);
      } else {
        request.getSession().removeAttribute(SANDBOX_DATE_TIME_VAR);
        request.getSession().removeAttribute(SANDBOX_ID_VAR);
      }
      if (sandboxId != null) {
        currentSandbox = sandBoxService.retrieveSandboxById(sandboxId);
        request.setAttribute(SANDBOX_VAR, currentSandbox);
        if (currentSandbox != null
            && !SandBoxType.PRODUCTION.equals(currentSandbox.getSandBoxType())) {
          setContentTime(request);
        }
      }

      if (currentSandbox == null && site != null) {
        currentSandbox = site.getProductionSandbox();
      }
    }

    if (LOG.isTraceEnabled()) {
      LOG.trace("Serving request using sandbox: " + currentSandbox);
    }

    Date currentSystemDateTime = SystemTime.asDate(true);
    Calendar sandboxDateTimeCalendar = Calendar.getInstance();
    sandboxDateTimeCalendar.setTime(currentSystemDateTime);
    request.setAttribute(
        SANDBOX_DISPLAY_DATE_TIME_DATE_PARAM,
        CONTENT_DATE_DISPLAY_FORMATTER.format(currentSystemDateTime));
    request.setAttribute(
        SANDBOX_DISPLAY_DATE_TIME_HOURS_PARAM,
        CONTENT_DATE_DISPLAY_HOURS_FORMATTER.format(currentSystemDateTime));
    request.setAttribute(
        SANDBOX_DISPLAY_DATE_TIME_MINUTES_PARAM,
        CONTENT_DATE_DISPLAY_MINUTES_FORMATTER.format(currentSystemDateTime));
    request.setAttribute(
        SANDBOX_DISPLAY_DATE_TIME_AMPM_PARAM, sandboxDateTimeCalendar.get(Calendar.AM_PM));
    return currentSandbox;
  }