logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Tuesday, August 31, 2021 4:54:27 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Some of our products have extremely large variant lists. We can easily have 30,000+ variant combinations spread across 5 dropdowns on a single product.

This routine in ProductController.cs:
Code:

        [HttpPost]
        [Code.BuyProductDialog.GetChoiceSelections]
        [Code.BuyProductDialog.PrepareBuyProductDialogData]
        [Code.BuyProductDialog.AddToCartValidation]
        public ActionResult BuyProductDialog(BuyProductDialogParams parameters, int quantity, string addToCart, string addToWishlist, string subscribe, RestockNotificationSignup signup, decimal? price, bool? autoDeliver, short? deliveryInterval)


returns a Controller.Json() response. However the JSON response size is limited internally. It does not respect the JSON response size in web.config.

The result is any partial postback made when selecting variant dropdown choices (for large variant lists) throws an exception:
Quote:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.


The only solution I found in StackOverflow is here: https://stackoverflow.co...jsonlength-in-web-config

However the accepted fix didn't work because this isn't a web service. Further down you'll see the working solution for a controller action method is to rewrite the method's final return statement. Change it from:
Code:
return Json(new { status = "HTML", html = RenderRazorViewToString("_BuyProductDialog", model)});


to:

Code:

            return new JsonResult()
            {
                Data = new { status = "HTML", html = RenderRazorViewToString("_BuyProductDialog", model) },
                JsonRequestBehavior = JsonRequestBehavior.DenyGet,
                MaxJsonLength = int.MaxValue
            };


I suggest you make the same change as the product page will be broken for products with a large list of variant choices.

I'll continue to do more testing to be sure this resolves the issue and post here if I find new information. Ideally the variants list choices should be pulled individually via separate ajax requests to provide better scalability in larger stores. But I get why it's nice having everything loaded up in one call too.


Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

shaharyar  
#2 Posted : Tuesday, August 31, 2021 6:46:33 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 704

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
Thanks for pointing this out. I am registering this as an improvement.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.