From 725b70ea19fbbdb82cd825944262460fdf03dc2c Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Wed, 22 May 2019 04:42:24 +0530 Subject: [PATCH] catalog rule edit form complete --- packages/Webkul/Admin/src/Http/routes.php | 2 +- .../Admin/src/Resources/lang/en/app.php | 1 + .../promotions/catalog-rule/edit.blade.php | 464 ++++++++++++++++++ .../Controllers/CatalogRuleController.php | 16 +- 4 files changed, 474 insertions(+), 9 deletions(-) diff --git a/packages/Webkul/Admin/src/Http/routes.php b/packages/Webkul/Admin/src/Http/routes.php index b998ca69b..b48410e72 100755 --- a/packages/Webkul/Admin/src/Http/routes.php +++ b/packages/Webkul/Admin/src/Http/routes.php @@ -626,7 +626,7 @@ Route::group(['middleware' => ['web']], function () { ])->name('admin.catalog-rule.create'); Route::post('/catalog-rule/create', 'Webkul\Discount\Http\Controllers\CatalogRuleController@store')->defaults('_config', [ - 'redirect' => 'admin.catalog-rule.create' + 'redirect' => 'admin.catalog-rule.index' ])->name('admin.catalog-rule.store'); Route::get('/catalog-rule/edit/{id}', 'Webkul\Discount\Http\Controllers\CatalogRuleController@edit')->defaults('_config', [ diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 21ededad4..a84f3ae5a 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -776,6 +776,7 @@ return [ 'create-catalog-rule' => 'Create Catalog Rule', 'create-cart-rule' => 'Create Cart Rule', 'save-btn-title' => 'Create', + 'edit-btn-title' => 'Edit', 'select-attr' => 'Select Attribute', 'select-attr-fam' => 'Select Attribute Family', 'select-cart-attr' => 'Select Cart Attribute', diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/edit.blade.php index e69de29bb..8c7938c52 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/edit.blade.php @@ -0,0 +1,464 @@ +@extends('admin::layouts.content') + +@section('page_title') + {{ __('admin::app.promotion.edit-catalog-rule') }} +@stop + +@section('content') +
+ +
+ + @push('scripts') + + + + @endpush +@stop \ No newline at end of file diff --git a/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php index a2dfb69c3..84346e821 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php @@ -97,8 +97,6 @@ class CatalogRuleController extends Controller public function store() { - // dd(request()->all()); - $this->validate(request(), [ 'name' => 'required|string', 'description' => 'string', @@ -130,11 +128,11 @@ class CatalogRuleController extends Controller $catalog_rule['conditions'] = $catalog_rule['all_conditions']; unset($catalog_rule['all_conditions']); - if (isset($catalog_rule['disc_amt'])) { + if (isset($catalog_rule['disc_amount'])) { $catalog_rule['action_type'] = $catalog_rule['apply']; $catalog_rule['actions'] = [ 'action_type' => $catalog_rule['apply'], - 'disc_amt' => $catalog_rule['disc_amt'] + 'disc_amount' => $catalog_rule['disc_amount'] ]; } else if (isset($catalog_rule['disc_percent'])) { $catalog_rule['action_type'] = $catalog_rule['apply']; @@ -155,7 +153,7 @@ class CatalogRuleController extends Controller $catalogRule = $this->catalogRule->create($catalog_rule); foreach($catalog_rule_channels as $catalog_rule_channel) { - $catalog_rule_channels['catalog_rule_id'] = $catalog_rule_channel; + $catalog_rule_channels['catalog_rule_id'] = $catalogRule['id']; $catalog_rule_channels['channel_id'] = $catalog_rule_channel; $catalogRuleChannels = $this->catalogRuleChannels->create($catalog_rule_channels); } @@ -168,11 +166,13 @@ class CatalogRuleController extends Controller if($catalogRule && $catalogRuleChannels && $catalogRuleCustomerGroups) { session()->flash('success', trans('admin::app.promotion.status.success')); + + return redirect()->route('admin.catalog-rule.index'); } else { session()->flash('error', trans('admin::app.promotion.status.failed')); - } - return redirect()->back(); + return redirect()->back(); + } } public function edit($id) @@ -181,7 +181,7 @@ class CatalogRuleController extends Controller $catalog_rule_channels = $this->catalogRuleChannels->findByField('catalog_rule_id', $id); $catalog_rule_customer_groups = $this->catalogRuleCustomerGroups->findByField('catalog_rule_id', $id); - dd($catalog_rule, $catalog_rule_channels, $catalog_rule_customer_groups); + return view($this->_config['view'])->with('catalog_rule', [$this->attribute->getPartial(), $this->category->getPartial(), $this->fetchOptionableAttributes(), $this->appliedConfig, $this->appliedConditions, $catalog_rule, $catalog_rule_channels, $catalog_rule_customer_groups]); } public function fetchOptionableAttributes()