London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

PromotionEngine.GetDiscountPrices throws NullRefException (Commerce 10.1.1)

Vote:
 

Hi

I have encountered an issue where the promotionEngine.GetDiscountPrices(...) throw a NullReferenceException if a variation has no pricing on it.

following the blogpost: http://world.episerver.com/blogs/Shannon-Gray/Dates/2016/10/calculating-discounted-pricing-with-episervers-new-promotion-engine/

we implemented a GetDiscountPrice method for getting the lowest discount price for a Variation in the given market.

public DiscountPrice GetDiscountPrice(Variation variation, IMarket market)
        {
            var discountEntries = _promotionEngine.GetDiscountPrices(new List { variation.ContentLink }, market, market.DefaultCurrency, _referenceConverter, _lineItemCalculator);

            var lowestDiscountedPrice = discountEntries.SelectMany(x => x.DiscountPrices).OrderBy(x => x.Price).FirstOrDefault();
            
            return lowestDiscountedPrice;
        }


Is this the intended behavior of the promotionEngine? 

/Swensson

#174388
Jan 25, 2017 13:50
Vote:
 

Can you post the full stacktrace - I took a quick look at the code and it seems that the non-price variations were handed ...

#174390
Jan 25, 2017 14:39
Vote:
 

at EPiServer.Commerce.Marketing.Internal.PromotionEngineContentLoader.CreateInMemoryOrderGroup(ContentReference entryLink, IMarket market, Currency marketCurrency)
at EPiServer.Commerce.Marketing.PromotionEngine.Evaluate(IEnumerable`1 entryLinks, IMarket market, Currency currency, RequestFulfillmentStatus requestFulfillmentStatus)
at EPiServer.Commerce.Marketing.IPromotionEngineExtensions.GetDiscountPrices(IPromotionEngine promotionEngine, IEnumerable`1 entryLinks, IMarket market, Currency marketCurrency, ReferenceConverter referenceConverter, ILineItemCalculator lineItemCalculator)
at Vertica.Pompdelux.Business.Features.Shared.Services.PricingService.GetDiscountPrice(Variation variation, IMarket market) in C:\Projects\POMPdeLUX\Development\src\Business\Features\Shared\Services\PricingService.cs:line 88
at Vertica.Pompdelux.Business.Features.Integration.RequestHandlers.IndexElasticProductsRequestHandler.MapToElasticProducts(CultureInfo currentCatalogCulture, Variation[] variations, Dictionary`2 categoryTree, Product product) in C:\Projects\POMPdeLUX\Development\src\Business\Features\Integration\RequestHandlers\IndexElasticProductsRequestHandler.cs:line 131
at Vertica.Pompdelux.Business.Features.Integration.RequestHandlers.IndexElasticProductsRequestHandler.Handle(IndexElasticProductsRequest request) in C:\Projects\POMPdeLUX\Development\src\Business\Features\Integration\RequestHandlers\IndexElasticProductsRequestHandler.cs:line 106
at Vertica.Pompdelux.Business.Infrastructure.RequestHandler.Mediator.RequestHandler`2.Handle(IRequest`1 request) in C:\Projects\POMPdeLUX\Development\src\Business\Infrastructure\RequestHandler\Mediator.cs:line 59
at Vertica.Pompdelux.Business.Infrastructure.RequestHandler.Mediator.Send[TResponse](IRequest`1 request) in C:\Projects\POMPdeLUX\Development\src\Business\Infrastructure\RequestHandler\Mediator.cs:line 20
at Vertica.Pompdelux.Business.Infrastructure.Api.BaseApiController.Send[TResponse](IRequest`1 request) in C:\Projects\POMPdeLUX\Development\src\Business\Infrastructure\Api\BaseApiController.cs:line 13
at Vertica.Pompdelux.Business.Features.Integration.Controllers.IntegrationApiController.IndexElasticProducts() in C:\Projects\POMPdeLUX\Development\src\Business\Features\Integration\Controllers\IntegrationApiController.cs:line 25
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

#174391
Jan 25, 2017 14:42
Vote:
 

You just found a bug! I will log a bug for this and we will include the fix in upcoming releases.

Thank you to bringing this into out attention.

Regards,

/Q

#174392
Jan 25, 2017 14:46
Vote:
 

No problem! :)

Can you update here when the fix is included in an upcoming release? 

/Swensson

#174394
Jan 25, 2017 14:51
Vote:
 

The bug is now fixed and will be available in upcoming releases - probably 10.4.x :) 

#174462
Jan 26, 2017 15:54
Vote:
 

Awesome! 
Thanks for the update :) 

#174463
Jan 26, 2017 15:55
Vote:
 

The 10.3 was released just three days ago. Is the bug corrected in that version?

/Kristoffer

#175578
Feb 23, 2017 15:05
Vote:
 

No, the bug is COM-3812 and it will be in 10.4 instead

#175579
Feb 23, 2017 15:11
Vote:
 

Thanks!

#175580
Feb 23, 2017 15:29
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.