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
judy at Web2Market  
#1 Posted : Monday, September 25, 2023 11:41:51 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 289

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

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

shaharyar  
#2 Posted : Wednesday, September 27, 2023 2:03:36 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)
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
judy at Web2Market  
#3 Posted : Wednesday, September 27, 2023 6:54:23 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 289

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
shaharyar  
#4 Posted : Wednesday, September 27, 2023 7:41:54 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)
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?
judy at Web2Market  
#5 Posted : Thursday, September 28, 2023 7:24:14 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 289

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.
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.