BusinessSettingsController.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\BusinessSetting;
  5. use Artisan;
  6. use CoreComponentRepository;
  7. class BusinessSettingsController extends Controller
  8. {
  9. public function general_setting(Request $request)
  10. {
  11. CoreComponentRepository::instantiateShopRepository();
  12. CoreComponentRepository::initializeCache();
  13. return view('backend.setup_configurations.general_settings');
  14. }
  15. public function update2(Request $request)
  16. {
  17. foreach ($request->types as $key => $type) {
  18. if($type == 'site_name'){
  19. $this->overWriteEnvFile('APP_NAME', $request[$type]);
  20. }
  21. if($type == 'timezone'){
  22. $this->overWriteEnvFile('APP_TIMEZONE', $request[$type]);
  23. }
  24. else {
  25. $lang = null;
  26. if(gettype($type) == 'array'){
  27. $lang = array_key_first($type);
  28. $type = $type[$lang];
  29. $business_settings = BusinessSetting::where('type', $type)->where('lang',$lang)->first();
  30. }else{
  31. $business_settings = BusinessSetting::where('type', $type)->first();
  32. }
  33. if($business_settings!=null){
  34. if(gettype($request[$type]) == 'array'){
  35. $business_settings->value = json_encode($request[$type]);
  36. }
  37. else {
  38. $business_settings->value = $request[$type];
  39. }
  40. $business_settings->lang = $lang;
  41. $business_settings->save();
  42. }
  43. else{
  44. $business_settings = new BusinessSetting;
  45. $business_settings->type = $type;
  46. if(gettype($request[$type]) == 'array'){
  47. $business_settings->value = json_encode($request[$type]);
  48. }
  49. else {
  50. $business_settings->value = $request[$type];
  51. }
  52. $business_settings->lang = $lang;
  53. $business_settings->save();
  54. }
  55. }
  56. }
  57. Artisan::call('cache:clear');
  58. flash(translate("Settings updated successfully"))->success();
  59. return back();
  60. }
  61. public function activation(Request $request)
  62. {
  63. CoreComponentRepository::instantiateShopRepository();
  64. CoreComponentRepository::initializeCache();
  65. return view('backend.setup_configurations.activation');
  66. }
  67. public function social_login(Request $request)
  68. {
  69. CoreComponentRepository::instantiateShopRepository();
  70. CoreComponentRepository::initializeCache();
  71. return view('backend.setup_configurations.social_login');
  72. }
  73. public function smtp_settings(Request $request)
  74. {
  75. CoreComponentRepository::instantiateShopRepository();
  76. CoreComponentRepository::initializeCache();
  77. return view('backend.setup_configurations.smtp_settings');
  78. }
  79. public function google_analytics(Request $request)
  80. {
  81. CoreComponentRepository::instantiateShopRepository();
  82. CoreComponentRepository::initializeCache();
  83. return view('backend.setup_configurations.google_configuration.google_analytics');
  84. }
  85. public function google_recaptcha(Request $request)
  86. {
  87. CoreComponentRepository::instantiateShopRepository();
  88. CoreComponentRepository::initializeCache();
  89. return view('backend.setup_configurations.google_configuration.google_recaptcha');
  90. }
  91. public function google_map(Request $request) {
  92. CoreComponentRepository::instantiateShopRepository();
  93. CoreComponentRepository::initializeCache();
  94. return view('backend.setup_configurations.google_configuration.google_map');
  95. }
  96. public function google_firebase(Request $request) {
  97. CoreComponentRepository::instantiateShopRepository();
  98. CoreComponentRepository::initializeCache();
  99. return view('backend.setup_configurations.google_configuration.google_firebase');
  100. }
  101. public function facebook_chat(Request $request)
  102. {
  103. CoreComponentRepository::instantiateShopRepository();
  104. CoreComponentRepository::initializeCache();
  105. return view('backend.setup_configurations.facebook_chat');
  106. }
  107. public function facebook_comment(Request $request)
  108. {
  109. CoreComponentRepository::instantiateShopRepository();
  110. CoreComponentRepository::initializeCache();
  111. return view('backend.setup_configurations.facebook_configuration.facebook_comment');
  112. }
  113. public function payment_method(Request $request)
  114. {
  115. CoreComponentRepository::instantiateShopRepository();
  116. CoreComponentRepository::initializeCache();
  117. return view('backend.setup_configurations.payment_method');
  118. }
  119. public function file_system(Request $request)
  120. {
  121. CoreComponentRepository::instantiateShopRepository();
  122. CoreComponentRepository::initializeCache();
  123. return view('backend.setup_configurations.file_system');
  124. }
  125. /**
  126. * Update the API key's for payment methods.
  127. * @param \Illuminate\Http\Request $request
  128. * @return \Illuminate\Http\Response
  129. */
  130. public function payment_method_update(Request $request)
  131. {
  132. foreach ($request->types as $key => $type) {
  133. $this->overWriteEnvFile($type, $request[$type]);
  134. }
  135. $business_settings = BusinessSetting::where('type', $request->payment_method.'_sandbox')->first();
  136. if($business_settings != null){
  137. if ($request->has($request->payment_method.'_sandbox')) {
  138. $business_settings->value = 1;
  139. $business_settings->save();
  140. }
  141. else{
  142. $business_settings->value = 0;
  143. $business_settings->save();
  144. }
  145. }
  146. Artisan::call('cache:clear');
  147. flash(translate("Settings updated successfully"))->success();
  148. return back();
  149. }
  150. /**
  151. * Update the API key's for GOOGLE analytics.
  152. * @param \Illuminate\Http\Request $request
  153. * @return \Illuminate\Http\Response
  154. */
  155. public function google_analytics_update(Request $request)
  156. {
  157. foreach ($request->types as $key => $type) {
  158. $this->overWriteEnvFile($type, $request[$type]);
  159. }
  160. $business_settings = BusinessSetting::where('type', 'google_analytics')->first();
  161. if ($request->has('google_analytics')) {
  162. $business_settings->value = 1;
  163. $business_settings->save();
  164. }
  165. else{
  166. $business_settings->value = 0;
  167. $business_settings->save();
  168. }
  169. Artisan::call('cache:clear');
  170. flash(translate("Settings updated successfully"))->success();
  171. return back();
  172. }
  173. public function google_recaptcha_update(Request $request)
  174. {
  175. foreach ($request->types as $key => $type) {
  176. $this->overWriteEnvFile($type, $request[$type]);
  177. }
  178. $business_settings = BusinessSetting::where('type', 'google_recaptcha')->first();
  179. if ($request->has('google_recaptcha')) {
  180. $business_settings->value = 1;
  181. $business_settings->save();
  182. }
  183. else{
  184. $business_settings->value = 0;
  185. $business_settings->save();
  186. }
  187. Artisan::call('cache:clear');
  188. flash(translate("Settings updated successfully"))->success();
  189. return back();
  190. }
  191. public function google_map_update(Request $request)
  192. {
  193. foreach ($request->types as $key => $type) {
  194. $this->overWriteEnvFile($type, $request[$type]);
  195. }
  196. $business_settings = BusinessSetting::where('type', 'google_map')->first();
  197. if ($request->has('google_map')) {
  198. $business_settings->value = 1;
  199. $business_settings->save();
  200. }
  201. else{
  202. $business_settings->value = 0;
  203. $business_settings->save();
  204. }
  205. Artisan::call('cache:clear');
  206. flash(translate("Settings updated successfully"))->success();
  207. return back();
  208. }
  209. public function google_firebase_update(Request $request)
  210. {
  211. foreach ($request->types as $key => $type) {
  212. $this->overWriteEnvFile($type, $request[$type]);
  213. }
  214. $business_settings = BusinessSetting::where('type', 'google_firebase')->first();
  215. if ($request->has('google_firebase')) {
  216. $business_settings->value = 1;
  217. $business_settings->save();
  218. }
  219. else{
  220. $business_settings->value = 0;
  221. $business_settings->save();
  222. }
  223. Artisan::call('cache:clear');
  224. flash(translate("Settings updated successfully"))->success();
  225. return back();
  226. }
  227. /**
  228. * Update the API key's for GOOGLE analytics.
  229. * @param \Illuminate\Http\Request $request
  230. * @return \Illuminate\Http\Response
  231. */
  232. public function facebook_chat_update(Request $request)
  233. {
  234. foreach ($request->types as $key => $type) {
  235. $this->overWriteEnvFile($type, $request[$type]);
  236. }
  237. $business_settings = BusinessSetting::where('type', 'facebook_chat')->first();
  238. if ($request->has('facebook_chat')) {
  239. $business_settings->value = 1;
  240. $business_settings->save();
  241. }
  242. else{
  243. $business_settings->value = 0;
  244. $business_settings->save();
  245. }
  246. Artisan::call('cache:clear');
  247. flash(translate("Settings updated successfully"))->success();
  248. return back();
  249. }
  250. public function facebook_comment_update(Request $request)
  251. {
  252. foreach ($request->types as $key => $type) {
  253. $this->overWriteEnvFile($type, $request[$type]);
  254. }
  255. $business_settings = BusinessSetting::where('type', 'facebook_comment')->first();
  256. if(!$business_settings) {
  257. $business_settings = new BusinessSetting;
  258. $business_settings->type = 'facebook_comment';
  259. }
  260. $business_settings->value = 0;
  261. if ($request->facebook_comment) {
  262. $business_settings->value = 1;
  263. }
  264. $business_settings->save();
  265. Artisan::call('cache:clear');
  266. flash(translate("Settings updated successfully"))->success();
  267. return back();
  268. }
  269. public function facebook_pixel_update(Request $request)
  270. {
  271. foreach ($request->types as $key => $type) {
  272. $this->overWriteEnvFile($type, $request[$type]);
  273. }
  274. $business_settings = BusinessSetting::where('type', 'facebook_pixel')->first();
  275. if ($request->has('facebook_pixel')) {
  276. $business_settings->value = 1;
  277. $business_settings->save();
  278. }
  279. else{
  280. $business_settings->value = 0;
  281. $business_settings->save();
  282. }
  283. Artisan::call('cache:clear');
  284. flash(translate("Settings updated successfully"))->success();
  285. return back();
  286. }
  287. /**
  288. * Update the API key's for other methods.
  289. * @param \Illuminate\Http\Request $request
  290. * @return \Illuminate\Http\Response
  291. */
  292. public function env_key_update(Request $request)
  293. {
  294. foreach ($request->types as $key => $type) {
  295. $this->overWriteEnvFile($type, $request[$type]);
  296. }
  297. flash(translate("Settings updated successfully"))->success();
  298. return back();
  299. }
  300. /**
  301. * overWrite the Env File values.
  302. * @param String type
  303. * @param String value
  304. * @return \Illuminate\Http\Response
  305. */
  306. public function overWriteEnvFile($type, $val)
  307. {
  308. if(env('DEMO_MODE') != 'On'){
  309. $path = base_path('.env');
  310. if (file_exists($path)) {
  311. $val = '"'.trim($val).'"';
  312. if(is_numeric(strpos(file_get_contents($path), $type)) && strpos(file_get_contents($path), $type) >= 0){
  313. file_put_contents($path, str_replace(
  314. $type.'="'.env($type).'"', $type.'='.$val, file_get_contents($path)
  315. ));
  316. }
  317. else{
  318. file_put_contents($path, file_get_contents($path)."\r\n".$type.'='.$val);
  319. }
  320. }
  321. }
  322. }
  323. public function seller_verification_form(Request $request)
  324. {
  325. return view('backend.sellers.seller_verification_form.index');
  326. }
  327. /**
  328. * Update sell verification form.
  329. * @param \Illuminate\Http\Request $request
  330. * @return \Illuminate\Http\Response
  331. */
  332. public function seller_verification_form_update(Request $request)
  333. {
  334. $form = array();
  335. $select_types = ['select', 'multi_select', 'radio'];
  336. $j = 0;
  337. for ($i=0; $i < count($request->type); $i++) {
  338. $item['type'] = $request->type[$i];
  339. $item['label'] = $request->label[$i];
  340. if(in_array($request->type[$i], $select_types)){
  341. $item['options'] = json_encode($request['options_'.$request->option[$j]]);
  342. $j++;
  343. }
  344. array_push($form, $item);
  345. }
  346. $business_settings = BusinessSetting::where('type', 'verification_form')->first();
  347. $business_settings->value = json_encode($form);
  348. if($business_settings->save()){
  349. Artisan::call('cache:clear');
  350. flash(translate("Verification form updated successfully"))->success();
  351. return back();
  352. }
  353. }
  354. public function update(Request $request)
  355. {
  356. foreach ($request->types as $key => $type) {
  357. if($type == 'site_name'){
  358. $this->overWriteEnvFile('APP_NAME', $request[$type]);
  359. }
  360. if($type == 'timezone'){
  361. $this->overWriteEnvFile('APP_TIMEZONE', $request[$type]);
  362. }
  363. else {
  364. $lang = null;
  365. if(gettype($type) == 'array'){
  366. $lang = array_key_first($type);
  367. $type = $type[$lang];
  368. $business_settings = BusinessSetting::where('type', $type)->where('lang',$lang)->first();
  369. }else{
  370. $business_settings = BusinessSetting::where('type', $type)->first();
  371. }
  372. if($business_settings!=null){
  373. if(gettype($request[$type]) == 'array'){
  374. $business_settings->value = json_encode($request[$type]);
  375. }
  376. else {
  377. $business_settings->value = $request[$type];
  378. }
  379. $business_settings->lang = $lang;
  380. $business_settings->save();
  381. }
  382. else{
  383. $business_settings = new BusinessSetting;
  384. $business_settings->type = $type;
  385. if(gettype($request[$type]) == 'array'){
  386. $business_settings->value = json_encode($request[$type]);
  387. }
  388. else {
  389. $business_settings->value = $request[$type];
  390. }
  391. $business_settings->lang = $lang;
  392. $business_settings->save();
  393. }
  394. }
  395. }
  396. Artisan::call('cache:clear');
  397. flash(translate("Settings updated successfully"))->success();
  398. return back();
  399. }
  400. public function updateActivationSettings(Request $request)
  401. {
  402. $env_changes = ['FORCE_HTTPS', 'FILESYSTEM_DRIVER'];
  403. if (in_array($request->type, $env_changes)) {
  404. return $this->updateActivationSettingsInEnv($request);
  405. }
  406. $business_settings = BusinessSetting::where('type', $request->type)->first();
  407. if($business_settings!=null){
  408. if ($request->type == 'maintenance_mode' && $request->value == '1') {
  409. if(env('DEMO_MODE') != 'On'){
  410. Artisan::call('down');
  411. }
  412. }
  413. elseif ($request->type == 'maintenance_mode' && $request->value == '0') {
  414. if(env('DEMO_MODE') != 'On') {
  415. Artisan::call('up');
  416. }
  417. }
  418. $business_settings->value = $request->value;
  419. $business_settings->save();
  420. }
  421. else{
  422. $business_settings = new BusinessSetting;
  423. $business_settings->type = $request->type;
  424. $business_settings->value = $request->value;
  425. $business_settings->save();
  426. }
  427. Artisan::call('cache:clear');
  428. return '1';
  429. }
  430. public function updateActivationSettingsInEnv($request)
  431. {
  432. if ($request->type == 'FORCE_HTTPS' && $request->value == '1') {
  433. $this->overWriteEnvFile($request->type, 'On');
  434. if(strpos(env('APP_URL'), 'http:') !== FALSE) {
  435. $this->overWriteEnvFile('APP_URL', str_replace("http:", "https:", env('APP_URL')));
  436. }
  437. }
  438. elseif ($request->type == 'FORCE_HTTPS' && $request->value == '0') {
  439. $this->overWriteEnvFile($request->type, 'Off');
  440. if(strpos(env('APP_URL'), 'https:') !== FALSE) {
  441. $this->overWriteEnvFile('APP_URL', str_replace("https:", "http:", env('APP_URL')));
  442. }
  443. }
  444. elseif ($request->type == 'FILESYSTEM_DRIVER' && $request->value == '1') {
  445. $this->overWriteEnvFile($request->type, 's3');
  446. }
  447. elseif ($request->type == 'FILESYSTEM_DRIVER' && $request->value == '0') {
  448. $this->overWriteEnvFile($request->type, 'local');
  449. }
  450. return '1';
  451. }
  452. public function vendor_commission(Request $request)
  453. {
  454. return view('backend.sellers.seller_commission.index');
  455. }
  456. public function vendor_commission_update(Request $request){
  457. foreach ($request->types as $key => $type) {
  458. $business_settings = BusinessSetting::where('type', $type)->first();
  459. if($business_settings!=null){
  460. $business_settings->value = $request[$type];
  461. $business_settings->save();
  462. }
  463. else{
  464. $business_settings = new BusinessSetting;
  465. $business_settings->type = $type;
  466. $business_settings->value = $request[$type];
  467. $business_settings->save();
  468. }
  469. }
  470. Artisan::call('cache:clear');
  471. flash(translate('Seller Commission updated successfully'))->success();
  472. return back();
  473. }
  474. public function shipping_configuration(Request $request){
  475. return view('backend.setup_configurations.shipping_configuration.index');
  476. }
  477. public function shipping_configuration_update(Request $request){
  478. $business_settings = BusinessSetting::where('type', $request->type)->first();
  479. $business_settings->value = $request[$request->type];
  480. $business_settings->save();
  481. Artisan::call('cache:clear');
  482. return back();
  483. }
  484. public function order_configuration(){
  485. return view('backend.setup_configurations.order_configuration.index');
  486. }
  487. }