Ejemplo n.º 1
0
 @DefaultHandler
 public Resolution pre() {
   pricingDto = new PricingDto(order.getCartLineItems(), order.getAddress());
   coupon = referrerProgramManager.getOrCreateRefferrerCoupon(order.getUser());
   barcodePath = barcodeGenerator.getBarcodePath(order.getGatewayOrderId(), 1.0f, 150, false);
   return new ForwardResolution("/pages/invoice.jsp");
 }
Ejemplo n.º 2
0
 public Set<Offer> getApplicableOffers(Order order) {
   applicableOffers = new HashSet<Offer>();
   User user = order.getUser();
   List<Offer> activeOffers = offerDao.listAllValidShowPromptly();
   if (activeOffers != null) {
     for (Offer activeOffer : activeOffers) {
       if (activeOffer.getOfferTrigger() != null) {
         logger.debug("Active Offer ID -> " + activeOffer.getId());
         OfferTriggerMatcher offerTriggerMatcher =
             new OfferTriggerMatcher(activeOffer.getOfferTrigger(), order.getCartLineItems());
         if (offerTriggerMatcher.hasEasyMatch(false)
             && offerManager.isOfferValidForUser(activeOffer, user)
             && activeOffer.isShowPromptly()) {
           if (activeOffer.getOfferAction().getFreeVariant() != null) {
             ProductVariant freeVariant = activeOffer.getOfferAction().getFreeVariant();
             if (!freeVariant.isDeleted() && !freeVariant.isOutOfStock()) {
               applicableOffers.add(activeOffer);
             }
           } else {
             applicableOffers.add(activeOffer);
           }
         }
       }
     }
   }
   List<OfferInstance> offerInstances = offerInstanceDao.getActiveOffers(user);
   for (OfferInstance instance : offerInstances) {
     if (offerManager.isOfferValidForUser(instance.getOffer(), user)) {
       applicableOffers.add(instance.getOffer());
     }
   }
   return applicableOffers;
 }
 @Override
 @Transactional
 public void onMessage(javax.jms.Message message) {
   if (message instanceof TextMessage) {
     try {
       String orderSplitterMessageString = ((TextMessage) message).getText();
       OrderSplitterMessage orderResponse =
           new Gson().fromJson(orderSplitterMessageString, OrderSplitterMessage.class);
       Long orderId = Long.valueOf(orderResponse.getOrderId());
       Order order = orderService.find(orderId);
       if (order != null) {
         logger.info(
             "order id " + order.getId() + "order status is " + order.getOrderStatus().getId());
         orderService.splitBOCreateShipmentEscalateSOAndRelatedTasks(order);
       }
     } catch (JMSException ex) {
       throw new RuntimeException(ex);
     }
   } else {
     throw new IllegalArgumentException("Message must be of type TextMessage");
   }
 }
Ejemplo n.º 4
0
 @GET
 @Path("/otherApplicableOffers")
 @Produces("application/json")
 public String otherApplicableOffers() {
   Offer appliedOffer = null;
   if (getPrincipal() != null) {
     User user = getUserService().getUserById(getPrincipal().getId());
     if (user != null) {
       order = getOrderService().findCart(user, EnumStore.HEALTHKART.asStore());
       if (order != null) {
         if (order.getOfferInstance() != null) {
           appliedOffer = order.getOfferInstance().getOffer();
         }
         applicableOffers = this.getApplicableOffers(order);
       }
     }
   }
   return new JSONResponseBuilder()
       .addField("applicableOffers", applicableOffers)
       .addField("appliedOffer", appliedOffer)
       .build();
 }
  @SuppressWarnings("unchecked")
  @JsonHandler
  @DefaultHandler
  public Resolution buyNow() {
    getConfigValuesFromJson(jsonConfigValues);

    ProductVariant productVariant = getProductVariantService().getVariantById(variantId);
    User user = null;
    ProductReferrer productReferrer = null;

    if (getPrincipal() != null) {
      user = getUserService().getUserById(getPrincipal().getId());
      // user = UserCache.getInstance().getUserById(getPrincipal().getId()).getUser();
      if (user == null) {
        user = userManager.createAndLoginAsGuestUser(null, null);
      }
    } else {
      user = userManager.createAndLoginAsGuestUser(null, null);
    }
    Order order = orderManager.getOrCreateOrder(user);

    CartLineItemConfig lineItemConfig = new CartLineItemConfig();
    boolean isLineItemCreated = false;
    try {
      for (LineItemConfigValuesDTO dto : configValues) {
        CartLineItemConfigValues configValue = new CartLineItemConfigValues();
        configValue.setLineItemConfig(lineItemConfig);
        VariantConfigOption configOption =
            getBaseDao().get(VariantConfigOption.class, dto.getOptionId());
        VariantConfigValues selectedConfigValue =
            getBaseDao().get(VariantConfigValues.class, dto.getValueId());

        if (configOption != null && selectedConfigValue != null) {
          if (configOption
              .getAdditionalParam()
              .equalsIgnoreCase(VariantConfigOptionParam.ENGRAVING.param())) {
            configValue.setValue(getNameToBeEngraved());
          } else {
            configValue.setValue(selectedConfigValue.getValue());
          }
        }
        if (VariantConfigOptionParam.shouldPriceBeDoubledForParam(
            configOption.getAdditionalParam())) {
          configValue.setAdditionalPrice(selectedConfigValue.getAdditonalPrice() * 2);
        } else {
          configValue.setAdditionalPrice(selectedConfigValue.getAdditonalPrice());
        }

        if (VariantConfigOptionParam.shouldPriceBeDoubledForParam(
            configOption.getAdditionalParam())) {
          configValue.setCostPrice(selectedConfigValue.getCostPrice() * 2);
        } else {
          configValue.setCostPrice(selectedConfigValue.getCostPrice());
        }
        configValue.setVariantConfigOption(configOption);

        lineItemConfig.getCartLineItemConfigValues().add(configValue);
      }
      productVariant.setQty(new Long(1));
      if (productReferrerId != null) {
        productReferrer = getBaseDao().get(ProductReferrer.class, productReferrerId);
      }
      isLineItemCreated =
          orderManager.createLineItems(productVariant, lineItemConfig, order, productReferrer);
      userProductHistoryDao.updateIsAddedToCart(productVariant.getProduct(), user, order);

    } catch (OutOfStockException e) {
      getContext().getValidationErrors().add("e2", new SimpleError(e.getMessage()));
      return new JsonResolution(getContext().getValidationErrors(), getContext().getLocale());
    }

    Map dataMap = new HashMap();
    String cartUrl = linkManager.getCartUrl();
    dataMap.put("url", cartUrl);
    dataMap.put("name", productVariant.getProduct().getName());
    dataMap.put("qty", productVariant.getQty());
    Long itemsInCart =
        Long.valueOf(
            order.getExclusivelyProductCartLineItems().size()
                + order.getExclusivelyComboCartLineItems().size());
    dataMap.put("itemsInCart", isLineItemCreated ? itemsInCart + 1L : itemsInCart);
    HealthkartResponse healthkartResponse =
        new HealthkartResponse(
            HealthkartResponse.STATUS_OK, "Product has been added to cart", dataMap);

    noCache();
    return new JsonResolution(healthkartResponse);
  }
Ejemplo n.º 6
0
  @GET
  @Path("/applyCoupon")
  @Produces("application/json")
  public String applyCoupon(@QueryParam("couponCode") String couponCode) {
    if (StringUtils.isBlank(couponCode)) {
      message = "Please enter a coupon code.";
      return message;
    }

    coupon = couponDao.findByCode(couponCode);
    User user = getUserService().getUserById(getPrincipal().getId());
    Order order = orderManager.getOrCreateOrder(user);

    // If coupon is NULL
    // Check if the user has applied an IHO Coupon for the first time
    // and create the coupon - it will validate and then create coupon
    if (coupon == null) {
      coupon = ihoManager.createIHOCoupon(user, couponCode);
    }
    /*if (coupon == null) {
      coupon = employeeManager.createEmpCoupon(user, couponCode);
    }*/

    if (coupon == null) {
      message = "Coupon code is invalid.";
    } else {
      List<OfferInstance> offerInstances = offerInstanceDao.findByUserAndCoupon(user, coupon);
      if (offerInstances != null && !offerInstances.isEmpty()) {
        offerInstance = offerInstances.get(0);
      }
      if (offerInstance != null && !coupon.getRepetitiveUsage()) {
        if (!offerInstance.isActive()) {
          error = error_alreadyUsed;
          message = "This offer has already been used";
        } else {
          error = error_alreadyApplied;
          order.setOfferInstance(offerInstance);
          message = "You have already added this coupon.";
        }
      } else if (!coupon.isValid()) {
        message = "Coupon code has expired.";
        error = error_couponExpired;
      } else if (!offerManager.isOfferValidForUser(coupon.getOffer(), user)) {
        error = error_role;
        Offer offer = coupon.getOffer();
        if (!offerManager.isOfferValidForUserDomain(coupon.getOffer(), user)) {
          message = "The offer is valid for the following domains only:";
          for (OfferEmailDomain offerEmailDomain : offer.getOfferEmailDomains()) {
            message += "<br/>" + offerEmailDomain.getEmailDomain();
          }
        } else {
          message = "This offer is not activated for you yet.";
        }
      } else if (user.equals(coupon.getReferrerUser())) {
        message = "You are not allowed to use your own referrer code.";
      } else if (coupon.getReferrerUser() != null && user.getReferredBy() != null) {
        error = error_alreadyReferrer;
        message = "You have already mentioned your referrer.";
      } else if (coupon.getReferrerUser() != null
          && coupon.getCouponType() != null
          && !coupon.getCouponType().getId().equals(EnumCouponType.AFFILIATE.getId())
          && user.getCreateDate().before(coupon.getCreateDate())) {
        error = error_referralNotAllowed;
        message = "You are not allowed to use this referrer coupon.";
      } else if (coupon.getReferrerUser() != null && orderDao.getLatestOrderForUser(user) != null) {
        message =
            "Coupon can not be applied. This is a referral discount coupon and it is only valid before you place your first order.";
      } else {

        Date offerInstanceEndDate = null;

        // add referredBy to the user if coupon contains the referrerUser
        if (coupon.getReferrerUser() != null) {
          // add affiliate_to to the user if its an affiliate coupon
          CouponType couponType = coupon.getCouponType();
          if (couponType != null && couponType.getId().equals(EnumCouponType.AFFILIATE.getId())) {
            Assert.assertNull(user.getAffiliateTo());
            user.setAffiliateTo(coupon.getReferrerUser());
            user = (User) getBaseDao().save(user);
          } else { // its a referral coupon
            Assert.assertNull(user.getReferredBy());
            user.setReferredBy(coupon.getReferrerUser());
            user = (User) getBaseDao().save(user);
            offerInstanceEndDate =
                new DateTime()
                    .plusDays(OfferConstants.MAX_ALLOWED_DAYS_FOR_15_PERCENT_REFERREL_DISCOUNT)
                    .toDate();
          }
        }
        if (coupon.getRepetitiveUsage()) {
          List<OfferInstance> activeOfferInstances =
              offerInstanceDao.findActiveOfferInstances(user, coupon.getOffer());
          if (activeOfferInstances == null || activeOfferInstances.isEmpty()) {
            offerInstance =
                offerInstanceDao.createOfferInstance(
                    coupon.getOffer(), coupon, user, offerInstanceEndDate);
          }
        } else {
          offerInstance =
              offerInstanceDao.createOfferInstance(
                  coupon.getOffer(), coupon, user, offerInstanceEndDate);
        }
        order.setOfferInstance(offerInstance);
        coupon.setAlreadyUsed(coupon.getAlreadyUsed() + 1);
        couponDao.save(coupon);
        success = true;

        ProductVariant freeVariant = coupon.getOffer().getOfferAction().getFreeVariant();
        if (freeVariant != null) {
          // OfferTriggerMatcher offerTriggerMatcher = new
          // OfferTriggerMatcher(coupon.getOffer().getOfferTrigger(), order.getCartLineItems());
          // && offerTriggerMatcher.hasEasyMatch(false)
          if (!freeVariant.isDeleted() && !freeVariant.isOutOfStock()) {
            orderManager.createLineItems(Arrays.asList(freeVariant), order, null, null, null);
            message =
                "Free variant successfuly added to your cart. Please <a href='javascript:location.reload();' style='font-size:1.2em;'>refresh</a> your cart.";
          } else {
            message = "Oops! Offer is over.";
            error = error_freeVariantStockOver;
          }
        } else {
          message = "Coupon applied successfully.";
        }
      }
    }
    return new JSONResponseBuilder()
        .addField("offerInstance", offerInstance)
        .addField("error", error)
        .build();
  }