-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df65a47
commit e033ae9
Showing
35 changed files
with
28,876 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,53 @@ | ||
# Discounts | ||
|
||
Coming Soon... | ||
... | ||
|
||
### Fields | ||
|
||
The model used is `Shopper\Models\Discount`. | ||
|
||
| Name | Type | Required | Notes | | ||
|------------------------|----------|----------|-------------------------------------------------------------------------------------------------| | ||
| `id` | autoinc | | auto | | ||
| `code` | string | yes | The given code for the discount | | ||
| `type` | string | yes | The type of discount `Shopper\Core\Enum\DiscountType` | | ||
| `value` | int | yes | Depends on the type of discount you want to apply. It can be a percentage or a fixed amount | | ||
| `is_active` | boolean | no | Defines the visibility of the discount for customers. | | ||
| `apply_to` | string | yes | Defines what the discount can be applied to `Shopper\Core\Enum\DiscountApplyTo` | | ||
| `min_required` | string | yes | Defines the conditions required to apply the discount `Shopper\Core\Enum\DiscountRequirement` | | ||
| `min_required_value` | string | no | The minimum value required after defining the required condition, default `NULL` | | ||
| `eligibility` | string | yes | Defines discount eligibility conditions `Shopper\Core\Enum\DiscountEligibility` | | ||
| `usage_limit` | int | no | How many uses the discount has had | | ||
| `usage_limit_per_user` | boolean | no | Defines whether the coupon can be used more than once by customers | | ||
| `total_use` | int | no | The number of times the discount has been used, default `0` | | ||
| `start_at` | datetime | yes | The datetime the discount starts | | ||
| `end_at` | datetime | no | The datetime the discount expires, if `NULL` it won't expire | | ||
| `metadata` | array | no | `NULL`, json column to save any data key:value | | ||
| `zone_id` | int | no | The area in which the discount can be applied. If `NULL`, the discount can be applied anywhere. | | ||
|
||
### Components | ||
|
||
By default, discounts Livewire components are not published. To customize components, you must publish them. | ||
|
||
```bash | ||
php artisan shopper:component:publish discount | ||
``` | ||
|
||
This command will publish all Livewire components used for discount management (from pages to form components). | ||
Once you've published the component, you can find it in the `discount.php` locate in the `config/shopper/components` folder. | ||
|
||
```php | ||
use Shopper\Livewire; | ||
|
||
return [ | ||
'pages' => [ | ||
'discount-index' => Livewire\Pages\Discount\Index::class, | ||
], | ||
|
||
'components' => [ | ||
'slide-overs.discount-form' => Livewire\SlideOvers\DiscountForm::class, | ||
], | ||
]; | ||
``` | ||
|
||
## Manage Brands |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/admin/src/Actions/Store/SaveAndDispatchDiscountAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopper\Actions\Store; | ||
|
||
use Shopper\Core\Models\Discount; | ||
use Shopper\Jobs\DiscountCustomersJobs; | ||
use Shopper\Jobs\DiscountProductsJob; | ||
|
||
final readonly class SaveAndDispatchDiscountAction | ||
{ | ||
public function __invoke( | ||
array $values, | ||
?int $discountId = null, | ||
array $productsIds = [], | ||
array $customersIds = [] | ||
): Discount { | ||
$discount = Discount::query()->updateOrCreate( | ||
attributes: ['id' => $discountId], | ||
values: $values, | ||
); | ||
|
||
DiscountProductsJob::dispatch( | ||
data_get($values, 'apply_to'), | ||
$productsIds, | ||
$discount, | ||
); | ||
|
||
DiscountCustomersJobs::dispatch( | ||
data_get($values, 'eligibility'), | ||
$customersIds, | ||
$discount, | ||
); | ||
|
||
return $discount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.