Skip to content

Commit

Permalink
Added Promotions CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
molnarerwin committed Jul 29, 2024
1 parent 9516eaa commit 5fd80e9
Show file tree
Hide file tree
Showing 13 changed files with 579 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/Contracts/Requests/CreatePromotion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Vanilo\Admin\Contracts\Requests;

use Konekt\Concord\Contracts\BaseRequest;

interface CreatePromotion extends BaseRequest
{
}
11 changes: 11 additions & 0 deletions src/Contracts/Requests/UpdatePromotion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Vanilo\Admin\Contracts\Requests;

use Konekt\Concord\Contracts\BaseRequest;

interface UpdatePromotion extends BaseRequest
{
}
77 changes: 76 additions & 1 deletion src/Http/Controllers/PromotionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,87 @@

namespace Vanilo\Admin\Http\Controllers;

use Illuminate\Http\Request;
use Konekt\AppShell\Http\Controllers\BaseController;

use Vanilo\Admin\Contracts\Requests\CreatePromotion;
use Vanilo\Admin\Contracts\Requests\UpdatePromotion;
use Vanilo\Promotion\Models\Promotion;
use Vanilo\Promotion\Models\PromotionProxy;

class PromotionController extends BaseController
{
public function index()
{
return view('vanilo::promotion.index', ['promotions' => collect()]);
return view('vanilo::promotion.index', [
'promotions' => PromotionProxy::paginate(100),
]);
}

public function create()
{
return view('vanilo::promotion.create', [
'promotion' => app(Promotion::class),
]);
}

public function store(CreatePromotion $request)
{
try {
$promotion = PromotionProxy::create($request->validated());

flash()->success(__(':name has been created', ['name' => $promotion->name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));

return redirect()->back()->withInput();
}

return redirect(route('vanilo.admin.promotion.index'));
}

public function show(Promotion $promotion)
{
return view('vanilo::promotion.show', [
'promotion' => $promotion,
]);
}

public function edit(Promotion $promotion)
{
return view('vanilo::promotion.edit', [
'promotion' => $promotion,
]);
}

public function update(Promotion $promotion, UpdatePromotion $request)
{
try {
$promotion->update($request->validated());

flash()->success(__(':name has been updated', ['name' => $promotion->name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));

return redirect()->back()->withInput();
}

return redirect(route('vanilo.admin.promotion.index'));
}

public function destroy(Promotion $promotion)
{
try {
$name = $promotion->name;
$promotion->delete();

flash()->warning(__(':name has been deleted', ['name' => $name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));

return redirect()->back();
}

return redirect(route('vanilo.admin.promotion.index'));
}
}
33 changes: 33 additions & 0 deletions src/Http/Requests/CreatePromotion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Vanilo\Admin\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Konekt\AppShell\Validation\CurrencyExists;
use Vanilo\Admin\Contracts\Requests\CreatePromotion as CreatePromotionContract;


class CreatePromotion extends FormRequest implements CreatePromotionContract
{
public function rules()
{
return [
'name' => 'required|string|min:1|max:255',
'description' => 'nullable|string|min:1|max:65000',
'priority' => 'required|integer|min:0',
'is_exclusive' => 'required|boolean',
'usage_limit' => 'nullable|integer|min:0',
'is_coupon_based' => 'required|boolean',
'starts_at' => 'required|date|before:ends_at',
'ends_at' => 'required|date|after:starts_at',
'applies_to_discounted' => 'required|boolean',
];
}

public function authorize()
{
return true;
}
}
32 changes: 32 additions & 0 deletions src/Http/Requests/UpdatePromotion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Vanilo\Admin\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Konekt\AppShell\Validation\CurrencyExists;
use Vanilo\Admin\Contracts\Requests\UpdatePromotion as UpdatePromotionContract;

class UpdatePromotion extends FormRequest implements UpdatePromotionContract
{
public function rules()
{
return [
'name' => 'required|string|min:1|max:255',
'description' => 'nullable|string|min:1|max:65000',
'priority' => 'required|integer|min:0',
'is_exclusive' => 'required|boolean',
'usage_limit' => 'nullable|integer|min:0',
'is_coupon_based' => 'required|boolean',
'starts_at' => 'required|date|before:ends_at',
'ends_at' => 'required|date|after:starts_at',
'applies_to_discounted' => 'required|boolean',
];
}

public function authorize()
{
return true;
}
}
4 changes: 4 additions & 0 deletions src/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Vanilo\Admin\Http\Requests\CreateMedia;
use Vanilo\Admin\Http\Requests\CreatePaymentMethod;
use Vanilo\Admin\Http\Requests\CreateProduct;
use Vanilo\Admin\Http\Requests\CreatePromotion;
use Vanilo\Admin\Http\Requests\CreateProperty;
use Vanilo\Admin\Http\Requests\CreatePropertyValue;
use Vanilo\Admin\Http\Requests\CreatePropertyValueForm;
Expand All @@ -53,6 +54,7 @@
use Vanilo\Admin\Http\Requests\UpdateOrder;
use Vanilo\Admin\Http\Requests\UpdatePaymentMethod;
use Vanilo\Admin\Http\Requests\UpdateProduct;
use Vanilo\Admin\Http\Requests\UpdatePromotion;
use Vanilo\Admin\Http\Requests\UpdateProperty;
use Vanilo\Admin\Http\Requests\UpdatePropertyValue;
use Vanilo\Admin\Http\Requests\UpdateShippingMethod;
Expand Down Expand Up @@ -112,6 +114,8 @@ class ModuleServiceProvider extends BaseBoxServiceProvider
UpdateTaxRate::class,
CreateLinkForm::class,
CreateLink::class,
CreatePromotion::class,
UpdatePromotion::class,
];

public function register(): void
Expand Down
20 changes: 20 additions & 0 deletions src/resources/routes/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,23 @@
$breadcrumbs->parent('vanilo.admin.tax-rate.show', $taxRate);
$breadcrumbs->push(__('Edit'), route('vanilo.admin.tax-rate.edit', $taxRate));
});

Breadcrumbs::for('vanilo.admin.promotion.index', function ($breadcrumbs) {
$breadcrumbs->parent('home');
$breadcrumbs->push(__('Promotions'), route('vanilo.admin.promotion.index'));
});

Breadcrumbs::for('vanilo.admin.promotion.create', function ($breadcrumbs) {
$breadcrumbs->parent('vanilo.admin.promotion.index');
$breadcrumbs->push(__('Create'));
});

Breadcrumbs::for('vanilo.admin.promotion.show', function ($breadcrumbs, $promotion) {
$breadcrumbs->parent('vanilo.admin.promotion.index');
$breadcrumbs->push($promotion->name, route('vanilo.admin.promotion.show', $promotion));
});

Breadcrumbs::for('vanilo.admin.promotion.edit', function ($breadcrumbs, $promotion) {
$breadcrumbs->parent('vanilo.admin.promotion.show', $promotion);
$breadcrumbs->push(__('Edit'), route('vanilo.admin.promotion.edit', $promotion));
});
Loading

0 comments on commit 5fd80e9

Please sign in to comment.