1

I'm trying to check whether Sellable item exists or not and using below code, but it is always returning null whether Sellable item is present or not in database.

public class GetCommerceEntity : CommerceCommand
{
    private readonly CommerceCommander _commander;
    public GetCommerceEntity(CommerceCommander commander, IServiceProvider serviceProvider)
        : base(serviceProvider)
    {
        _commander = commander;
    }

    public virtual async Task<bool> Process(CommerceContext commerceContext, ImportJSONDto importJSONDto)
    {
        using (CommandActivity.Start(commerceContext, this))
        {
            try
            {
                var result = await _commander.Command<GetSellableItemCommand>().Process(commerceContext, "Entity-SellableItem-" + importJSONDto.EntityId.ToString().Trim(), true);
                if (result != null) { return true; }
                else { return false; }
            }
            catch (Exception ex)
            {
                Log.Error(ex.StackTrace);
                return false;
            }
        }
    }
}

enter image description here

2
  • Did you debug and check the value of importJSONDto.EntityId ? Usually EntityId already contains the prefix you are appending here. Commented Apr 27 at 12:39
  • Yes, I've checked it finally passing this- Entity-SellableItem-2416129. Also, same code checked with colleague system, same result i.e. null. Added screen shot for your reference. Thanks Commented Apr 27 at 12:58

2 Answers 2

0

Can you try getting using this command

public class GetCommerceEntity : CommerceCommand
{
    private readonly GetSellableItemCommand _getSellableItemCommand;
    public GetCommerceEntity(GetSellableItemCommand getSellableItemCommand, IServiceProvider serviceProvider)
        : base(serviceProvider)
    {
        _getSellableItemCommand = getSellableItemCommand;
    }

    public virtual async Task<bool> Process(CommerceContext commerceContext, ImportJSONDto importJSONDto)
    {
         using (var activity = CommandActivity.Start(commerceContext, this))
         {
            try
            {
                var identifier = $"Entity-SellableItem-{importJSONDto.EntityId.ToString().Trim()}"; // Verify the prefix
                var result = await _getSellableItemCommand.Process(commerceContext, identifier ).ConfigureAwait(continueOnCapturedContext: false);
                if (result != null) { return true; }
                else { return false; }
            }
            catch (Exception ex)
            {
                 Log.Error(ex.StackTrace);
                 return false;
            }
        }
    }
}

Hope this helps !

0

We faced this issue in one of our project and found that whenever we were adding or updating any item, a restart or IIS reset was required to reflect the sellable items. Please do that and try again that may help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.