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 : Wednesday, June 1, 2022 12:33:53 PM(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)
As it works today, there is no way to recalculate quantity (volume) discounts if an order is modified after it has been placed.

So I added another checkbox to the Recalculate partial view and some simple code:
Code:

            if (recalculateDiscounts)
            {
                // recalculate discounts
                IDiscountCalculator discountCalculator = AbleContext.Resolve<IDiscountCalculator>();
                discountCalculator.Calculate(order);
            }


This works if I recalculate discounts first. But if I recalculate discounts AFTER shipping is recalculated, I get an nHibernate cascade error.

Quote:

$exception {"deleted object would be re-saved by cascade (remove deleted object from associations)[CommerceBuilder.Orders.OrderItem#469836]"} NHibernate.ObjectDeletedException


Is there a way to resolve this cascade error? Maybe some sort of flush or commit after each checkbox is executed to clear the entities?

Edited by user Wednesday, June 1, 2022 12:44:27 PM(UTC)  | Reason: Not specified

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

shaharyar  
#2 Posted : Thursday, June 2, 2022 5:45:56 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)
Code:
discountCalculator.Calculate(order);


Is this your custom-written function? I can't find a calculate function with an order object as a parameter.
The default existing function takes a Basket object as a parameter.
Joe Payne2  
#3 Posted : Thursday, June 2, 2022 6:58:58 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)
Yes. It's a complete copy of discountCalculator(basket). We needed the ability to recalculate discounts on an existing order. All we did was change all the basket references to order references. It was surprisingly simple to implement.

This is probably why it blows up. My guess is shipping-recalc is changing order items that are also changed by discountCalculator. So nHibernate throws the cascade error.

Is there a way force nHibernate to commit or flush everything it's told to do after shipping-recalc, so that nHibernate doesn't have a cascade problem when discountCalculator() wants to do something to those same line items? Or perhaps tell nHibernate to forget about everything in that order and reload it all from SQL again?

I thought about just wiring them into separate buttons. That way each one happens in separate postback events which should resolve the issue. But that still leaves lots of room for user error. We need this fully automated.
nadeem  
#4 Posted : Friday, June 3, 2022 1:31:12 PM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 110

Thanks: 19 times
Was thanked: 18 time(s) in 18 post(s)
Quote:
Is there a way force nHibernate to commit or flush everything it's told to do after shipping-recalc, so that nHibernate doesn't have a cascade problem when discountCalculator() wants to do something to those same line items?


You can wrap the code inside a transaction e.g.

Code:
AbleContext.Current.Database.BeginTransaction();

....................
....................
....................

AbleContext.Current.Database.CommitTransaction();



Quote:

Or perhaps tell nHibernate to forget about everything in that order and reload it all from SQL again?


You can try reloading the order object from DB after evicting it from the first-level cache, something like this:

Code:
AbleContext.Current.Database.GetSession().Evict(order);


Users browsing this topic
Guest (3)
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.