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

Creating event doesn't allow setting product values #2265

ronaldbarendse opened this issue Jun 25, 2019 · 0 comments


None yet
1 participant
Copy link

commented Jun 25, 2019

Because the CreateProduct action of the ProductApiController overwrites all properties of the IProduct that's returned by the _productService.CreateProduct call (merchProduct = product.ToProduct(merchProduct);), any properties that are set in the Creating/Created events are not saved!

public ProductDisplay CreateProduct(ProductDisplay product)
// we need to remove the detached content to generate the product to begin with due to db foreign keys
var detachedContents = product.DetachedContents.ToArray();
product.DetachedContents = Enumerable.Empty<ProductVariantDetachedContentDisplay>();
// First create the product record and save it
var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);
merchProduct = product.ToProduct(merchProduct);
// we don't want to raise events here since we will be saving again and there is no sense
// in having examine index it twice. Use the detached contents to determine whether we need to fire event
_productService.Save(merchProduct, !detachedContents.Any());

Also, not raising events, but saving all other changes can cause problems when consumers of the service use the events to detect changes (like this issue: #2113).

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.