It would allow for cleaning up of associated resources that are not stored directly on the document. For example a custom property editor that stores related files in third party storage. All other cases can be served by doing inline add/removes via ajax in the property editor and handling the Deleting or Deleted event.
However using 'Remove Extended Content' causes a 'Saving' event with the detached content already removed. So there is no way of hijacking the change and dealing with it.
I sort of see where you're going, but if I understand correctly, I don't see how the DetachedContentTypeService events will help.
That service is only used to create the association between the Umbraco ContentType and Merchello - basically so we can isolate which ones are intended to be used by Merchello.
After that association is made, with respect to a product, a ProductVariantDetachedContent model is creating and the property values are store as key value pairs in the merchProductVariantDetachedContent table.
The work is actually done in the ProductVariantRepository.
At the moment, there is no way I can think of to externally determine when changes are made - BUT your inquiry provides a really good use case.
I can't get a change into 2.3.0 at this point, but can certainly look at it for 2.3.1 ...
We could think about bubbling up events and exposing it through the ProductService - but would need feedback and hopefully some help testing if your up for it.
Maybe something like:
CreatingExtendedContent
CreatedExtendedContent
SavingExtendedContent
SavedExtendedContent
DeletingExtendedContent
DeletedExtendedContent
If you would write up a few more details and create an issue in http://issues.merchello.com it would be great to start the discussion about this feature.
Alternatively, it may be possible (depending on how your implementation is setup) to check the DetachedContents collection of the product variants in the ProductService.Saving ...
// where "p" is the product is passed in the event args collection
var productDc = p.DetachedContents;
// do something with productDc.DetachedValues;
var variants = p.ProductVariants;
foreach(var v in variants)
{
foreach(var dc in v.DetachedContents)
{
// do something with the dc.DetachedValues
}
}
Hi Rusty, thanks for your thoughts to give a bit more detail on the specific problem I'm trying to solve:
Custom property editor that saves files to a third party api
The angular buttons for upload/delete on this do it immediately and save the document at the same time e.g. they ajax call a controller of mine that modifies DetachedContent and saves it so that the user, having used this custom property editor, doesn't need to hit save to have those changes made (similar to attachments on Jira etc)
By doing things instantly like that I don't need to hook into any events except for Product Deleting/Deleted
Deleting/Deleted provide the full document including detached content at the time of delete so I can go through those and 'clean-up'
This leaves just one hole for cleanup, 'Remove Extended Content' which does fire a Saving/Saved event but with a completely empty DetachedContent (because it's been removed) so there is no way of looping through values that are about to be removed and doing a cleanup
To address this I'd either need:
A BeforeSave event that includes the OldValues as well as the about to be saved values
A specific Extended Content Removed event that includes the content that is about to be removed (I was hoping DetachedContent Deleting was this type of event but it doesn't look like it when I attach an event handler to it using reflection)
If I was to do these changes not instantly e.g. not update the umbraco product via ajax I'd also need 'OldValues' on the product Saving event. But as I say the workaround is to just do it instantly (which is a nicer user experience anyway).
Access 'old data' in ProductService events (Detached Content )
Is it possible to access the IProduct as it existed prior to the change in the ProductService.Saving or Saved events?
This would be similar to 'OldValue' on WPF dependency properties.
It would allow for cleaning up of associated resources that are not stored directly on the document. For example a custom property editor that stores related files in third party storage. All other cases can be served by doing inline add/removes via ajax in the property editor and handling the Deleting or Deleted event.
However using 'Remove Extended Content' causes a 'Saving' event with the detached content already removed. So there is no way of hijacking the change and dealing with it.
Looking at the Merchello source there appears to be a
Event however DetachedContentTypeService is an internal class and so is inaccessible as a solution to the above
Hey Craig,
I sort of see where you're going, but if I understand correctly, I don't see how the
DetachedContentTypeService
events will help.That service is only used to create the association between the Umbraco ContentType and Merchello - basically so we can isolate which ones are intended to be used by Merchello.
After that association is made, with respect to a product, a ProductVariantDetachedContent model is creating and the property values are store as key value pairs in the merchProductVariantDetachedContent table.
The work is actually done in the
ProductVariantRepository
.https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Core/Persistence/Repositories/ProductVariantRepository.cs#L516
At the moment, there is no way I can think of to externally determine when changes are made - BUT your inquiry provides a really good use case.
I can't get a change into 2.3.0 at this point, but can certainly look at it for 2.3.1 ...
We could think about bubbling up events and exposing it through the ProductService - but would need feedback and hopefully some help testing if your up for it.
Maybe something like:
CreatingExtendedContent
CreatedExtendedContent
SavingExtendedContent
SavedExtendedContent
DeletingExtendedContent
DeletedExtendedContent
If you would write up a few more details and create an issue in http://issues.merchello.com it would be great to start the discussion about this feature.
Alternatively, it may be possible (depending on how your implementation is setup) to check the DetachedContents collection of the product variants in the ProductService.Saving ...
Hi Rusty, thanks for your thoughts to give a bit more detail on the specific problem I'm trying to solve:
To address this I'd either need:
If I was to do these changes not instantly e.g. not update the umbraco product via ajax I'd also need 'OldValues' on the product Saving event. But as I say the workaround is to just do it instantly (which is a nicer user experience anyway).
is working on a reply...