Not able to get the skuId and offer status in addtoCartItem
Posted: Fri Mar 07, 2014 9:32 am
Hi for getting the sku Id and Offer status in addToCartItem i am calling jquery method from my product.html page but its getting null. I have tried to do ajax call for sending the itemAttibute to my controller but still its not able to get the skuId and offerstatus in addToCartItem object cause of that adding item to cart is not happening .Please see my ajax call where i am mistaking.My requirement is to while placing the order now first user has to login then after that should move to shipping detail page with adding the product in cart.
this is my ajax call on cartOperation.js
This is my product.html
snippet
This is the modify method of quickOrder()
this is my ajax call on cartOperation.js
Code: Select all
$('body').on('click', 'input.redirectTologin', function() {
var $button = $(this),
$container = $button.closest('.product_container'),
$form = $button.closest('form'),
$options = $container.find('span.option-value'),
$errorSpan = $container.find('span.error');
$productOptionsSpan = $container.find('span.productOptionsSpan');
if ($container.length == 0) {
var myId = $button.parent().attr('id').substring('productOptions'.length);
$container = $('.productActions' + myId).closest('.product_container');
$form = $container.find('form');
$options = $button.parent().find('span.option-value');
$errorSpan = $button.parent().find('span.error');
$productOptionsSpan = $container.find('span.productOptionsSpan');
}
var itemRequest = BLC.serializeObject($form),
modalClick = $button.parents('.fancybox-inner').length > 0,
wishlistAdd = $button.hasClass('addToWishlist');
if (itemRequest.hasProductOptions == "true" && !modalClick) {
$.fancybox.open($.extend({ href : '#productOptions' + itemRequest.productId}, fancyProductOptionsOptions));
} else {
$options.each(function(index, element) {
var optionType = $(element).data('optiontype');
var value;
if ("TEXT" == optionType) {
value = $(element).next().find('input').val();
} else {
var value = $(element).text();
}//need to add other types(date,long, etc) as needed
$("#sizeVarience").val(value);
itemRequest['itemAttributes[' + $(element).attr('id') + ']'] = value;
});
BLC.ajax({url: $form.attr('action'),
type: "POST",
dataType: "json",
data: itemRequest
}, function(data, extraData) {}
alert("yeah its returning something after success");
);
}
});
This is my product.html
snippet
Code: Select all
<blc:form method="POST" th:action="@{/cart/anonymousOrder}" id="orderNow">
<div th:class="*{'productActions' + id}">
<div class="in_cart"
th:classappend="${!cart.containsSku(#object.defaultSku)}? ' hidden'">
<a class="fancycart fancybox.ajax big-button gray-button"
th:href="@{/cart}">In Cart!</a>
</div>
<div class="add_to_cart prod-details-addto-cart"
th:classappend="${cart.containsSku(#object.defaultSku)}? ' hidden'">
<input type="hidden" name="productId" th:value="*{id}" /> <input
type="hidden" name="quantity" value="1" />
<input type="hidden" id="sizeVarience" name="sizeVarience" />
<input type="submit" class="redirectTologin order-now-butt" th:value="#{order.now}"/>
</div>
<p class="error" th:if="${param.errorMessage}"
th:text="${param.errorMessage[0]}"></p>
</div>
</blc:form>
This is the modify method of quickOrder()
Code: Select all
@RequestMapping(value = "/anonymousOrder", method = RequestMethod.POST )
public String quickOrder(HttpServletRequest request,
HttpServletResponse response, Model model,
@ModelAttribute("addToCartItem") AddToCartItem addToCartItem)
throws IOException, PricingException, AddToCartException {
Map<String, String> itemAttribute = addToCartItem.getItemAttributes();
String size = request.getParameter("sizeVarience");
HttpSession session = request.getSession();
if (CustomerState.getCustomer().isAnonymous()) {
//String referrer = request.getHeader("Referer");
// session.setAttribute("referrer", referrer);
String referrer1 = "/cart/anonymousOrder";
itemAttribute.put("OfferStatus", "NoOffer");
itemAttribute.put("Size_" + addToCartItem.getProductId(), "M");
addToCartItem.setItemAttributes(itemAttribute);
session.setAttribute("addToCart", addToCartItem);
session.setAttribute("url_prior_login", referrer1);
// model.addAttribute("addToCartItem", addToCartItem);
return "redirect:login";
} else {
AddToCartItem addToCartItem1 = (AddToCartItem) session
.getAttribute("addToCart");
session.removeAttribute("addToCart");
//String url = (String) session.getAttribute("referrer");
// session.removeAttribute("referrer");
this.addJson(request, response, model, addToCartItem1);
RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
redirectStrategy.sendRedirect(request, response, "/cart");
return null;
}
}