umbraco / Umbraco.Commerce.Issues

18 stars 2 forks source link

Store ID is null #569

Open RunnicFusion opened 2 days ago

RunnicFusion commented 2 days ago

Describe the bug When getting the picked Umbraco Commerce store on our homepage (datatype: Umbraco.Commerce.StorePicker) an error occurs. Looks like the store ID is empty when getting the published node trough UmbracoContext

Steps To Reproduce Steps to reproduce the behavior:

  1. Create order
  2. Use StoreId in (custom code)
  3. Store ID GUID is empty

Expected behavior In v10 this piece of code wans't trowing errors and the store ID could be retrieved perfectly fine.

Screenshots image

Additional context Example code snippet using StoreId:

[HttpGet]
public async Task<string> GetPaymentUrl(string orderNumber)
{
    return await _unitOfWorkProvider.ExecuteAsync(async delegate (IUnitOfWork uow, CancellationToken ct)
    {
        using var umbracoContext = _umbracoContextFactory.EnsureUmbracoContext();
        var storeId = umbracoContext.UmbracoContext.Content.GetAtRoot()?.OfType<Homepage>().FirstOrDefault()?.Store.Id ?? throw new StoreNotFoundException();
        var order = _umbracoCommerceApi.GetOrder(storeId, orderNumber).AsWritable(uow) ?? throw new OrderNotFoundException($"{nameof(orderNumber)}:{orderNumber}");
        var paymentMethod = _umbracoCommerceApi.GetPaymentMethods(storeId).First(x => x.Name.Equals("Buckaroo", StringComparison.InvariantCultureIgnoreCase));

        var paymentProviderContext = _paymentProviderContextFactory.CreateContext(order, paymentMethod);

        // more code here

    });
}

other code example, this time in our paymentprovider callback action using logic like:

var homepage = _publishedContentContextAcc.Content?.AncestorOrSelf<Homepage>()
var storeId = homepage?.Store?.Id ?? throw new Exception("No store id found");

No error is thrown in logs, but I see this error very often:

"Value cannot be null. (Parameter 'key1')"

Exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'key1')
   at Umbraco.Cms.Infrastructure.PublishedCache.Property.HasValue(String culture, String segment)
   at Umbraco.Extensions.PublishedPropertyExtension.Value[T](IPublishedProperty property, IPublishedValueFallback publishedValueFallback, String culture, String segment, Fallback fallback, T defaultValue)
   at Umbraco.Commerce.Cms.Helpers.PublishedContentHelper.GetPropertyValue[T](IPublishedProperty prop, String culture, Fallback fallback)
   at Umbraco.Commerce.Cms.Helpers.PublishedContentHelper.GetNodePropertyValue[T](IPublishedContent productNode, IPublishedElement productVariantNode, String propertyAlias, String languageIsoCode, Func`2 ancestorSelector, Boolean recursive, Func`2 hasValueCheck, VariantFallbackBehavior variantFallbackBehavior)
   at Umbraco.Commerce.Cms.Finders.UmbracoPublishedContentStoreFinder.FindStore(Int32 nodeId)
   at Umbraco.Commerce.Cms.Services.UmbracoStoreService.FindStoreByNodeId(Int32 nodeId)
   at Umbraco.Commerce.Cms.PropertyEditors.Stock.UmbracoStockSynchronizer.Synchronize(IContent content, SynchronizeAttempt attempt)
   at Umbraco.Commerce.Cms.Events.Notification.Handlers.SynchronizeUmbracoStockOnSaving.Handle(ContentSavingNotification notification)
   at Umbraco.Cms.Core.Events.INotificationHandler`1.Handle(IEnumerable`1 notifications)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishCore[TNotification](IEnumerable`1 allHandlers, IEnumerable`1 notifications)
   at Umbraco.Cms.Core.Events.NotificationHandlerWrapperImpl`1.Handle[TNotification,TNotificationHandler](IEnumerable`1 notifications, ServiceFactory serviceFactory, Action`2 publish)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishNotifications[TNotification,TNotificationHandler](IEnumerable`1 notifications)
   at Umbraco.Cms.Core.Events.EventAggregator.Publish[TNotification,TNotificationHandler](IEnumerable`1 notifications)
   at Umbraco.Cms.Core.Events.ScopedNotificationPublisher`1.PublishCancelable(ICancelableNotification notification)
   at Umbraco.Cms.Core.Services.ContentService.PerformScheduledPublishingExpiration(DateTime date, List`1 results, EventMessages evtMsgs, Lazy`1 allLangs)
   at Umbraco.Cms.Core.Services.ContentService.PerformScheduledPublish(DateTime date)
   at Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.ScheduledPublishingJob.RunJobAsync()

Umbraco Commerce version: Umbraco Commerce version: 13.1.4 CMS version: 13.4.0

Note: Was previously running version v10 with Umbraco Commerce version 10.0.9 without this issue. Saw the key1 is null error also in our v10 install but without issues.

mattbrailsford commented 1 day ago

Can you 1) confirm your store picker alias is “store” and 2) is the issue still present if you rebuild your internal lucene index and force update the internal memory cache? (Dashboards in the settings section)