@DefaultHandler
 public Resolution pre() {
   if (prodVariantId != null && !prodVariantId.isEmpty()) {
     loyaltyProduct = loyaltyProductDao.getProductbyVariantId(prodVariantId);
     prodVariant = loyaltyProduct.getVariant();
     product = prodVariant.getProduct();
     // To handle proxy instances from hibernate
     if (product instanceof HibernateProxy) {
       HibernateProxy proxy = (HibernateProxy) product;
       product = (Product) proxy.getHibernateLazyInitializer().getImplementation();
     }
   }
   return new ForwardResolution("/pages/loyalty/productDescription.jsp");
 }
  @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);
  }