Skip to content

Fix discount conditions on collections#2345

Merged
glennjacobs merged 15 commits intolunarphp:1.xfrom
ryanmitchell:fix/seperate-collection-conditions
Dec 8, 2025
Merged

Fix discount conditions on collections#2345
glennjacobs merged 15 commits intolunarphp:1.xfrom
ryanmitchell:fix/seperate-collection-conditions

Conversation

@ryanmitchell
Copy link
Contributor

This PR builds on the work done in #2250

It:

  1. Adds a brand check
  2. Seperates collections into its own relation manager to allow it to continue to use collection_discount table

It's breaking, but for v2 we should consolidate everything into the discountable table - I missed these when I did this initial piece of work. It would make the UI much more streamlined and from a data point of view reduce the redundancy of the tables.

fredmarmillod and others added 12 commits July 21, 2025 09:13
- Added whereDiscountableType() checks to whereDoesntHave subqueries in scopeCollections, scopeProducts, and scopeProductVariants
- Ensures proper filtering when discounts have mixed discountable types
- Added comprehensive test coverage for all three scope methods
- Tests verify correct behavior with mixed types and edge cases
- Add discountable_type filtering to products() and productVariants() scopes
- Ensures scopes only match discountables of the correct type
- Add comprehensive tests covering the new type filtering behavior
Keep local implementation of collections scope tests using pivot table relationships
@glennjacobs glennjacobs requested a review from Copilot November 12, 2025 09:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes discount conditions on collections by adding brand checks and separating collection discount relationships from the generic discountable table. The changes ensure that collection discounts use a dedicated collection_discount pivot table while brand and product discounts use the brand_discount and discountables tables respectively.

Key Changes:

  • Added brand scope filtering to discount queries
  • Separated collection conditions into a dedicated relation manager
  • Fixed table prefix handling for pivot table queries

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/core/src/Models/Discount.php Added brands scope method and updated collections/products/variants scopes to use proper pivot table names with prefix
packages/core/src/Managers/DiscountManager.php Added brand condition checking to discount manager query
packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/ProductConditionRelationManager.php Removed collection handling from product conditions
packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionConditionRelationManager.php New relation manager for collection conditions using collection_discount pivot
packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php Added pivot table type filtering
packages/admin/src/Filament/Resources/DiscountResource/Pages/EditDiscount.php Grouped product and collection conditions together
packages/admin/src/Filament/Resources/DiscountResource.php Removed duplicate relation managers and added collection condition manager
packages/admin/resources/lang/en/discount.php Updated language strings to clarify product/variant vs collection conditions
tests/core/Unit/Models/DiscountTest.php Added comprehensive tests for collections, brands, products, and variants scopes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glennjacobs glennjacobs merged commit 28c1794 into lunarphp:1.x Dec 8, 2025
44 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants