diff --git a/packages/Webkul/Velocity/src/Database/Migrations/2020_08_17_104228_add_channel_to_velocity_meta_data_table.php b/packages/Webkul/Velocity/src/Database/Migrations/2020_08_17_104228_add_channel_to_velocity_meta_data_table.php new file mode 100644 index 000000000..ae064713a --- /dev/null +++ b/packages/Webkul/Velocity/src/Database/Migrations/2020_08_17_104228_add_channel_to_velocity_meta_data_table.php @@ -0,0 +1,32 @@ +text('channel')->after('locale'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('velocity_meta_data', function (Blueprint $table) { + // + }); + } +} diff --git a/packages/Webkul/Velocity/src/Helpers/Helper.php b/packages/Webkul/Velocity/src/Helpers/Helper.php index 0a93ecb19..a93073959 100644 --- a/packages/Webkul/Velocity/src/Helpers/Helper.php +++ b/packages/Webkul/Velocity/src/Helpers/Helper.php @@ -214,20 +214,26 @@ class Helper extends Review * * @return array */ - public function getVelocityMetaData($locale = null, $default = true) + public function getVelocityMetaData($locale = null, $channel = null, $default = true) { if (! $locale) { $locale = request()->get('locale') ?: app()->getLocale(); } + if (! $channel) { + $channel = request()->get('channel') ?: 'default'; + } + try { $metaData = $this->velocityMetadataRepository->findOneWhere([ - 'locale' => $locale + 'locale' => $locale, + 'channel' => $channel ]); if (! $metaData && $default) { $metaData = $this->velocityMetadataRepository->findOneWhere([ - 'locale' => 'en' + 'locale' => 'en', + 'channel' => 'default' ]); } @@ -295,7 +301,7 @@ class Helper extends Review * @param \Webkul\Product\Contracts\Product $product * @param bool $list * @param array $metaInformation - * + * * @return array */ public function formatProduct($product, $list = false, $metaInformation = []) @@ -398,7 +404,7 @@ class Helper extends Review } } } - + return $productCollection; } } diff --git a/packages/Webkul/Velocity/src/Http/Controllers/Admin/ConfigurationController.php b/packages/Webkul/Velocity/src/Http/Controllers/Admin/ConfigurationController.php index e2fc51f8e..f2eff00ac 100644 --- a/packages/Webkul/Velocity/src/Http/Controllers/Admin/ConfigurationController.php +++ b/packages/Webkul/Velocity/src/Http/Controllers/Admin/ConfigurationController.php @@ -15,8 +15,16 @@ class ConfigurationController extends Controller */ protected $velocityMetaDataRepository; + /** + * Locale + */ protected $locale; + /** + * Channel + */ + protected $channel; + /** * Create a new controller instance. * @@ -28,10 +36,10 @@ class ConfigurationController extends Controller $this->_config = request('_config'); $this->velocityHelper = app('Webkul\Velocity\Helpers\Helper'); - $this->velocityMetaDataRepository = $velocityMetadataRepository; $this->locale = request()->get('locale') ?: app()->getLocale(); + $this->channel = request()->get('channel') ?: 'default'; } /** @@ -39,12 +47,12 @@ class ConfigurationController extends Controller */ public function renderMetaData() { - $velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, false); + $velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, $this->channel, false); if (! $velocityMetaData) { - $this->createMetaData($this->locale); + $this->createMetaData($this->locale, $this->channel); - $velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale); + $velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, $this->channel); } $velocityMetaData->advertisement = $this->manageAddImages(json_decode($velocityMetaData->advertisement, true) ?: []); @@ -112,7 +120,7 @@ class ConfigurationController extends Controller unset($params['slides']); $params['locale'] = $this->locale; - + // update row $product = $this->velocityMetaDataRepository->update($params, $id); @@ -125,7 +133,7 @@ class ConfigurationController extends Controller * @param array $data * @param int $index * @param array $advertisement - * + * * @return array */ public function uploadAdvertisementImages($data, $index, $advertisement) @@ -138,13 +146,13 @@ class ConfigurationController extends Controller if ($image != "") { $file = 'images.' . $index . '.' . $imageId; $dir = 'velocity/images'; - + if (Str::contains($imageId, 'image_')) { if (request()->hasFile($file) && $image) { $filter_index = substr($imageId, 6, 1); if ( isset($data[$filter_index]) ) { $size = array_key_last($saveData[$index]); - + $saveImage[$size + 1] = request()->file($file)->store($dir); } else { $saveImage[substr($imageId, 6, 1)] = request()->file($file)->store($dir); @@ -153,13 +161,13 @@ class ConfigurationController extends Controller } else { if ( isset($advertisement[$index][$imageId]) && $advertisement[$index][$imageId] && !request()->hasFile($file)) { $saveImage[$imageId] = $advertisement[$index][$imageId]; - + unset($advertisement[$index][$imageId]); } - + if (request()->hasFile($file) && isset($advertisement[$index][$imageId])) { Storage::delete($advertisement[$index][$imageId]); - + $saveImage[$imageId] = request()->file($file)->store($dir); } } @@ -192,7 +200,7 @@ class ConfigurationController extends Controller /** * @param array $data * @param int $index - * + * * @return mixed */ public function uploadImage($data, $index) @@ -215,7 +223,7 @@ class ConfigurationController extends Controller /** * @param array $addImages - * + * * @return array */ public function manageAddImages($addImages) @@ -236,14 +244,15 @@ class ConfigurationController extends Controller ]; } } - + return $imagePaths; } - private function createMetaData($locale) + private function createMetaData($locale, $channel) { \DB::table('velocity_meta_data')->insert([ 'locale' => $locale, + 'channel' => $channel, 'home_page_content' => "
@include('shop::home.advertisements.advertisement-four')@include('shop::home.featured-products') @include('shop::home.product-policy') @include('shop::home.advertisements.advertisement-three') @include('shop::home.new-products') @include('shop::home.advertisements.advertisement-two')
", 'footer_left_content' => __('velocity::app.admin.meta-data.footer-left-raw-content'), diff --git a/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php b/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php index 75522d3b7..95aaaf2a2 100644 --- a/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php @@ -5,7 +5,8 @@ @stop @php - $locale = request()->get('locale') ?: app()->getLocale(); + $locale = request()->get('locale') ?: 'en'; + $channel = request()->get('channel') ?: 'default'; @endphp @section('content') @@ -29,12 +30,25 @@ + + +