-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
412. add cart sort feature for sales
- Loading branch information
1 parent
037aaeb
commit 15e09e8
Showing
6 changed files
with
82 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Enums\Promo; | ||
|
||
use Filament\Support\Contracts\HasLabel; | ||
use Illuminate\Support\Collection; | ||
|
||
/** | ||
* Enum representing sorting options for a cart sale. | ||
*/ | ||
enum CartSortForSale: int implements HasLabel | ||
{ | ||
case PRICE_ASC = 1; | ||
case PRICE_DESC = 2; | ||
|
||
/** | ||
* Get the label for the sorting option. | ||
*/ | ||
public function getLabel(): ?string | ||
{ | ||
return match ($this) { | ||
self::PRICE_ASC => 'Цена по возрастанию', | ||
self::PRICE_DESC => 'Цена по убыванию', | ||
}; | ||
} | ||
|
||
/** | ||
* Apply the sorting option to a collection of products. | ||
*/ | ||
public function apply(Collection $products): Collection | ||
{ | ||
return match ($this) { | ||
self::PRICE_ASC => $products->sortBy('price'), | ||
self::PRICE_DESC => $products->sortByDesc('price'), | ||
}; | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/database/migrations/2024_05_19_225445_add_cart_sort_field_to_sales_table.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,32 @@ | ||
<?php | ||
|
||
use App\Enums\Promo\CartSortForSale; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('sales', function (Blueprint $table) { | ||
$table->tinyInteger('cart_sort') | ||
->default(CartSortForSale::PRICE_ASC) | ||
->after('algorithm') | ||
->comment('Sorting the cart before applying the discount'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('sales', function (Blueprint $table) { | ||
$table->dropColumn('cart_sort'); | ||
}); | ||
} | ||
}; |