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
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
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);
|
|
|
|
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.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close