-
Notifications
You must be signed in to change notification settings - Fork 409
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,24 +20,16 @@ public function setUp(): void | |
|
||
$record->customerGroups()->detach(); | ||
|
||
$record->variants()->each(function (Model $variant) { | ||
$variant->values()->detach(); | ||
|
||
$variant->prices()->delete(); | ||
}); | ||
|
||
$record->urls()->delete(); | ||
|
||
$record->variants()->delete(); | ||
$record->variants()->get()->each->forceDelete(); | ||
|
||
$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 commentThe reason will be displayed to describe this comment to others. Learn more. this is unnecessary as handled by Spatie's Media observer for cleanup |
||
|
||
return $record->forceDelete(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @alecritson Alright, got it. |
||
}); | ||
}); | ||
|
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