2018-11-27 04:46:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Admin\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-12-07 05:25:33 +00:00
|
|
|
use Webkul\Admin\Facades\Configuration;
|
2018-11-27 04:46:35 +00:00
|
|
|
use Webkul\Core\Repositories\CoreConfigRepository as CoreConfig;
|
2018-12-14 09:32:59 +00:00
|
|
|
use Webkul\Core\Tree;
|
2018-11-27 04:46:35 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configuration controller
|
|
|
|
|
*
|
|
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class ConfigurationController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CoreConfigRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $coreConfig;
|
|
|
|
|
|
2018-12-14 09:32:59 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $configTree;
|
|
|
|
|
|
2018-11-27 04:46:35 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @param Webkul\Core\Repositories\CoreConfigRepository $coreConfig
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(CoreConfig $coreConfig)
|
|
|
|
|
{
|
|
|
|
|
$this->middleware('admin');
|
|
|
|
|
|
2018-12-19 09:30:40 +00:00
|
|
|
$this->coreConfig = $coreConfig;
|
|
|
|
|
|
2018-11-27 04:46:35 +00:00
|
|
|
$this->_config = request('_config');
|
|
|
|
|
|
2018-12-14 09:32:59 +00:00
|
|
|
$this->prepareConfigTree();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepares config tree
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function prepareConfigTree()
|
|
|
|
|
{
|
|
|
|
|
$tree = Tree::create();
|
|
|
|
|
|
|
|
|
|
foreach(config('core') as $item) {
|
|
|
|
|
$tree->add($item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tree->items = core()->sortItems($tree->items);
|
|
|
|
|
|
|
|
|
|
$this->configTree = $tree;
|
2018-11-27 04:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2018-12-18 08:11:25 +00:00
|
|
|
$slugs = $this->getDefaultConfigSlugs();
|
2018-12-14 09:32:59 +00:00
|
|
|
|
2018-12-18 08:11:25 +00:00
|
|
|
if(count($slugs)) {
|
|
|
|
|
return redirect()->route('admin.configuration.index', $slugs);
|
|
|
|
|
}
|
2018-12-14 09:32:59 +00:00
|
|
|
|
|
|
|
|
return view($this->_config['view'], ['config' => $this->configTree]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns slugs
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getDefaultConfigSlugs()
|
|
|
|
|
{
|
2018-12-18 08:11:25 +00:00
|
|
|
$slugs = [];
|
|
|
|
|
|
|
|
|
|
if(!request()->route('slug')) {
|
|
|
|
|
$firstItem = current($this->configTree->items);
|
|
|
|
|
$secondItem = current($firstItem['children']);
|
|
|
|
|
|
|
|
|
|
$temp = explode('.', $secondItem['key']);
|
2018-12-14 09:32:59 +00:00
|
|
|
|
2018-12-18 08:11:25 +00:00
|
|
|
$slugs = [
|
|
|
|
|
'slug' => current($temp),
|
|
|
|
|
'slug2' => end($temp)
|
|
|
|
|
];
|
|
|
|
|
} else {
|
|
|
|
|
if(!request()->route('slug2')) {
|
|
|
|
|
$secondItem = current($this->configTree->items[request()->route('slug')]['children']);
|
|
|
|
|
|
|
|
|
|
$temp = explode('.', $secondItem['key']);
|
|
|
|
|
|
|
|
|
|
$slugs = [
|
|
|
|
|
'slug' => current($temp),
|
|
|
|
|
'slug2' => end($temp)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-13 10:58:28 +00:00
|
|
|
|
2018-12-18 08:11:25 +00:00
|
|
|
return $slugs;
|
2018-12-07 05:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store()
|
|
|
|
|
{
|
2018-12-14 06:26:52 +00:00
|
|
|
$this->coreConfig->create(request()->all());
|
2018-12-07 05:25:33 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', 'Shipping Method is created successfully');
|
|
|
|
|
|
2018-12-19 09:30:40 +00:00
|
|
|
return redirect()->back();
|
2018-11-27 04:46:35 +00:00
|
|
|
}
|
|
|
|
|
}
|