In addition to the 1st issue, after the exception occurs it seems to destroy the TeaCommerce object. Giving the following exception every time an order is called up.
Nullable object must have a value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Nullable object must have a value.
First of all the the AfterOrderFinalized event is triggeret by the /base code and not the business logic - so you need to fire that event your self - just do WebshopEvents.SendAfterOrderFinalized( order, callbackInfo );
The problem with finalize - you should try and see if any of your strings is null that you pass to the constructor of CallbackInfo. Or check what else is null. Here is the code that runs when an order is finalized
//Only finalize a cart if ( !this.IsOrder && callbackInfo.IsValid ) {
lock ( this ) { if ( callbackInfo.OrderName != null ) this.TransactionOrderName = callbackInfo.OrderName; this.TransactionPaymentAmount = callbackInfo.Amount; this.PaymentStatus = callbackInfo.PaymentStatus; if ( callbackInfo.TransactionId != null ) this.TransactionPaymentTransactionId = callbackInfo.TransactionId; if ( callbackInfo.CardType != null ) this.TransactionPaymentCardType = callbackInfo.CardType; if ( callbackInfo.CardNumber != null ) this.TransactionPaymentCardNumber = callbackInfo.CardNumber;
//From the callback we may get a different price because of extra Fee's on the payment provider. Here we add the to the original fee this.TransactionPaymentFeeWithoutVAT += ( callbackInfo.Amount - this.TotalPrice ) * ( 1M / ( 1M + this.TransactionPaymentVAT ) );
Anders, I cannot find WebshopEvents.SendAfterOrderFinalized (couldn't even find it in the object browser) can you confirm this is the right event? Also assuming we call it from the class which inherits ITeaCommerceExtension.
Some of the transaction data is set when you call goToPayment - the missing ones - orderName, PaymentAmount, CardNumber etc is in the Finalize event - so when it fails - it won't set the correct info in the DB.
Ok, the issue was not having an Email Confirmation template. But I can't see how it would error when you're clearing checking to see if the template is set.
Ahh great you solved it! It should be able to handle not having a email template - but if the xslt the template should use is missing - I think that creates the error :)
I'm still getting a NULL exception after finalizing the order. This happens when my mini cart tries to refresh the cart. Specifically the TeaCommerce.SessionController.CurrentOrder object.
I was under the impression if there is no order, Tea Commerce would create 1.
If the CurrentOrderId is null this is the code that is running - it creates a new order. Do you have a default order status and can you see if anything of the order stuff might be the reason?
Order order = new Order( SessionController.CurrentCurrency.Id, SessionController.CurrentCountry.Id, OrderStatus.GetDefaultOrderStatus().Id ); order.Save();
Finalizing issues
Hi again,
I've got a couple of odd issues, with finalizing orders.
1) Recently I've been getting an "Object reference not set to an instance of an object." when manually calling Finalize. See the code below:
Note: The order object is correctly being populated with the order.
2) WebshopEvents_AfterOrderFinalized isn't being called when manually calling Finalize, however it does get called when Finalize occurs with Paypal.
Any ideas?
In addition to the 1st issue, after the exception occurs it seems to destroy the TeaCommerce object. Giving the following exception every time an order is called up.
Nullable object must have a value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Nullable object must have a value.
Source Error:
Hi Bernard
First of all the the AfterOrderFinalized event is triggeret by the /base code and not the business logic - so you need to fire that event your self - just do WebshopEvents.SendAfterOrderFinalized( order, callbackInfo );
The problem with finalize - you should try and see if any of your strings is null that you pass to the constructor of CallbackInfo. Or check what else is null. Here is the code that runs when an order is finalized
//Only finalize a cart
if ( !this.IsOrder && callbackInfo.IsValid ) {
lock ( this ) {
if ( callbackInfo.OrderName != null )
this.TransactionOrderName = callbackInfo.OrderName;
this.TransactionPaymentAmount = callbackInfo.Amount;
this.PaymentStatus = callbackInfo.PaymentStatus;
if ( callbackInfo.TransactionId != null )
this.TransactionPaymentTransactionId = callbackInfo.TransactionId;
if ( callbackInfo.CardType != null )
this.TransactionPaymentCardType = callbackInfo.CardType;
if ( callbackInfo.CardNumber != null )
this.TransactionPaymentCardNumber = callbackInfo.CardNumber;
//From the callback we may get a different price because of extra Fee's on the payment provider. Here we add the to the original fee
this.TransactionPaymentFeeWithoutVAT += ( callbackInfo.Amount - this.TotalPrice ) * ( 1M / ( 1M + this.TransactionPaymentVAT ) );
foreach ( OrderLine orderLine in this.OrderLines ) {
//Stock management
if ( TeaCommerceSettings.IsOptimisticStockManagement ) {
NodeStock.ChangeStock( orderLine.NodeId, orderLine.Quantity );
}
}
this.IsOrder = true;
Save();
}
long? emailTemplateId = TeaCommerceSettings.DefaultConfirmationEmailId.ParseToLong();
if ( emailTemplateId != null )
EmailTemplate.GetEmailTemplate( emailTemplateId.Value ).Send( this, EmailTemplate.EmailTemplateType.Confirmation );
else
Log.Add( LogTypes.Error, -1, "Tea Commerce - Error sending confirmation email for order " + this.Id + ": No default confirmation email template selected" );
Kind regards
Anders
Anders, I cannot find WebshopEvents.SendAfterOrderFinalized (couldn't even find it in the object browser) can you confirm this is the right event? Also assuming we call it from the class which inherits ITeaCommerceExtension.
I'll get back to you about the NULL issue.
Anders, nothing in the callback info object apart from Errors is NULL. See the serialization below:
{TeaCommerce.Data.Payment.CallbackInfo}
Amount: 35.12
CardNumber: "XXXXXXXX1111"
CardType: "Credit Card (eWay)"
ErrorMessage: null
IsValid: true
OrderName: "TeaCommerce Purchase 170"
PaymentStatus: Captured
TransactionId: "9858025"
What sets the Transaction... records in the order?
TransactionCurrencyCultureName: "en-AU"
TransactionCurrencyISOCode: "AUD"
TransactionOrderName: null
TransactionPaymentAmount: null
TransactionPaymentCardNumber: null
TransactionPaymentCardType: null
TransactionPaymentFee: 0
TransactionPaymentFeeWithoutVAT: 0
TransactionPaymentName: "eWay"
TransactionPaymentTransactionId: null
TransactionPaymentVAT: 0.1
TransactionShippingFee: 9.12
TransactionShippingFeeWithoutVAT: 8.290909090909090909090909091
TransactionShippingName: "AusPost eParcel"
TransactionShippingVAT: 0.1
TransactionVAT: 0.1
Ahh sorry - you call the AfterOrderFinalized event. Its a static event in TeaCommerce.Data.Extensibility.WebshopEvents
From the code I posted - could you see if anything else would be null - in the finalize method call?
Some of the transaction data is set when you call goToPayment - the missing ones - orderName, PaymentAmount, CardNumber etc is in the Finalize event - so when it fails - it won't set the correct info in the DB.
Ok, the issue was not having an Email Confirmation template. But I can't see how it would error when you're clearing checking to see if the template is set.
long? emailTemplateId = TeaCommerceSettings.DefaultConfirmationEmailId.ParseToLong();
if ( emailTemplateId != null )
...
This could be a migration issue, with the database having a set value to an xslt that doesn't exist on the test server.
Both issues are now closed. Thanks for the great support.
Ahh great you solved it! It should be able to handle not having a email template - but if the xslt the template should use is missing - I think that creates the error :)
Kind regards
Anders
Actually, it's been semi-resolved.
I'm still getting a NULL exception after finalizing the order. This happens when my mini cart tries to refresh the cart. Specifically the TeaCommerce.SessionController.CurrentOrder object.
I was under the impression if there is no order, Tea Commerce would create 1.
Any ideas?
If the CurrentOrderId is null this is the code that is running - it creates a new order. Do you have a default order status and can you see if anything of the order stuff might be the reason?
Order order = new Order( SessionController.CurrentCurrency.Id, SessionController.CurrentCountry.Id, OrderStatus.GetDefaultOrderStatus().Id );
order.Save();
SessionController.CurrentOrderId = order.Id;
Kind regards
Anders
is working on a reply...