Skip to content

Commit

Permalink
basic level of coupon code crud
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Jun 3, 2017
1 parent 8b162e6 commit 6857a9b
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 7 deletions.
91 changes: 84 additions & 7 deletions modules/base/Mage2/Sale/Controllers/Admin/GiftCouponController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,98 @@
*/
namespace Mage2\Sale\Controllers\Admin;

use Illuminate\Support\Collection;
use Mage2\Sale\Models\GiftCoupon;
use Mage2\Sale\Requests\GiftCouponRequest;
use Mage2\Framework\System\Controllers\AdminController;
use Mage2\Framework\DataGrid\Facades\DataGrid;


class GiftCouponController extends AdminController {

public function getDataGrid()
{
return $users = DataGrid::dataTableData(new GiftCoupon());
}


class GiftCouponController extends AdminController
{

/**
* Display the specified page.
* Display a listing of the Category.
*
* @param NULL
* @return \Illuminate\Http\Response
*/
public function index() {

return view('mage2sale::admin.gift-coupon.index');
}

/**
* Show the form for creating a new Category.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
public function create() {


return view('mage2sale::admin.gift-coupon.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Mage2\Catalog\Requests\CategoryRequest $request
*
* @return \Illuminate\Http\Response
*/
public function store(GiftCouponRequest $request) {

GiftCoupon::create($request->all());

return redirect()->route('admin.gift-coupon.index');
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function edit($id) {

$giftCoupon = GiftCoupon::findorfail($id);

return view('mage2sale::admin.gift-coupon.edit')
->with('giftCoupon', $giftCoupon);
}

/**
* Update the specified resource in storage.
*
* @param \Mage2\Sale\Requests\GiftCouponRequest $request
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function update(GiftCouponRequest $request, $id) {
$giftCoupon = GiftCoupon::findorfail($id);

$giftCoupon->update($request->all());

return redirect()->route('admin.gift-coupon.index');
}

/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id) {

dd('Gift Coupon Controller Index Action');
GiftCoupon::destroy($id);
return redirect()->route('admin.gift-coupon.index');
}
}
65 changes: 65 additions & 0 deletions modules/base/Mage2/Sale/Models/GiftCoupon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Mage2
*
* NOTICE OF LICENSE
*
* This source file is subject to the GNU General Public License v3.0
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://www.gnu.org/licenses/gpl-3.0.en.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://mage2.website for more information.
*
* @author Purvesh <[email protected]>
* @copyright 2016-2017 Mage2
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License v3.0
*/
namespace Mage2\Sale\Models;

use Carbon\Carbon;
use Mage2\Framework\System\Models\BaseModel;

class GiftCoupon extends BaseModel
{
protected $fillable = [ 'title', 'code', 'start_date','end_date','status'];

protected $dates = ['start_date','end_date','created_at','updated_at'];

public function getStartDateAttribute($val , $format = true) {
$value = Carbon::createFromTimestamp(strtotime($val));

if(true === $format) {
return $value->format('d-M-Y');
}

return $value;
}

public function setStartDateAttribute($val) {
$value = Carbon::createFromTimestamp(strtotime($val));
$this->attributes['start_date'] = $value->toDateString();
}

public function getEndDateAttribute($val , $format = true) {
$value = Carbon::createFromTimestamp(strtotime($val));

if(true === $format) {
return $value->format('d-M-Y');
}

return $value;
}

public function setEndDateAttribute($val) {
$value = Carbon::createFromTimestamp(strtotime($val));
$this->attributes['end_date'] = $value->toDateString();
}
}
56 changes: 56 additions & 0 deletions modules/base/Mage2/Sale/Requests/GiftCouponRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Mage2
*
* NOTICE OF LICENSE
*
* This source file is subject to the GNU General Public License v3.0
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://www.gnu.org/licenses/gpl-3.0.en.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://mage2.website for more information.
*
* @author Purvesh <[email protected]>
* @copyright 2016-2017 Mage2
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License v3.0
*/
namespace Mage2\Sale\Requests;

use Illuminate\Foundation\Http\FormRequest as Request;

class GiftCouponRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$validationRule = [];

$validationRule['title'] = 'required|max:255';
$validationRule['code'] = 'required|max:255';


return $validationRule;
}
}
14 changes: 14 additions & 0 deletions modules/base/Mage2/Sale/database/Mage2SaleSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ class Mage2SaleSchema extends Migration {
*/
public function install() {


Schema::create('gift_coupons', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('code');
$table->timestamp('start_date');
$table->timestamp('end_date');
$table->enum('status',['ENABLED','DISABLED']);
$table->timestamps();
});

}

/**
Expand All @@ -45,6 +56,9 @@ public function install() {
* @return void
*/
public function uninstall() {
Schema::dropIfExits('gift_coupons');
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{!! Form::text('title','Title',['autofocus'=>true,'class' => 'form-control']) !!}
{!! Form::text('code','Code') !!}
{!! Form::text('start_date','Start Date') !!}
{!! Form::text('end_date','End Date') !!}
{!! Form::select('status','Status',['ENABLED' => 'Enabled','DISABLED' => 'Disabled']) !!}

24 changes: 24 additions & 0 deletions modules/base/Mage2/Sale/views/admin/gift-coupon/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@extends('layouts.admin')


@section('content')
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">Create Gift Coupon</div>
<div class="panel-body">

{!! Form::open(['action' => route('admin.gift-coupon.store'),'method' => 'POST']) !!}
@include('mage2sale::admin.gift-coupon._fields')

<div class="input-field">
{!! Form::submit("Create Gift Coupon",['class' => 'btn btn-primary']) !!}
{!! Form::button("cancel",['class' => 'btn disabled','onclick' => 'location="' . route('admin.gift-coupon.index'). '"']) !!}
</div>

{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection
27 changes: 27 additions & 0 deletions modules/base/Mage2/Sale/views/admin/gift-coupon/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@extends('layouts.admin')

@section('content')
<div class="row">
<div class="col-md-12">

<div class="panel-default panel">
<div class="panel-heading">

Edit Gift Coupon
<!--<small>Sub title</small> -->

</div>
<div class="panel-body">

{!! Form::bind($giftCoupon, ['method' => 'PUT', 'action' => route('admin.gift-coupon.update', $giftCoupon->id)]) !!}
@include('mage2sale::admin.gift-coupon._fields')

{!! Form::submit("Update Gift Coupon",['class' => 'btn btn-primary']) !!}
{!! Form::button("cancel",['class' => 'btn disabled','onclick' => 'location="' . route('admin.gift-coupon.index'). '"']) !!}
{!! Form::close() !!}
</div>
</div>

</div>
</div>
@endsection
62 changes: 62 additions & 0 deletions modules/base/Mage2/Sale/views/admin/gift-coupon/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@extends('layouts.admin')

@section('content')
<div class="container">
<h1>
<span class="main-title-wrap">Gift Coupon List</span>
<a style="" href="{{ route('admin.gift-coupon.create') }}" class="btn btn-primary pull-right">Create
Gift Coupon</a>
</h1>

<table class="table table-bordered" id="gift-coupon-table">
<thead>
<tr>
<th>Id</th>
<th>Title</th>

<th>Edit</th>
<th>Destroy</th>
</tr>
</thead>
</table>
</div>
@stop

@push('scripts')
<script>
$(function () {
$('#gift-coupon-table').DataTable({
processing: true,
searching: false,
serverSide: true,
ajax: '{!! route('admin.sale.gift-coupon.data-grid-table.get-data') !!}',
columns: [
{data: 'id', name: 'id'},
{data: 'title', name: 'title'},
{
data: 'edit',
name: 'edit',
sortable: false,
render: function (data, type, object, meta) {
return '<a href="/admin/sale/gift-coupon/'+ object.id +'/edit">Edit</a>';
}
},
{
data: 'destroy',
name: 'destroy',
sortable: false,
render: function (data, type, object, meta) {
return '<form id="admin-gift-coupon-destroy-'+object.id+'" method="post" action="/admin/sale/gift-coupon/'+object.id+'" >' +
'<input type="hidden" name="_method" value="DELETE"/>' +
'<input type="hidden" name="_token" value="{{ csrf_token() }}"/>' +
'</form>' +
'<a onclick="event.preventDefault();jQuery(\'#admin-gift-coupon-destroy-'+object.id+'\').submit()"' +
'href="/admin/sale/gift-coupon/'+object.id+'">Destroy' +
'</a>';
}
}
]
});
});
</script>
@endpush

0 comments on commit 6857a9b

Please sign in to comment.