Files
Fritz Ramirez 10d0c477c8 Initial commit
2024-02-12 22:54:20 -05:00

98 lines
4.1 KiB
PHP

<?php
namespace Modules\RegistrationFormSteps\Services;
use File;
class AugmentationService
{
public function __construct() {
$this->copyLangFile();
$this->updateRegisterController();
$this->addCustomerRegisterStepForm();
//$this->updateStripePayment();
}
public static function copyLangFile() {
$langFile = module_path('RegistrationFormSteps', 'Resources/lang/default/member_register.php');
if (file_exists($langFile)) {
File::copy($langFile, resource_path('lang/default/member_register.php'));
}
}
public function updateRegisterController() {
$path = app_path('Http/Controllers/Auth/RegisterController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/isModuleActive\(\'RegistrationFormSteps\'\)/", $content)) {
$matches = null;
preg_match('/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?referral_code[.\s\S]+?}[.\s\S]+?}/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\n\t\tif(isModuleActive('RegistrationFormSteps')){\n\t\t\t\$user->wti_data = json_encode(\$data->only('storefront', 'company_name', 'brand_name', 'accounts_payable_name', 'accounts_payable_email', 'marketing_contact_name', 'marketing_contact_email', 'company_address'));\n\t\t\t\$user->save();\n\t\t}\n\n";
$code .= $snippet;
$content = preg_replace("/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?referral_code[.\s\S]+?}[.\s\S]+?}/", $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public static function addCustomerRegisterStepForm() {
if (isModuleActive('StaffPortal')) {
$path = module_path('StaffPortal', 'Resources/views/register.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/@include\('registrationformsteps::customer\.form'\)/", $content)) {
$matches = null;
preg_match("/@include\('staffportal::components\._customer_register_form'\)/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('RegistrationFormSteps'))
@include('registrationformsteps::customer.form')
@else
@include('staffportal::components._customer_register_form')
@endif
";
$code = $snippet;
$content = preg_replace("/@include\('staffportal::components\._customer_register_form'\)/", $code, $content);
file_put_contents($path, $content);
}
}
}
}
}
public static function updateStripePayment() {
$path = resource_path('views/frontend/amazy/partials/payments/stripe_payment.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/isset\(\$total_amount\)/", $content)) {
$matches = null;
preg_match('/<input type="hidden" name="amount" value="{{\$total_amount - \$coupon_am}}">/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isset(\$total_amount))
<input type=\"hidden\" name=\"amount\" value=\"{{\$total_amount - \$coupon_am}}\">
@else
<input type=\"hidden\" name=\"amount\" id=\"total_amount\">
@endif";
$code = $snippet;
$content = preg_replace('/<input type="hidden" name="amount" value="{{\$total_amount - \$coupon_am}}">/', $code, $content);
file_put_contents($path, $content);
}
}
}
}
}