-
Notifications
You must be signed in to change notification settings - Fork 407
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
fix forceDelete product #2075
base: 1.x
Are you sure you want to change the base?
fix forceDelete product #2075
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
||
$record->productOptions()->detach(); | ||
|
||
$record->associations()->delete(); | ||
|
||
$record->channels()->detach(); | ||
|
||
$record->clearMediaCollection('images'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unnecessary as handled by Spatie's Media observer for cleanup
$record->variants()->each(function (Model $variant) { | ||
$variant->values()->detach(); | ||
|
||
$variant->prices()->delete(); | ||
}); | ||
|
||
$record->urls()->delete(); | ||
|
||
$record->variants()->delete(); | ||
$record->variants()->get()->each->forceDelete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup to use ProductVariant observer for handling relationship
|
||
$record->productOptions()->detach(); | ||
|
||
$record->associations()->delete(); | ||
|
||
$record->channels()->detach(); | ||
|
||
$record->clearMediaCollection('images'); | ||
|
||
return $record->forceDelete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole code could be simplified to just this one line if we register a Product observer for handling the relationships.
user land can register own observer as well, i think 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alecritson need your input on this, not sure is ProductObserver is purposely left out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wychoong Yeah I think ultimately having this kind of logic in the panel is a mistake, we should really be using observers, whether within the model itself or in a separate class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alecritson Alright, got it.
Can you review the part for media observer? Will prepare a separate pr for the product observer
No description provided.