-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from vanilophp/feat-promotion-configuration
Promotion Configuration
- Loading branch information
Showing
22 changed files
with
631 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Contracts\Requests; | ||
|
||
use Konekt\Concord\Contracts\BaseRequest; | ||
|
||
interface CreatePromotionAction extends BaseRequest | ||
{ | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Contracts\Requests; | ||
|
||
use Konekt\Concord\Contracts\BaseRequest; | ||
|
||
interface CreatePromotionRule extends BaseRequest | ||
{ | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Contracts\Requests; | ||
|
||
use Konekt\Concord\Contracts\BaseRequest; | ||
|
||
interface UpdatePromotionAction extends BaseRequest | ||
{ | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Contracts\Requests; | ||
|
||
use Konekt\Concord\Contracts\BaseRequest; | ||
|
||
interface UpdatePromotionRule extends BaseRequest | ||
{ | ||
} |
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,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Http\Controllers; | ||
|
||
use Konekt\AppShell\Http\Controllers\BaseController; | ||
use Vanilo\Admin\Contracts\Requests\CreatePromotionAction; | ||
use Vanilo\Admin\Contracts\Requests\UpdatePromotionAction; | ||
use Vanilo\Promotion\Contracts\Promotion; | ||
use Vanilo\Promotion\Contracts\PromotionAction; | ||
use Vanilo\Promotion\Models\PromotionActionProxy; | ||
use Vanilo\Promotion\PromotionActionTypes; | ||
|
||
class PromotionActionController extends BaseController | ||
{ | ||
public function create(Promotion $promotion) | ||
{ | ||
return view('vanilo::promotion-action.create', [ | ||
'promotion' => $promotion, | ||
'action' => app(PromotionAction::class), | ||
'types' => PromotionActionTypes::choices(), | ||
]); | ||
} | ||
|
||
public function store(Promotion $promotion, CreatePromotionAction $request) | ||
{ | ||
try { | ||
$promotionAction = PromotionActionProxy::create( | ||
array_merge( | ||
[ | ||
'promotion_id' => $promotion->id, | ||
], | ||
$request->validated(), | ||
) | ||
); | ||
|
||
flash()->success(__('Action :title has been created', ['title' => $promotionAction->getTitle()])); | ||
} catch (\Exception $e) { | ||
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()])); | ||
|
||
return redirect()->back()->withInput(); | ||
} | ||
|
||
return redirect(route('vanilo.admin.promotion.show', $promotion)); | ||
} | ||
|
||
public function edit(Promotion $promotion, PromotionAction $promotionAction) | ||
{ | ||
return view('vanilo::promotion-action.edit', [ | ||
'promotion' => $promotion, | ||
'action' => $promotionAction, | ||
'types' => PromotionActionTypes::choices(), | ||
]); | ||
} | ||
|
||
public function update(Promotion $promotion, PromotionAction $promotionAction, UpdatePromotionAction $request) | ||
{ | ||
try { | ||
$promotionAction->update($request->validated()); | ||
|
||
flash()->success(__('The action :title has been updated', ['title' => $promotionAction->getTitle()])); | ||
} catch (\Exception $e) { | ||
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()])); | ||
|
||
return redirect()->back()->withInput(); | ||
} | ||
|
||
return redirect()->route('vanilo.admin.promotion.show', $promotion); | ||
} | ||
|
||
public function destroy(Promotion $promotion, PromotionAction $promotionAction) | ||
{ | ||
try { | ||
$title = $promotionAction->getTitle(); | ||
$promotionAction->delete(); | ||
|
||
flash()->warning(__('The action :title has been deleted', ['title' => $title])); | ||
} catch (\Exception $e) { | ||
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()])); | ||
|
||
return redirect()->back(); | ||
} | ||
|
||
return redirect()->route('vanilo.admin.promotion.show', $promotion); | ||
} | ||
} |
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,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Http\Controllers; | ||
|
||
use Konekt\AppShell\Http\Controllers\BaseController; | ||
use Vanilo\Admin\Contracts\Requests\CreatePromotionRule; | ||
use Vanilo\Admin\Contracts\Requests\UpdatePromotionRule; | ||
use Vanilo\Promotion\Contracts\Promotion; | ||
use Vanilo\Promotion\Contracts\PromotionRule; | ||
use Vanilo\Promotion\Models\PromotionRuleProxy; | ||
use Vanilo\Promotion\PromotionRuleTypes; | ||
|
||
class PromotionRuleController extends BaseController | ||
{ | ||
public function create(Promotion $promotion) | ||
{ | ||
return view('vanilo::promotion-rule.create', [ | ||
'promotion' => $promotion, | ||
'rule' => app(PromotionRule::class), | ||
'types' => PromotionRuleTypes::choices(), | ||
]); | ||
} | ||
|
||
public function store(Promotion $promotion, CreatePromotionRule $request) | ||
{ | ||
try { | ||
$promotionRule = PromotionRuleProxy::create( | ||
array_merge( | ||
[ | ||
'promotion_id' => $promotion->id, | ||
], | ||
$request->validated(), | ||
) | ||
); | ||
|
||
flash()->success(__('Rule :title has been created', ['title' => $promotionRule->getTitle()])); | ||
} catch (\Exception $e) { | ||
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()])); | ||
|
||
return redirect()->back()->withInput(); | ||
} | ||
|
||
return redirect(route('vanilo.admin.promotion.show', $promotion)); | ||
} | ||
|
||
public function edit(Promotion $promotion, PromotionRule $promotionRule) | ||
{ | ||
return view('vanilo::promotion-rule.edit', [ | ||
'promotion' => $promotion, | ||
'rule' => $promotionRule, | ||
'types' => PromotionRuleTypes::choices(), | ||
]); | ||
} | ||
|
||
public function update(Promotion $promotion, PromotionRule $promotionRule, UpdatePromotionRule $request) | ||
{ | ||
try { | ||
$promotionRule->update($request->validated()); | ||
|
||
flash()->success(__('The rule :title has been updated', ['title' => $promotionRule->getTitle()])); | ||
} catch (\Exception $e) { | ||
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()])); | ||
|
||
return redirect()->back()->withInput(); | ||
} | ||
|
||
return redirect()->route('vanilo.admin.promotion.show', $promotion); | ||
} | ||
|
||
public function destroy(Promotion $promotion, PromotionRule $promotionRule) | ||
{ | ||
try { | ||
$title = $promotionRule->getTitle(); | ||
$promotionRule->delete(); | ||
|
||
flash()->warning(__('The rule :title has been deleted', ['title' => $title])); | ||
} catch (\Exception $e) { | ||
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()])); | ||
|
||
return redirect()->back(); | ||
} | ||
|
||
return redirect()->route('vanilo.admin.promotion.show', $promotion); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
use Vanilo\Admin\Contracts\Requests\CreatePromotionAction as CreatePromotionActionContract; | ||
use Vanilo\Promotion\PromotionActionTypes; | ||
|
||
class CreatePromotionAction extends FormRequest implements CreatePromotionActionContract | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'type' => ['required', Rule::in(PromotionActionTypes::ids())], | ||
'configuration' => 'sometimes|json', | ||
]; | ||
} | ||
|
||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
use Vanilo\Admin\Contracts\Requests\CreatePromotionRule as CreatePromotionRuleContract; | ||
use Vanilo\Promotion\PromotionRuleTypes; | ||
|
||
class CreatePromotionRule extends FormRequest implements CreatePromotionRuleContract | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'type' => ['required', Rule::in(PromotionRuleTypes::ids())], | ||
'configuration' => 'sometimes|json', | ||
]; | ||
} | ||
|
||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
use Vanilo\Admin\Contracts\Requests\UpdatePromotionAction as UpdatePromotionActionContract; | ||
use Vanilo\Promotion\PromotionActionTypes; | ||
|
||
class UpdatePromotionAction extends FormRequest implements UpdatePromotionActionContract | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'type' => ['required', Rule::in(PromotionActionTypes::ids())], | ||
'configuration' => 'sometimes|json', | ||
]; | ||
} | ||
|
||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Admin\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
use Vanilo\Admin\Contracts\Requests\UpdatePromotionRule as UpdatePromotionRuleContract; | ||
use Vanilo\Promotion\PromotionRuleTypes; | ||
|
||
class UpdatePromotionRule extends FormRequest implements UpdatePromotionRuleContract | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'type' => ['required', Rule::in(PromotionRuleTypes::ids())], | ||
'configuration' => 'sometimes|json', | ||
]; | ||
} | ||
|
||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
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.