Redirect to checkout page on Button Click

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hello !!

I have customized "Buy Now" button in NopCommerce 3.80, I am able to add product in cart on button click but not able to redirect to checkout page or shopping cart.

Please help...
6 years ago
You need to change some code for that with test scenarios like if product has attributes to select before add to cart and other.

That method located at Nop.Web > Controllers > ShoppingCart > ShoppingCartController: AddProductToCart_Catalog

Change this:

return Json(new
{
    success = true,
    message = string.Format(_localizationService.GetResource("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl("ShoppingCart")),
    updatetopcartsectionhtml = updatetopcartsectionhtml,
    updateflyoutcartsectionhtml = updateflyoutcartsectionhtml
});


To

return Json(new
{
    redirect = Url.RouteUrl("ShoppingCart"),
});


This helps you to redirect to the shopping cart page, as per my suggestion, you should not redirect to checkout page directly without accept the policy.
  
Here is just simple example, you need to figure out all the test cases and make it more feasible.

Edit:
Go with Sohel's answer, I was not aware of it. Thanks @Sohel
6 years ago
SSeBookStore wrote:
Hello !!

I have customized "Buy Now" button in NopCommerce 3.80, I am able to add product in cart on button click but not able to redirect to checkout page or shopping cart.

Please help...


Go to Admin >Configuration>Settings>Shopping cart settings==>"/Admin/Setting/ShoppingCart"

Choose Advance mode. then Checked the checkbox "Display cart after adding product"  And save it.

See from the link.
http://www.openscreenshot.com/BJ6rLeW2b
6 years ago
Divyang wrote:
You need to change some code for that with test scenarios like if product has attributes to select before add to cart and other.

That method located at Nop.Web > Controllers > ShoppingCart > ShoppingCartController: AddProductToCart_Catalog

Change this:

return Json(new
{
    success = true,
    message = string.Format(_localizationService.GetResource("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl("ShoppingCart")),
    updatetopcartsectionhtml = updatetopcartsectionhtml,
    updateflyoutcartsectionhtml = updateflyoutcartsectionhtml
});


To

return Json(new
{
    redirect = Url.RouteUrl("ShoppingCart"),
});


This helps you to redirect to the shopping cart page, as per my suggestion, you should not redirect to checkout page directly without accept the policy.
  
Here is just simple example, you need to figure out all the test cases and make it more feasible.

Edit:
Go with Sohel's answer, I was not aware of it. Thanks @Sohel


@Sohel.. I know this setting but it would not be able to solve my problem..

@Divyang.. What I want is to add a BuyNow button on product detail page. As Add to Cart is already there.

I debugged the controller and found that after click add to cart button, "ShoppingCartController:AddProductToCart_Catalog" is not calling so can I know which method it fires ??

Add to Cart button onclick : "AjaxCart.addproducttocart_details('@Url.RouteUrl("AddProductToCart-Details", new { productId = Model.Id, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })', '#product-details-form');return false;""

Hope it helps and my problem is clear to you...
6 years ago
SSeBookStore wrote:

@Divyang.. What I want is to add a BuyNow button on product detail page. As Add to Cart is already there.

I debugged the controller and found that after click add to cart button, "ShoppingCartController:AddProductToCart_Catalog" is not calling so can I know which method it fires ??


Product detail add to cart button will fire AddProductToCart_Details from ShoppingCartController.
6 years ago
Divyang wrote:

@Divyang.. What I want is to add a BuyNow button on product detail page. As Add to Cart is already there.

I debugged the controller and found that after click add to cart button, "ShoppingCartController:AddProductToCart_Catalog" is not calling so can I know which method it fires ??


Product detail add to cart button will fire AddProductToCart_Details from ShoppingCartController.


I tried that.. but it doesn't work..

I changed the return jason in the case "ShoppingCartType.ShoppingCart" but that also don't worked for me..
6 years ago
SSeBookStore wrote:
You need to change some code for that with test scenarios like if product has attributes to select before add to cart and other.



I debugged the controller and found that after click add to cart button, "ShoppingCartController:AddProductToCart_Catalog" is not calling so can I know which method it fires ??


==> ShoppingCartController:AddProductToCart_Details(...) will fire


Note: Already replied by Mr. Divyang, So ignore it.
6 years ago
SSeBookStore wrote:

I tried that.. but it doesn't work..


It should fire, not sure why it doesn't work, did you customize anything? view page override? route override?
6 years ago
Divyang wrote:

I tried that.. but it doesn't work..

It should fire, not sure why it doesn't work, did you customize anything? view page override? route override?


No.. Not customized anything yet in ShoppingCart Controller nor override route.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.