Merge pull request #299 from bagisto/jitendra

Jitendra
This commit is contained in:
JItendra Singh 2018-12-07 12:41:02 +05:30 committed by GitHub
commit e4530c0965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 219 additions and 5249 deletions

View File

@ -1,23 +1,7 @@
<?php
return [
'flatrate' => [
'code' => 'flatrate',
'title' => 'Flat Rate',
'description' => 'This is a flat rate',
'active' => true,
'default_rate' => '10',
'type' => 'per_unit',
'class' => 'Webkul\Shipping\Carriers\FlatRate',
],
'free' => [
'code' => 'free',
'title' => 'Free Shipping',
'description' => 'This is a free shipping',
'active' => true,
'class' => 'Webkul\Shipping\Carriers\Free',
]
];
?>

4
config/core.php Normal file
View File

@ -0,0 +1,4 @@
<?php
return [
];

View File

@ -1,34 +1,6 @@
<?php
return [
'cashondelivery' => [
'code' => 'cashondelivery',
'title' => 'Cash On Delivery',
'description' => 'Cash On Delivery',
'class' => 'Webkul\Payment\Payment\CashOnDelivery',
'order_status' => 'pending',
'active' => true
],
'moneytransfer' => [
'code' => 'moneytransfer',
'title' => 'Money Transfer',
'description' => 'Money Transfer',
'class' => 'Webkul\Payment\Payment\MoneyTransfer',
'order_status' => 'pending',
'active' => true
],
'paypal_standard' => [
'code' => 'paypal_standard',
'title' => 'Paypal Standard',
'description' => 'Paypal Standard',
'class' => 'Webkul\Paypal\Payment\Standard',
'order_status' => 'pending_payment',
'sandbox' => true,
'active' => true,
'business_account' => 'test@webkul.com'
]
];
?>

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js",
"/css/admin.css": "/css/admin.css"
}
"/js/admin.js": "/js/admin.js?id=c70dacdf945a32e04b77",
"/css/admin.css": "/css/admin.css?id=201f91bc553baa11139f"
}

View File

@ -1,37 +0,0 @@
<?php
namespace Webkul\Admin;
use Illuminate\Support\Facades\Config;
/**
* Facade for Configuartion.
*
* @author Rahul Shukla <rahulshukla.symfony517@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class Configuration {
/**
* ShippingMethods
*
* @var array
*/
protected $shippingMethods = [];
/**
* Collects shipping methods
*
* @return array
*/
public function getShippingMethod()
{
foreach(Config::get('carriers') as $shippingMethod) {
$object = new $shippingMethod['class'];
$shippingMethods[] = $object;
}
return $shippingMethods;
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Webkul\Admin\Facades;
use Illuminate\Support\Facades\Facade;
class Configuration extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'configuration';
}
}

View File

@ -51,9 +51,7 @@ class ConfigurationController extends Controller
*/
public function index()
{
$shippingMethods = Configuration::getShippingMethod();
return view($this->_config['view'], compact('shippingMethods'));
return view($this->_config['view']);
}
/**
@ -65,70 +63,6 @@ class ConfigurationController extends Controller
{
$data = request()->all();
unset($data['_token']);
if($data['locale'] || $data['channel']){
$locale = $data['locale'];
$channel = $data['channel'];
unset($data['locale']);
unset($data['channel']);
}
foreach($data as $key => $value) {
$reomoveUnderScore = explode ("_", $key);
$key= implode(".",$reomoveUnderScore);
$fieldName = end($reomoveUnderScore);
array_pop($reomoveUnderScore);
$fieldCode = end($reomoveUnderScore);
foreach(Configuration::getShippingMethod() as $fields) {
$code = $fields->getCode();
if($code == $fieldCode) {
$field = $fields->getFieldDetails($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;
}
$coreConfigValue = $this->coreConfig->findOneWhere([
'code' => $key,
'value' => $value,
'locale_code' => $locale_based ? $locale : null,
'channel_code' => $channel_based ? $channel : null
]);
if(!$coreConfigValue) {
$this->coreConfig->create([
'code' => $key,
'value' => $value,
'locale_code' => $locale_based ? $locale : null,
'channel_code' => $channel_based ? $channel : null
]);
}else {
$updataData['code'] = $key;
$updataData['value'] = $value;
$updataData['locale_code'] = $locale_based ? $locale : null;
$updataData['channel_code'] = $channel_based ? $channel : null;
$this->coreConfig->update($updataData, $coreConfigValue->id);
}
}
session()->flash('success', 'Shipping Method is created successfully');
return redirect()->route($this->_config['redirect']);

View File

@ -41,16 +41,6 @@ class AdminServiceProvider extends ServiceProvider
);
}
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->registerFacades();
}
/**
* Bind the the data to the views
*
@ -102,19 +92,4 @@ class AdminServiceProvider extends ServiceProvider
$this->app['config']->set($key, array_merge($config, require $path));
}
/**
* Register Bouncer as a singleton.
*
* @return void
*/
protected function registerFacades()
{
$loader = AliasLoader::getInstance();
$loader->alias('configuration', ConfigurationFacade::class);
$this->app->singleton('configuration', function () {
return new Configuration();
});
}
}

View File

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

View File

@ -1,4 +1,4 @@
<input type="text" v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($fieldDetail['name']) ?: $configData['value'] }}" data-vv-as="&quot;{{ $fieldDetail['name'] }}&quot;">
<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 +1 @@
<textarea v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $fieldDetail['name'] }}&quot;">{{ old($fieldDetail['name']) ?: $configData['value'] }}</textarea>
<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

@ -54,73 +54,69 @@
<div class="form-container">
@csrf()
@foreach($shippingMethods as $fields)
<?php
$methodFields = $fields->getConfigFields();
$code = $fields->getCode();
?>
<accordian :active="true">
<div slot="body">
@foreach($methodFields as $fieldDetail)
<?php
$validations = [];
$disabled = false;
if(isset($fieldDetail['validation'])) {
array_push($validations, $fieldDetail['validation']);
}else {
$disabled = true;
}
$validations = implode('|', array_filter($validations));
?>
@if(view()->exists($typeView = 'admin::configuration.sales.field-types.' . $fieldDetail['type']))
@foreach (config('core.carriers') as $method => $carrier)
<accordian :title="'{{ __(config('carriers.' . $method . '.title')) }}'" :active="true">
<div slot="body">
@foreach ($carrier as $field)
<?php
$name = 'carrires'.'.'.$code.'.'.$fieldDetail['name'];
$validations = [];
$disabled = false;
if (isset($field['validation'])) {
array_push($validations, $field['validation']);
} else {
$disabled = true;
}
$validations = implode('|', array_filter($validations));
?>
<div class="control-group {{ $fieldDetail['type'] }}" :class="[errors.has('{{ $name }}') ? 'has-error' : '']">
<label for="{{ $name }}" {{ $disabled == false ? 'class=required' : '' }}>
{{ $fieldDetail['title'] }}
<?php
$channel_locale = [];
if(isset($fieldDetail['channel_based']) && $fieldDetail['channel_based'])
{
array_push($channel_locale, $channel);
}
if(isset($fieldDetail['locale_based']) && $fieldDetail['locale_based']) {
array_push($channel_locale, $locale);
}
?>
@if(count($channel_locale))
<span class="locale">[{{ implode(' - ', $channel_locale) }}]</span>
@endif
</label>
@if (view()->exists($typeView = 'admin::configuration.sales.field-types.' . $field['type']))
<?php
$configData = core()->getConfigData($name, current($channel_locale), next($channel_locale));
$name = 'carriers' . '.' . $method . '.' . $field['name'];
?>
@include ($typeView)
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $name }}') ? 'has-error' : '']">
<label for="{{ $name }}" {{ $disabled == false ? 'class=required' : '' }}>
<span class="control-error" v-if="errors.has('{{ $name }}')">@{{ errors.first('{!! $name !!}') }}</span>
{{ $field['title'] }}
</div>
<?php
$channel_locale = [];
@endif
@endforeach
</div>
</accordian>
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

View File

@ -483,18 +483,21 @@ class Core
public function getConfigData($field, $channel = null, $locale = null)
{
if (null === $channel) {
$channel = $this->getCurrentChannel()->code;
$channel = request()->get('channel') ?: ($this->getCurrentChannelCode() ?: $this->getDefaultChannelCode());
}
if (null === $locale) {
$locale = app()->getLocale();
$locale = request()->get('locale') ?: app()->getLocale();
}
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
'code' => $field
]);
return $coreConfigValue;
if(!$coreConfigValue)
return Config::get($field);
return $coreConfigValue->value;
}
/**

View File

@ -0,0 +1,31 @@
<?php
return [
'cashondelivery' => [
'code' => 'cashondelivery',
'title' => 'Cash On Delivery',
'description' => 'Cash On Delivery',
'class' => 'Webkul\Payment\Payment\CashOnDelivery',
'order_status' => 'pending',
'active' => true
],
'moneytransfer' => [
'code' => 'moneytransfer',
'title' => 'Money Transfer',
'description' => 'Money Transfer',
'class' => 'Webkul\Payment\Payment\MoneyTransfer',
'order_status' => 'pending',
'active' => true
],
'paypal_standard' => [
'code' => 'paypal_standard',
'title' => 'Paypal Standard',
'description' => 'Paypal Standard',
'class' => 'Webkul\Paypal\Payment\Standard',
'order_status' => 'pending_payment',
'sandbox' => true,
'active' => true,
'business_account' => 'test@webkul.com'
]
];

View File

@ -28,6 +28,10 @@ class PaymentServiceProvider extends ServiceProvider
public function register()
{
$this->registerFacades();
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/paymentmethods.php', 'paymentmethods'
);
}
/**
* Register Bouncer as a singleton.

View File

@ -19,42 +19,6 @@ class FlatRate extends AbstractShipping
*/
protected $code = 'flatrate';
/**
* Contains field details
*
* @var string
*/
protected $fields = [
[
'name' => 'title',
'title' => 'Title',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'type' => 'textarea',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
]
];
/**
* Returns rate for flatrate
*
@ -77,28 +41,4 @@ class FlatRate extends AbstractShipping
return $object;
}
/**
* Returns Configfields for flatrate
*
* @return array
*/
public function getConfigFields()
{
return $this->fields;
}
/**
* Returns fieldDetails for flatrate
*
* @return array
*/
public function getFieldDetails($fieldName)
{
foreach ($this->fields as $field) {
if ($fieldName == $field['name']) {
return $field;
}
}
}
}

View File

@ -19,42 +19,6 @@ class Free extends AbstractShipping
*/
protected $code = 'free';
/**
* Contains field details
*
* @var string
*/
protected $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' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
]
];
/**
* Returns rate for flatrate
*
@ -77,28 +41,4 @@ class Free extends AbstractShipping
return $object;
}
/**
* Returns Configfields for flatrate
*
* @return array
*/
public function getConfigFields()
{
return $this->fields;
}
/**
* Returns fieldDetails for flatrate
*
* @return array
*/
public function getFieldDetails($fieldName)
{
foreach ($this->fields as $field) {
if ($fieldName == $field['name']) {
return $field;
}
}
}
}

View File

@ -0,0 +1,21 @@
<?php
return [
'flatrate' => [
'code' => 'flatrate',
'title' => 'Flat Rate',
'description' => 'This is a flat rate',
'active' => true,
'default_rate' => '10',
'type' => 'per_unit',
'class' => 'Webkul\Shipping\Carriers\FlatRate',
],
'free' => [
'code' => 'free',
'title' => 'Free Shipping',
'description' => 'This is a free shipping',
'active' => true,
'class' => 'Webkul\Shipping\Carriers\Free',
]
];

View File

@ -0,0 +1,66 @@
<?php
return [
'carriers' => [
'free' => [
[
'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' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
]
],
'flatrate' => [
[
'name' => 'title',
'title' => 'Title',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'type' => 'textarea',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'active',
'title' => 'Status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'validation' => 'required'
]
]
]
];

View File

@ -29,7 +29,10 @@ class ShippingServiceProvider extends ServiceProvider
public function register()
{
$this->registerFacades();
$this->registerConfig();
}
/**
* Register Bouncer as a singleton.
*
@ -44,4 +47,20 @@ class ShippingServiceProvider extends ServiceProvider
return new Shipping();
});
}
/**
* Register package config.
*
* @return void
*/
protected function registerConfig()
{
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/carriers.php', 'carriers'
);
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/fields.php', 'core'
);
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/ui.js": "/js/ui.js",
"/css/ui.css": "/css/ui.css"
}
"/js/ui.js": "/js/ui.js?id=1fdce572fb02cd8c7dad",
"/css/ui.css": "/css/ui.css?id=e78eaaed7f89740f42d9"
}