Files
wticreatorstudio/Modules/WTIALaCarte/Services/AugmentationService.php
T
2024-02-12 22:54:20 -05:00

213 lines
11 KiB
PHP

<?php
namespace Modules\WTIALaCarte\Services;
class AugmentationService
{
public function __construct()
{
$this->addOrdersTabToProfile();
//$this->addOrdersTabToCustomerDetails();
$this->updateVericyCsrftoken();
$this->addCartToHeader();
$this->addCartToSubMenu();
}
public function addCartToHeader()
{
$path = resource_path('/views/frontend/amazy/partials/_header.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@include\('wtialacarte::components\.cart_mobile'\)/", $content)) {
$matches = null;
preg_match('/<a class="position-relative" href[.\s\S]+?\/cart[.\s\S]+?>[.\s\S]+?<\/a>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('WTIALaCarte'))
@include('wtialacarte::components.cart_mobile')
@else
<a class=\"position-relative\" href=\"{{url('/cart')}}\">
<div class=\"cart_singleIcon cart_singleIcon_cart d-flex align-items-center justify-content-center position-relative\">
<i class=\"ti-shopping-cart\"></i>
<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"
viewBox=\"0 0 127.3 144.29\" style=\"enable-background:new 0 0 127.3 144.29;\" xml:space=\"preserve\">
<g>
<path class=\"st0\" d=\"M63.65,143.29c-1.36,0-2.7-0.36-3.88-1.04l-54.9-31.7C2.49,109.18,1,106.6,1,103.84V40.45
c0-2.76,1.48-5.33,3.88-6.71l54.9-31.7C60.95,1.36,62.29,1,63.65,1c1.36,0,2.7,0.36,3.88,1.04l54.9,31.7
c2.39,1.38,3.88,3.95,3.88,6.71v63.39c0,2.76-1.49,5.33-3.88,6.71l-54.9,31.7C66.35,142.93,65.01,143.29,63.65,143.29z\" fill=\"#fff\"/>
<path class=\"st1\" d=\"M63.65,2c1.18,0,2.35,0.31,3.38,0.9l54.9,31.7c2.08,1.2,3.38,3.44,3.38,5.85v63.39c0,2.4-1.29,4.64-3.38,5.85
l-54.9,31.7c-1.02,0.59-2.19,0.9-3.38,0.9c-1.18,0-2.35-0.31-3.38-0.9l-54.9-31.7c-2.08-1.2-3.38-3.44-3.38-5.85V40.45
c0-2.4,1.29-4.64,3.38-5.85l54.9-31.7C61.3,2.31,62.47,2,63.65,2 M63.65,0c-1.51,0-3.02,0.39-4.38,1.17l-54.9,31.7
C1.67,34.43,0,37.32,0,40.45v63.39c0,3.13,1.67,6.02,4.38,7.58l54.9,31.7c1.35,0.78,2.86,1.17,4.38,1.17
c1.51,0,3.02-0.39,4.38-1.17l54.9-31.7c2.71-1.56,4.38-4.45,4.38-7.58V40.45c0-3.13-1.67-6.02-4.38-7.58l-54.9-31.7
C66.67,0.39,65.16,0,63.65,0L63.65,0z\" fill=\"currentColor\"/>
</g>
</svg>
</div>
<span>{{__('common.cart')}} (<span class=\"cart_count_bottom\">{{getNumberTranslate(\$items)}}</span>)</span>
</a>
@endif
";
$code = $snippet;
$content = preg_replace('/<a class="position-relative" href[.\s\S]+?\/cart[.\s\S]+?>[.\s\S]+?<\/a>/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function addCartToSubMenu()
{
$path = resource_path('/views/frontend/amazy/partials/_submenu.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@include\('wtialacarte::components\.cart_web'\)/", $content)) {
$matches = null;
preg_match('/<a href\=\"\{\{ url\(\'\/cart[.\s\S]+?>[.\s\S]+?<\/a>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('WTIALaCarte'))
@include('wtialacarte::components.cart_web')
@else
<a href=\"{{ url('/cart') }}\" class=\"single_top_lists d-flex align-items-center d-none d-md-inline-flex\">
{{-- <img src=\"{{showImage('frontend/amazy/img/amaz_icon/cart.svg')}}\" alt=\"\"> --}}
<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"12\" height=\"12\" xmlns:v=\"https://vecta.io/nano\"><g fill=\"rgb(81.960784%,25.882353%,25.882353%)\"><path d=\"M2.266 3.336c-.18 0-.344-.125-.383-.309l-.074-.332a.95.95 0 0 0-.926-.746H.484c-.215 0-.391-.176-.391-.395S.27 1.16.484 1.16h.398c.809 0 1.523.574 1.695 1.367l.074.332c.047.211-.086.422-.301.469a.57.57 0 0 1-.086.008zm6.297 6.43v-.051a1.3 1.3 0 0 1 .223-.734H5.707a1.3 1.3 0 0 1 .223.734c0 .016 0 .035-.004.051zm-5.258-.051a1.3 1.3 0 0 1 .227-.738.36.36 0 0 1-.328-.359c0-.199.16-.363.359-.363.219 0 .395-.176.395-.395a.39.39 0 0 0-.395-.391 1.15 1.15 0 0 0-1.148 1.148c0 .547.383 1.004.891 1.121v-.023zm0 0\"/><path d=\"M10.16 8.254H3.348a.4.4 0 0 1-.387-.309L1.883 3.027c-.023-.117.004-.238.078-.332s.188-.148.309-.148h9.246c.109 0 .219.051.293.133s.109.195.098.305l-.453 4.109a1.3 1.3 0 0 1-1.293 1.16zm-6.496-.785h6.496c.262 0 .484-.199.512-.461l.402-3.672H2.758zm0 0\"/><path d=\"M7.16 8.254c-.219 0-.395-.176-.395-.395V2.941c0-.215.176-.395.395-.395s.395.18.395.395v4.918c0 .219-.176.395-.395.395zm1.891 0h-.035c-.215-.02-.375-.207-.359-.426l.406-4.918a.39.39 0 0 1 .426-.359c.219.02.375.207.359.426l-.406 4.918a.39.39 0 0 1-.391.359zm-3.781 0c-.195 0-.367-.148-.391-.352L4.34 2.984c-.023-.215.133-.41.348-.434a.4.4 0 0 1 .438.348l.539 4.918c.023.219-.133.414-.348.438H5.27zm0 0\"/><path d=\"M11.246 5.797H2.809c-.219 0-.395-.176-.395-.395s.176-.395.395-.395h8.438c.215 0 .391.176.391.395s-.176.395-.391.395zm0 0\"/></g><path d=\"M5.535 9.711a.92.92 0 0 1-.918.922.92.92 0 0 1 0-1.84.92.92 0 0 1 .918.918zm5.258 0c0 .508-.414.922-.922.922a.92.92 0 0 1 0-1.84c.508 0 .922.414.922.918zm0 0\" fill=\"rgb(62.745098%,20%,20%)\"/></svg>
<span>{{ __('common.cart') }} (<span class=\"cart_count_bottom\">{{getNumberTranslate(\$items)}}</span>)</span>
</a>
@endif
";
$code = $snippet;
$content = preg_replace('/<a href\=\"\{\{ url\(\'\/cart[.\s\S]+?>[.\s\S]+?<\/a>/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function addOrdersTabToProfile()
{
$path = resource_path('/views/frontend/amazy/pages/profile/profile.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@include\('wtialacarte::components\.orders_tab'\)/", $content)) {
$matches = null;
preg_match('/<li[.\s\S]+?Language\"[.\s\S]+?<\/li>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('WTIALaCarte'))
@include('wtialacarte::components.orders_tab')
@endif
";
$code = $code.$snippet;
$content = preg_replace('/<li[.\s\S]+?Language\"[.\s\S]+?<\/li>/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
}
if (!preg_match("/@include\('wtialacarte::components\.orders_tab_content'\)/", $content)) {
$matches = null;
preg_match('/<div class\=\"tab-pane fade[.\s\S]+?Language\"[.\s\S]+?<\/form>[.\s\S]+?<\/div>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('WTIALaCarte'))
@include('wtialacarte::components.orders_tab_content')
@endif
";
$code = $code.$snippet;
$content = preg_replace('/<div class\=\"tab-pane fade[.\s\S]+?Language\"[.\s\S]+?<\/form>[.\s\S]+?<\/div>/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function addOrdersTabToCustomerDetails()
{
$path = module_path('Customer', 'Resources/views/customers/show_details.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@include\('wtialacarte::components\.customer_orders_tab_content'\)/", $content)) {
$matches = null;
preg_match('/<li[.\s\S]+?Language\"[.\s\S]+?<\/li>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('WTIALaCarte'))
@include('wtialacarte::components.customer_orders_tab_content')
@endif
";
$code .= $snippet;
$content = preg_replace('/<li[.\s\S]+?Language\"[.\s\S]+?<\/li>/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function updateVericyCsrftoken() {
$path = app_path('Http/Middleware/VerifyCsrfToken.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/a-la-carte\/webhooks\/stripe/", $content)) {
$matches = null;
preg_match("/\'search\'\,/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "'search',\n\t\t'/a-la-carte/webhooks/stripe',";
$code = $snippet;
$content = preg_replace("/\'search\'\,/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
}