Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateProduct always raises Creating event #2264

Open
ronaldbarendse opened this issue Jun 25, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@ronaldbarendse
Copy link

commented Jun 25, 2019

The CreateProduct method from the ProductService always triggers the Creating event, even when raiseEvents = false:

public IProduct CreateProduct(string name, string sku, decimal price, bool raiseEvents = true)
{
var templateVariant = new ProductVariant(name, sku, price);
var product = new Product(templateVariant);
if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IProduct>(product), this))
{
product.WasCancelled = true;
return product;
}
if (raiseEvents)
Created.RaiseEvent(new Events.NewEventArgs<IProduct>(product), this);
return product;
}

This is different then the CreateProductWithKey:

public IProduct CreateProductWithKey(string name, string sku, decimal price, bool raiseEvents = true)
{
var templateVariant = new ProductVariant(name, sku, price);
var product = new Product(templateVariant);
if (raiseEvents)
if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IProduct>(product), this))
{
product.WasCancelled = true;
return product;
}
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateProductRepository(uow))
{
repository.AddOrUpdate(product);
uow.Commit();
}
}
if (raiseEvents)
Created.RaiseEvent(new Events.NewEventArgs<IProduct>(product), this);
return product;
}

The if-statements also don't have parenthesis, so it's quite hard to read what code gets executed when raiseEvents is set...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.