123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Models\BusinessSetting;
- use Artisan;
- use CoreComponentRepository;
- class BusinessSettingsController extends Controller
- {
- public function general_setting(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.general_settings');
- }
- public function update2(Request $request)
- {
- foreach ($request->types as $key => $type) {
- if($type == 'site_name'){
- $this->overWriteEnvFile('APP_NAME', $request[$type]);
- }
- if($type == 'timezone'){
- $this->overWriteEnvFile('APP_TIMEZONE', $request[$type]);
- }
- else {
- $lang = null;
- if(gettype($type) == 'array'){
- $lang = array_key_first($type);
- $type = $type[$lang];
- $business_settings = BusinessSetting::where('type', $type)->where('lang',$lang)->first();
- }else{
- $business_settings = BusinessSetting::where('type', $type)->first();
- }
- if($business_settings!=null){
- if(gettype($request[$type]) == 'array'){
- $business_settings->value = json_encode($request[$type]);
- }
- else {
- $business_settings->value = $request[$type];
- }
- $business_settings->lang = $lang;
- $business_settings->save();
- }
- else{
- $business_settings = new BusinessSetting;
- $business_settings->type = $type;
- if(gettype($request[$type]) == 'array'){
- $business_settings->value = json_encode($request[$type]);
- }
- else {
- $business_settings->value = $request[$type];
- }
- $business_settings->lang = $lang;
- $business_settings->save();
- }
- }
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
-
- }
- public function activation(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.activation');
- }
- public function social_login(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.social_login');
- }
- public function smtp_settings(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.smtp_settings');
- }
- public function google_analytics(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.google_configuration.google_analytics');
- }
- public function google_recaptcha(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.google_configuration.google_recaptcha');
- }
-
- public function google_map(Request $request) {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.google_configuration.google_map');
- }
-
- public function google_firebase(Request $request) {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.google_configuration.google_firebase');
- }
- public function facebook_chat(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.facebook_chat');
- }
- public function facebook_comment(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.facebook_configuration.facebook_comment');
- }
- public function payment_method(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.payment_method');
- }
- public function file_system(Request $request)
- {
- CoreComponentRepository::instantiateShopRepository();
- CoreComponentRepository::initializeCache();
- return view('backend.setup_configurations.file_system');
- }
- /**
- * Update the API key's for payment methods.
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function payment_method_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', $request->payment_method.'_sandbox')->first();
- if($business_settings != null){
- if ($request->has($request->payment_method.'_sandbox')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- /**
- * Update the API key's for GOOGLE analytics.
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function google_analytics_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'google_analytics')->first();
- if ($request->has('google_analytics')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- public function google_recaptcha_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'google_recaptcha')->first();
- if ($request->has('google_recaptcha')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- public function google_map_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'google_map')->first();
- if ($request->has('google_map')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- public function google_firebase_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'google_firebase')->first();
- if ($request->has('google_firebase')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- /**
- * Update the API key's for GOOGLE analytics.
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function facebook_chat_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'facebook_chat')->first();
- if ($request->has('facebook_chat')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- public function facebook_comment_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'facebook_comment')->first();
- if(!$business_settings) {
- $business_settings = new BusinessSetting;
- $business_settings->type = 'facebook_comment';
- }
- $business_settings->value = 0;
- if ($request->facebook_comment) {
- $business_settings->value = 1;
- }
- $business_settings->save();
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- public function facebook_pixel_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- $business_settings = BusinessSetting::where('type', 'facebook_pixel')->first();
- if ($request->has('facebook_pixel')) {
- $business_settings->value = 1;
- $business_settings->save();
- }
- else{
- $business_settings->value = 0;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- /**
- * Update the API key's for other methods.
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function env_key_update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- $this->overWriteEnvFile($type, $request[$type]);
- }
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- /**
- * overWrite the Env File values.
- * @param String type
- * @param String value
- * @return \Illuminate\Http\Response
- */
- public function overWriteEnvFile($type, $val)
- {
- if(env('DEMO_MODE') != 'On'){
- $path = base_path('.env');
- if (file_exists($path)) {
- $val = '"'.trim($val).'"';
- if(is_numeric(strpos(file_get_contents($path), $type)) && strpos(file_get_contents($path), $type) >= 0){
- file_put_contents($path, str_replace(
- $type.'="'.env($type).'"', $type.'='.$val, file_get_contents($path)
- ));
- }
- else{
- file_put_contents($path, file_get_contents($path)."\r\n".$type.'='.$val);
- }
- }
- }
- }
- public function seller_verification_form(Request $request)
- {
- return view('backend.sellers.seller_verification_form.index');
- }
- /**
- * Update sell verification form.
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function seller_verification_form_update(Request $request)
- {
- $form = array();
- $select_types = ['select', 'multi_select', 'radio'];
- $j = 0;
- for ($i=0; $i < count($request->type); $i++) {
- $item['type'] = $request->type[$i];
- $item['label'] = $request->label[$i];
- if(in_array($request->type[$i], $select_types)){
- $item['options'] = json_encode($request['options_'.$request->option[$j]]);
- $j++;
- }
- array_push($form, $item);
- }
- $business_settings = BusinessSetting::where('type', 'verification_form')->first();
- $business_settings->value = json_encode($form);
- if($business_settings->save()){
- Artisan::call('cache:clear');
-
- flash(translate("Verification form updated successfully"))->success();
- return back();
- }
- }
- public function update(Request $request)
- {
- foreach ($request->types as $key => $type) {
- if($type == 'site_name'){
- $this->overWriteEnvFile('APP_NAME', $request[$type]);
- }
- if($type == 'timezone'){
- $this->overWriteEnvFile('APP_TIMEZONE', $request[$type]);
- }
- else {
- $lang = null;
- if(gettype($type) == 'array'){
- $lang = array_key_first($type);
- $type = $type[$lang];
- $business_settings = BusinessSetting::where('type', $type)->where('lang',$lang)->first();
- }else{
- $business_settings = BusinessSetting::where('type', $type)->first();
- }
- if($business_settings!=null){
- if(gettype($request[$type]) == 'array'){
- $business_settings->value = json_encode($request[$type]);
- }
- else {
- $business_settings->value = $request[$type];
- }
- $business_settings->lang = $lang;
- $business_settings->save();
- }
- else{
- $business_settings = new BusinessSetting;
- $business_settings->type = $type;
- if(gettype($request[$type]) == 'array'){
- $business_settings->value = json_encode($request[$type]);
- }
- else {
- $business_settings->value = $request[$type];
- }
- $business_settings->lang = $lang;
- $business_settings->save();
- }
- }
- }
- Artisan::call('cache:clear');
- flash(translate("Settings updated successfully"))->success();
- return back();
- }
- public function updateActivationSettings(Request $request)
- {
- $env_changes = ['FORCE_HTTPS', 'FILESYSTEM_DRIVER'];
- if (in_array($request->type, $env_changes)) {
- return $this->updateActivationSettingsInEnv($request);
- }
- $business_settings = BusinessSetting::where('type', $request->type)->first();
- if($business_settings!=null){
- if ($request->type == 'maintenance_mode' && $request->value == '1') {
- if(env('DEMO_MODE') != 'On'){
- Artisan::call('down');
- }
- }
- elseif ($request->type == 'maintenance_mode' && $request->value == '0') {
- if(env('DEMO_MODE') != 'On') {
- Artisan::call('up');
- }
- }
- $business_settings->value = $request->value;
- $business_settings->save();
- }
- else{
- $business_settings = new BusinessSetting;
- $business_settings->type = $request->type;
- $business_settings->value = $request->value;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- return '1';
- }
- public function updateActivationSettingsInEnv($request)
- {
- if ($request->type == 'FORCE_HTTPS' && $request->value == '1') {
- $this->overWriteEnvFile($request->type, 'On');
- if(strpos(env('APP_URL'), 'http:') !== FALSE) {
- $this->overWriteEnvFile('APP_URL', str_replace("http:", "https:", env('APP_URL')));
- }
- }
- elseif ($request->type == 'FORCE_HTTPS' && $request->value == '0') {
- $this->overWriteEnvFile($request->type, 'Off');
- if(strpos(env('APP_URL'), 'https:') !== FALSE) {
- $this->overWriteEnvFile('APP_URL', str_replace("https:", "http:", env('APP_URL')));
- }
- }
- elseif ($request->type == 'FILESYSTEM_DRIVER' && $request->value == '1') {
- $this->overWriteEnvFile($request->type, 's3');
- }
- elseif ($request->type == 'FILESYSTEM_DRIVER' && $request->value == '0') {
- $this->overWriteEnvFile($request->type, 'local');
- }
- return '1';
- }
- public function vendor_commission(Request $request)
- {
- return view('backend.sellers.seller_commission.index');
- }
- public function vendor_commission_update(Request $request){
- foreach ($request->types as $key => $type) {
- $business_settings = BusinessSetting::where('type', $type)->first();
- if($business_settings!=null){
- $business_settings->value = $request[$type];
- $business_settings->save();
- }
- else{
- $business_settings = new BusinessSetting;
- $business_settings->type = $type;
- $business_settings->value = $request[$type];
- $business_settings->save();
- }
- }
- Artisan::call('cache:clear');
- flash(translate('Seller Commission updated successfully'))->success();
- return back();
- }
- public function shipping_configuration(Request $request){
- return view('backend.setup_configurations.shipping_configuration.index');
- }
- public function shipping_configuration_update(Request $request){
- $business_settings = BusinessSetting::where('type', $request->type)->first();
- $business_settings->value = $request[$request->type];
- $business_settings->save();
- Artisan::call('cache:clear');
- return back();
- }
- public function order_configuration(){
- return view('backend.setup_configurations.order_configuration.index');
- }
- }
|