Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
I hope a developer is watching the forum because there doesn't seem to be much action. I am trying to add a kit with the lowest/default price to the Google feed. I have looked at the ProductController in the admin and it has this code for the DefaultPrice: Kit Kit = Product.Kit;
if (Kit != null) productKittingModel.ItemizedDisplayOption = Kit.ItemizeDisplay ? 1 : 0;
if (GetComponents(ProductId).Count > 0) { if (Kit == null) { // WE MUST HAVE KIT TO BIND COMPONENTS Kit = new Kit(Product, false); _kitRepo.Save(Kit); } productKittingModel.PriceRange = string.Format("{0} - {1}", Kit.MinPrice.LSCurrencyFormat("lc"), Kit.MaxPrice.LSCurrencyFormat("lc")); productKittingModel.BasePrice = Product.Price; productKittingModel.DefaultPrice = Kit.DefaultPrice.LSCurrencyFormat("lc"); When I try to pick up that Kit.DefaultPrice in the Google feed, it says it is null for a product and throws an error. When I try to check for null, then I get the message that the expression is always true since it is not a nullable type, but when I try to convert to decimal, it says it is null. I am trying to get what is shown as the Default price for a kit on the Edit product page, or what shows as the price on the product page when the first kit product is selected so Google will accept the price. For example, the product is $1099, but selecting a kit product is not optional, and that raises the price so it shows as $1399? Thanks
|
|
|
|
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)
|
Hi Judy, Quote:When I try to check for null, then I get the message that the expression is always true since it is not a nullable type, but when I try to convert to decimal, it says it is null. Can you share the code for the above scenario? I can suggest something after seeing the code that is actually throwing the exception. Thanks
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
I had actually given up and removed the code, but it was along the lines of: if (product.Kit !=null) { if (product.KitStatus == KitStatus.Master) { Kit kit = product.Kit; if (kit != null && GetComponents(product).Count > 0) { price = kit.DefaultPrice ---this is where I got the null reference error }
Thanks
|
|
|
|
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)
|
It should not give the error. If there was an OR operator instead of an AND, it would give an error.
Can you try once more?
At what place you use this code?
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
I used the code in the Google feed, where each piece of product data is defined. It was really strange because when I hovered over kit.DefaultPrice, it didn't show that it was nullable, but the code wouldn't compile.
|
|
|
|
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