2020-01-26 08:47:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Velocity\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2020-02-07 13:27:46 +00:00
|
|
|
use Illuminate\Support\Str;
|
2020-01-26 08:47:05 +00:00
|
|
|
use Webkul\Velocity\Repositories\VelocityMetadataRepository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Category Controller
|
|
|
|
|
*
|
|
|
|
|
* @author Shubham Mehrotra <shubhammehrotra.symfony@webkul.com> @shubhwebkul
|
2020-02-07 13:27:46 +00:00
|
|
|
* @author Vivek Sharma <viveksh047@webkul.com> @vivek-webkul
|
2020-01-26 08:47:05 +00:00
|
|
|
* @copyright 2019 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class ConfigurationController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* VelocityMetadataRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var Object
|
|
|
|
|
*/
|
|
|
|
|
protected $velocityMetaDataRepository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @param \Webkul\Velocity\Repositories\MetadataRepository $metaDataRepository
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function __construct (
|
|
|
|
|
VelocityMetadataRepository $velocityMetadataRepository
|
|
|
|
|
) {
|
|
|
|
|
$this->_config = request('_config');
|
2020-02-07 13:27:46 +00:00
|
|
|
|
|
|
|
|
$this->velocityHelper = app('Webkul\Velocity\Helpers\Helper');
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
$this->velocityMetaDataRepository = $velocityMetadataRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function renderMetaData()
|
|
|
|
|
{
|
2020-02-07 13:27:46 +00:00
|
|
|
$velocityMetaData = $this->velocityHelper->getVelocityMetaData();
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if ($velocityMetaData->advertisement) {
|
2020-02-12 11:16:06 +00:00
|
|
|
$velocityMetaData->advertisement = $this->manageAddImages(json_decode($velocityMetaData->advertisement, true));
|
|
|
|
|
}
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
return view($this->_config['view'], [
|
|
|
|
|
'metaData' => $velocityMetaData
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeMetaData($id)
|
|
|
|
|
{
|
|
|
|
|
// check if radio button value
|
|
|
|
|
if (request()->get('slides') == "on") {
|
|
|
|
|
$params = request()->all() + [
|
|
|
|
|
'slider' => 1
|
|
|
|
|
];
|
|
|
|
|
} else {
|
|
|
|
|
$params = request()->all() + [
|
|
|
|
|
'slider' => 0
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 13:27:46 +00:00
|
|
|
$velocityMetaData = $this->velocityMetaDataRepository->findorFail($id);
|
|
|
|
|
|
|
|
|
|
$advertisement = json_decode($velocityMetaData->advertisement, true);
|
|
|
|
|
|
2020-01-26 08:47:05 +00:00
|
|
|
$params['advertisement'] = [];
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if (isset($params['images'])) {
|
2020-02-07 13:27:46 +00:00
|
|
|
foreach ($params['images'] as $index => $images) {
|
|
|
|
|
$params['advertisement'][$index] = $this->uploadAdvertisementImages($images, $index, $advertisement);
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
2020-02-13 08:30:59 +00:00
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if ($advertisement) {
|
2020-02-13 08:30:59 +00:00
|
|
|
foreach ($advertisement as $key => $image_array) {
|
|
|
|
|
if (! isset($params['images'][$key])) {
|
|
|
|
|
foreach ($advertisement[$key] as $image) {
|
|
|
|
|
Storage::delete($image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-04 14:29:38 +00:00
|
|
|
if (isset($params['product_view_images'])) {
|
|
|
|
|
foreach ($params['product_view_images'] as $index => $productViewImage) {
|
|
|
|
|
if ($productViewImage !== "") {
|
|
|
|
|
$params['product_view_images'][$index] = $this->uploadImage($productViewImage, $index);
|
|
|
|
|
}
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
2020-02-04 14:29:38 +00:00
|
|
|
|
|
|
|
|
$params['product_view_images'] = json_encode($params['product_view_images']);
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$params['advertisement'] = json_encode($params['advertisement']);
|
|
|
|
|
$params['home_page_content'] = str_replace('=>', '=>', $params['home_page_content']);
|
|
|
|
|
|
|
|
|
|
unset($params['images']);
|
|
|
|
|
unset($params['slides']);
|
|
|
|
|
|
|
|
|
|
// update row
|
|
|
|
|
$product = $this->velocityMetaDataRepository->update($params, $id);
|
|
|
|
|
|
|
|
|
|
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Velocity Theme']));
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 13:27:46 +00:00
|
|
|
public function uploadAdvertisementImages($data, $index, $advertisement)
|
2020-01-26 08:47:05 +00:00
|
|
|
{
|
2020-02-07 13:27:46 +00:00
|
|
|
$save_image = [];
|
2020-02-13 08:30:59 +00:00
|
|
|
$save_data = $advertisement;
|
|
|
|
|
|
2020-01-26 08:47:05 +00:00
|
|
|
foreach ($data as $imageId => $image) {
|
2020-02-07 13:27:46 +00:00
|
|
|
$file = 'images.' . $index . '.' . $imageId;
|
|
|
|
|
$dir = 'velocity/images';
|
2020-01-26 08:47:05 +00:00
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if (Str::contains($imageId, 'image_')) {
|
2020-02-07 13:27:46 +00:00
|
|
|
if (request()->hasFile($file) && $image) {
|
2020-02-13 08:30:59 +00:00
|
|
|
$filter_index = substr($imageId, 6, 1);
|
|
|
|
|
if ( isset($data[$filter_index]) ) {
|
|
|
|
|
$size = array_key_last($save_data[$index]);
|
|
|
|
|
|
|
|
|
|
$save_image[$size + 1] = request()->file($file)->store($dir);
|
|
|
|
|
} else {
|
|
|
|
|
$save_image[substr($imageId, 6, 1)] = request()->file($file)->store($dir);
|
|
|
|
|
}
|
2020-02-07 13:27:46 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2020-02-13 08:30:59 +00:00
|
|
|
if ( isset($advertisement[$index][$imageId]) && $advertisement[$index][$imageId] && !request()->hasFile($file)) {
|
2020-02-07 13:27:46 +00:00
|
|
|
$save_image[$imageId] = $advertisement[$index][$imageId];
|
2020-02-13 08:30:59 +00:00
|
|
|
|
|
|
|
|
unset($advertisement[$index][$imageId]);
|
2020-02-07 13:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request()->hasFile($file) && isset($advertisement[$index][$imageId])) {
|
|
|
|
|
Storage::delete($advertisement[$index][$imageId]);
|
|
|
|
|
|
|
|
|
|
$save_image[$imageId] = request()->file($file)->store($dir);
|
|
|
|
|
}
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if (isset($advertisement[$index]) && $advertisement[$index]) {
|
2020-02-07 13:27:46 +00:00
|
|
|
foreach ($advertisement[$index] as $imageId) {
|
|
|
|
|
Storage::delete($imageId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $save_image;
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function uploadImage($data, $index)
|
|
|
|
|
{
|
|
|
|
|
$type = 'product_view_images';
|
|
|
|
|
$request = request();
|
|
|
|
|
|
|
|
|
|
$image = '';
|
|
|
|
|
$file = $type . '.' . $index;
|
|
|
|
|
$dir = "velocity/$type";
|
|
|
|
|
|
|
|
|
|
if ($request->hasFile($file)) {
|
|
|
|
|
Storage::delete($dir . $file);
|
|
|
|
|
|
|
|
|
|
$image = $request->file($file)->store($dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $image;
|
|
|
|
|
}
|
2020-02-07 13:27:46 +00:00
|
|
|
|
|
|
|
|
public function manageAddImages($add_images)
|
|
|
|
|
{
|
|
|
|
|
$images_path = [];
|
|
|
|
|
foreach ($add_images as $add_id => $images) {
|
|
|
|
|
foreach ($images as $key => $image) {
|
2020-02-20 07:38:52 +00:00
|
|
|
if ($image) {
|
2020-02-07 13:27:46 +00:00
|
|
|
$images_path[$add_id][] = [
|
2020-02-20 07:38:52 +00:00
|
|
|
'id' => $key,
|
2020-02-07 13:27:46 +00:00
|
|
|
'type' => null,
|
|
|
|
|
'path' => $image,
|
2020-02-20 07:38:52 +00:00
|
|
|
'url' => Storage::url($image)
|
2020-02-07 13:27:46 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $images_path;
|
|
|
|
|
}
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|