Skip to content

Commit

Permalink
Tweak products scope
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Jun 22, 2023
1 parent 5532acd commit 7990ccb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/Models/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,18 @@ public function scopeActive(Builder $query)
*
* @return Builder
*/
public function scopeProducts(Builder $query, iterable $productIds = [])
public function scopeProducts(Builder $query, iterable $productIds = [], string $type = 'condition')
{
if (is_array($productIds)) {
$productIds = collect($productIds);
}

return $query->where(function ($subQuery) use ($productIds) {
return $query->where(function ($subQuery) use ($productIds, $type) {
$subQuery->whereDoesntHave('purchasables')
->orWhereHas('purchasables', function ($relation) use ($productIds) {
$relation->whereIn('purchasable_id', $productIds);
->orWhereHas('purchasables', function ($relation) use ($productIds, $type) {
$relation->whereIn('purchasable_id', $productIds)
->wherePurchasableType(Product::class)
->whereType($type);
});
});
}
Expand Down

0 comments on commit 7990ccb

Please sign in to comment.