shipping & payment methods

This commit is contained in:
rahul shukla 2018-12-14 11:56:52 +05:30
parent 56d014f1af
commit 8cd04be89c
14 changed files with 385 additions and 204 deletions

View File

@ -64,7 +64,7 @@ class ConfigurationController extends Controller
*/
public function store()
{
$data = request()->all();
$this->coreConfig->create(request()->all());
session()->flash('success', 'Shipping Method is created successfully');

View File

@ -73,15 +73,19 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'admin::configuration.index'
])->name('admin.configuration.index');
Route::post('configuration/{slug?}/{slug2?}', 'Webkul\Admin\Http\Controllers\ConfigurationController@store')->defaults('_config', [
'redirect' => 'admin.configuration.index'
])->name('admin.configuration.index.store');
//Shipping Methods Routes
Route::get('configuration/sales/shipping-methods', 'Webkul\Admin\Http\Controllers\ConfigurationController@index')->defaults('_config', [
'view' => 'admin::configuration.sales.shipping-method'
])->name('admin.configuration.sales.shipping_methods');
// Route::get('configuration/sales/shipping-methods', 'Webkul\Admin\Http\Controllers\ConfigurationController@index')->defaults('_config', [
// 'view' => 'admin::configuration.sales.shipping-method'
// ])->name('admin.configuration.sales.shipping_methods');
Route::post('configuration/sales/shipping-methods', 'Webkul\Admin\Http\Controllers\ConfigurationController@store')->defaults('_config', [
'redirect' => 'admin.configuration.sales.shipping_methods'
])->name('admin.configuration.sales.shipping_methods.store');
// Route::post('configuration/sales/shipping-methods', 'Webkul\Admin\Http\Controllers\ConfigurationController@store')->defaults('_config', [
// 'redirect' => 'admin.configuration.sales.shipping_methods'
// ])->name('admin.configuration.sales.shipping_methods.store');
// Reviews Routes

View File

@ -8,9 +8,19 @@
$validations = implode('|', array_filter($validations));
$name = $field['title'];
$data = config('carriers.flatrate.title');
$key = $item['key'];
$key = explode(".", $key);
array_shift($key);
$firstField = current($key);
$secondField = next($key);
$key = implode(".", $key);
$name = $key . '.' . $field['name'];
?>
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $name }}') ? 'has-error' : '']">
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]') ? 'has-error' : '']">
<label for="{{ $name }}" {{ !isset($field['validation']) || strpos('required', $field['validation']) < 0 ? '' : 'class=required' }}>
{{ $field['title'] }}
@ -34,21 +44,17 @@
</label>
<?php
$configData = core()->getConfigData($name, current($channel_locale), next($channel_locale));
?>
@if ($field['type'] == 'text')
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">
@elseif ($field['type'] == 'textarea')
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">{{ old($name) ?: core()->getConfigData($name) }}</textarea>
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ $field['name'] }}&quot;">{{ old($name) ?: core()->getConfigData($name) }}</textarea>
@elseif ($field['type'] == 'select')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $field['name'] }}&quot;" >
<select v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ $field['name'] }}&quot;" >
@foreach($field['options'] as $option)
@ -71,5 +77,5 @@
@endif
<span class="control-error" v-if="errors.has('{{ $name }}')">@{{ errors.first('{!! $name !!}') }}</span>
<span class="control-error" v-if="errors.has('{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]')">@{{ errors.first('{!! $name !!}') }}</span>
</div>

View File

@ -55,7 +55,7 @@
@csrf()
@if ($groups = array_get($config->items, request()->route('slug') . '.children.' . request()->route('slug2') . '.children'))
@foreach ($groups as $key => $item)
<accordian :title="'{{ __($item['name']) }}'" :active="true">
@ -64,7 +64,7 @@
@foreach ($item['fields'] as $field)
@include ('admin::configuration.field-type', ['field' => $field])
@endforeach
</div>
@ -88,7 +88,7 @@
$('#channel-switcher').val()
var query = '?channel=' + $('#channel-switcher').val() + '&locale=' + $('#locale-switcher').val();
window.location.href = "{{ route('admin.configuration.sales.shipping_methods') }}" + query;
window.location.href = "{{ route('admin.configuration.index', [request()->route('slug'), request()->route('slug2')]) }}" + query;
})
});
</script>

View File

@ -1,20 +0,0 @@
<select v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $field['name'] }}&quot;" >
@foreach($field['options'] as $option)
<?php
if($option['value']) {
$value = 1;
}else {
$value = 0;
}
$selectedOption = core()->getConfigData($name) ?? '';
?>
<option value="{{ $value }}" {{ $value == $selectedOption ? 'selected' : ''}}>
{{ $option['title'] }}
</option>
@endforeach
</select>

View File

@ -1,8 +0,0 @@
<input type="text" v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">

View File

@ -1 +0,0 @@
<textarea v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">{{ old($name) ?: core()->getConfigData($name) }}</textarea>

View File

@ -1,141 +0,0 @@
@extends('admin::layouts.content')
@section('page_title')
{{ __('admin::app.configuration.sales.shipping-method.title') }}
@stop
@section('content')
<div class="content">
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
<?php $channel = request()->get('channel') ?: core()->getDefaultChannelCode(); ?>
<form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header">
<div class="page-title">
<h1>
{{ __('admin::app.configuration.sales.shipping-method.title') }}
</h1>
<div class="control-group">
<select class="control" id="channel-switcher" name="channel">
@foreach(core()->getAllChannels() as $channelModel)
<option value="{{ $channelModel->code }}" {{ ($channelModel->code) == $channel ? 'selected' : '' }}>
{{ $channelModel->name }}
</option>
@endforeach
</select>
</div>
<div class="control-group">
<select class="control" id="locale-switcher" name="locale">
@foreach(core()->getAllLocales() as $localeModel)
<option value="{{ $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
{{ $localeModel->name }}
</option>
@endforeach
</select>
</div>
</div>
<div class="page-action">
<button type="submit" class="btn btn-lg btn-primary">
{{ __('admin::app.configuration.sales.shipping-method.save-btn-title') }}
</button>
</div>
</div>
<div class="page-content">
<div class="form-container">
@csrf()
@foreach (config('core.carriers') as $method => $carrier)
<accordian :title="'{{ __(config('carriers.' . $method . '.title')) }}'" :active="true">
<div slot="body">
@foreach ($carrier as $field)
<?php
$validations = [];
$disabled = false;
if (isset($field['validation'])) {
array_push($validations, $field['validation']);
} else {
$disabled = true;
}
$validations = implode('|', array_filter($validations));
?>
@if (view()->exists($typeView = 'admin::configuration.sales.field-types.' . $field['type']))
<?php
$name = 'carriers' . '.' . $method . '.' . $field['name'];
?>
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $name }}') ? 'has-error' : '']">
<label for="{{ $name }}" {{ $disabled == false ? 'class=required' : '' }}>
{{ $field['title'] }}
<?php
$channel_locale = [];
if(isset($field['channel_based']) && $field['channel_based'])
{
array_push($channel_locale, $channel);
}
if(isset($field['locale_based']) && $field['locale_based']) {
array_push($channel_locale, $locale);
}
?>
@if(count($channel_locale))
<span class="locale">[{{ implode(' - ', $channel_locale) }}]</span>
@endif
</label>
<?php
$configData = core()->getConfigData($name, current($channel_locale), next($channel_locale));
?>
@include ($typeView)
<span class="control-error" v-if="errors.has('{{ $name }}')">@{{ errors.first('{!! $name !!}') }}</span>
</div>
@endif
@endforeach
</div>
</accordian>
@endforeach
</div>
</div>
</form>
</div>
@stop
@push('scripts')
<script>
$(document).ready(function () {
$('#channel-switcher, #locale-switcher').on('change', function (e) {
$('#channel-switcher').val()
var query = '?channel=' + $('#channel-switcher').val() + '&locale=' + $('#locale-switcher').val();
window.location.href = "{{ route('admin.configuration.sales.shipping_methods') }}" + query;
})
});
</script>
@endpush

View File

@ -15,11 +15,11 @@
</a>
</li>
@endforeach
@else
@foreach($config->items as $key => $item)
<li class="{{ $item['key'] == request()->route('slug') ? 'active' : '' }}">
<a href="{{ route('admin.configuration.index', $item['key']) }}">
{{ isset($item['name']) ? $item['name'] : '' }}

View File

@ -4,7 +4,7 @@
<?php $keys = explode('.', $menu->currentKey); ?>
@foreach(array_get($menu->items, implode('.children.', array_slice($keys, 0, 2)) . '.children') as $item)
<li class="{{ $menu->getActive($item) }}">
<a href="{{ $item['url'] }}">
@ -12,9 +12,9 @@
</a>
</li>
@endforeach
@else
@if (array_get($config->items, request()->route('slug') . '.children'))
@foreach (array_get($config->items, request()->route('slug') . '.children') as $key => $item)

View File

@ -490,9 +490,45 @@ class Core
$locale = request()->get('locale') ?: app()->getLocale();
}
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
'code' => $field
]);
$fields = $this->getConfigField($field);
$channel_based = false;
$locale_based = false;
if (isset($fields['channel_based']) && $fields['channel_based']) {
$channel_based = true;
}
if (isset($fields['locale_based']) && $fields['locale_based']) {
$locale_based = true;
}
if (isset($fields['channel_based']) && $fields['channel_based']) {
if (isset($fields['locale_based']) && $fields['locale_based']) {
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
'code' => $field,
'channel_code' => $channel,
'locale_code' => $locale
]);
} else {
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
'code' => $field,
'channel_code' => $channel,
]);
}
} else {
if (isset($fields['locale_based']) && $fields['locale_based']) {
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
'code' => $field,
'locale_code' => $locale
]);
}
else {
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
'code' => $field,
]);
}
}
if(!$coreConfigValue)
return Config::get($field);
@ -608,7 +644,7 @@ class Core
return date('Y-m-d', $end);
}
}
/**
* Method to sort through the acl items and put them in order
*
@ -630,7 +666,31 @@ class Core
});
return $this->convertToAssociativeArray($items);
}
}
/**
* @param string $fieldName
* @return array
*/
public function getConfigField($fieldName) {
foreach (config('core') as $coreData) {
if (isset($coreData['fields'])) {
foreach ($coreData['fields'] as $field) {
$key = $coreData['key'];
$key = explode(".", $key);
array_shift($key);
$key = implode(".", $key);
$name = $key . '.' . $field['name'];
if ($name == $fieldName ) {
return $field;
}
}
}
}
}
public function convertToAssociativeArray($items)
{

View File

@ -21,4 +21,100 @@ class CoreConfigRepository extends Repository
{
return 'Webkul\Core\Models\CoreConfig';
}
/**
* @param array $data
* @return mixed
*/
public function create(array $data)
{
unset($data['_token']);
if ($data['locale'] || $data['channel'])
{
$locale = $data['locale'];
$channel = $data['channel'];
unset($data['locale']);
unset($data['channel']);
}
foreach ($data as $method => $value)
{
foreach ($value as $key => $formData)
{
foreach (array_keys($formData) as $title)
{
$fieldName = $method . '.' . $key . '.' .$title;
$value = $formData[$title];
$field = core()->getConfigField($fieldName);
$channel_based = false;
$locale_based = false;
if (isset($field['channel_based']) && $field['channel_based']) {
$channel_based = true;
}
if (isset($field['locale_based']) && $field['locale_based']) {
$locale_based = true;
}
if (isset($field['channel_based']) && $field['channel_based'])
{
if (isset($field['locale_based']) && $field['locale_based'])
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('locale_code', $locale)
->where('channel_code', $channel)
->get();
}
else
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('channel_code', $channel)
->get();
}
} else
{
if (isset($field['locale_based']) && $field['locale_based'])
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('locale_code', $locale)
->get();
}
else
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->get();
}
}
if (!count($coreConfigValue) > 0)
{
$this->model->create([
'code' => $fieldName,
'value' => $value,
'locale_code' => $locale_based ? $locale : null,
'channel_code' => $channel_based ? $channel : null
]);
} else
{
$updataData['code'] = $fieldName;
$updataData['value'] = $value;
$updataData['locale_code'] = $locale_based ? $locale : null;
$updataData['channel_code'] = $channel_based ? $channel : null;
foreach ($coreConfigValue as $coreConfig)
{
$coreConfig->update($updataData);
}
}
}
}
}
}
}

View File

@ -0,0 +1,172 @@
<?php
return [
[
'key' => 'sales',
'name' => 'Sales',
'sort' => 1
], [
'key' => 'sales.paymentmethods',
'name' => 'Payment Methods',
'sort' => 2,
], [
'key' => 'sales.paymentmethods.cashondelivery',
'name' => 'Cash On Delivery',
'sort' => 1,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'order_status',
'title' => 'Order Status',
'type' => 'select',
'options' => [
[
'title' => 'Pending',
'value' => 'pending'
], [
'title' => 'Approved',
'value' => 'Approved'
], [
'title' => 'Pending Payment',
'value' => 'pending_payment'
]
],
'validation' => 'required'
], [
'name' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
]
]
], [
'key' => 'sales.paymentmethods.moneytransfer',
'name' => 'Money Transfer',
'sort' => 2,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'order_status',
'title' => 'Order Status',
'type' => 'select',
'options' => [
[
'title' => 'Pending',
'value' => 'pending'
], [
'title' => 'Approved',
'value' => 'Approved'
], [
'title' => 'Pending Payment',
'value' => 'pending_payment'
]
],
'validation' => 'required'
], [
'name' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
]
]
], [
'key' => 'sales.paymentmethods.paypal_standard',
'name' => 'Paypal Standard',
'sort' => 3,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'order_status',
'title' => 'Order Status',
'type' => 'select',
'options' => [
[
'title' => 'Pending',
'value' => 'pending'
], [
'title' => 'Approved',
'value' => 'Approved'
], [
'title' => 'Pending Payment',
'value' => 'pending_payment'
]
],
'validation' => 'required'
], [
'name' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
], [
'name' => 'business_account',
'title' => 'Business Account',
'type' => 'select',
'type' => 'text',
'validation' => 'required'
]
]
]
];

View File

@ -19,7 +19,7 @@ class PaymentServiceProvider extends ServiceProvider
{
include __DIR__ . '/../Http/helpers.php';
}
/**
* Register services.
*
@ -29,9 +29,7 @@ class PaymentServiceProvider extends ServiceProvider
{
$this->registerFacades();
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/paymentmethods.php', 'paymentmethods'
);
$this->registerConfig();
}
/**
* Register Bouncer as a singleton.
@ -47,4 +45,19 @@ class PaymentServiceProvider extends ServiceProvider
return new Payment();
});
}
/**
* Register package config.
*
* @return void
*/
protected function registerConfig()
{
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/paymentmethods.php', 'paymentmethods'
);
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/system.php', 'core'
);
}
}