ShoppingCartItem Event Consumer

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 12 años
I have a strange situation... I created a consumer for ShoppingCartItem and it fires when adding an item to the cart but inside the HandleEvent eventMessage.Entity is null. I have verified the db entry is added.

any ideas?



public class ShoppingCartItemInsertedHandler : IConsumer<EntityInserted<ShoppingCartItem>>
{
    private readonly ICustomerService _customerService;

    public ShoppingCartItemInsertedHandler(ICustomerService customerService)
    {
    }
    public void HandleEvent(EntityInserted<ShoppingCartItem> eventMessage)
    {
           var shoppingCartItem = eventMessage.Entity; // Entity is null

           //do some more stuff here
     }
}
Hace 12 años
cybernexus wrote:
I have a strange situation... I created a consumer for ShoppingCartItem and it fires when adding an item to the cart but inside the HandleEvent eventMessage.Entity is null. I have verified the db entry is added.

any ideas?



public class ShoppingCartItemInsertedHandler : IConsumer<EntityInserted<ShoppingCartItem>>
{
    private readonly ICustomerService _customerService;

    public ShoppingCartItemInsertedHandler(ICustomerService customerService)
    {
    }
    public void HandleEvent(EntityInserted<ShoppingCartItem> eventMessage)
    {
           var shoppingCartItem = eventMessage.Entity; // Entity is null

           //do some more stuff here
     }
}


I actually think I figured it out and perhaps my code is out of date though i believe I am working from the last release of 2.2 source.



ShoppingCartItem shoppingCartItem = FindShoppingCartItemInTheCart(cart,
                shoppingCartType, productVariant, selectedAttributes, customerEnteredPrice);

if (shoppingCartItem != null)
{
    //do this stuff and update shoppingCartItem
}
else
{
    //do other stuff then the following
customer.ShoppingCartItems.Add(new ShoppingCartItem() // this is a new shoppingCartItem given directly to the add
                    {
                        ShoppingCartType = shoppingCartType,
                        ProductVariant = productVariant,
                        AttributesXml = selectedAttributes,
                        CustomerEnteredPrice = customerEnteredPrice,
                        Quantity = quantity,
                        CreatedOnUtc = now,
                        UpdatedOnUtc = now
                    });
                    _customerService.UpdateCustomer(customer);

                    _eventPublisher.EntityInserted(shoppingCartItem); // shoppingCartItem is still null from the Find function



correct me if I'm wrong but should't you create the new ShoppingCartItem and assign it to the var shoppingCart item then pass that var to customer.ShoppingCartItems.Add

I have verified that this works and that this issue still exists as a bug in the most recent changeset.
Hace 12 años
Looks like you're right!
Hace 12 años
You're right. Thanks for reporting and the fix. I'll be fixed in the next release
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.