- changed order pk column to id - refactored and fixed inShop - using php Money for transaction
146 lines
4.6 KiB
PHP
146 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Customer\Customer;
|
|
use App\Models\Shop\DeliveryMode;
|
|
use App\Models\Site\GeneralConfig;
|
|
use App\Models\Shop\PaymentMode;
|
|
use App\Models\Merchandise\Range;
|
|
use App\Models\Merchandise\Tag;
|
|
use Gloudemans\Shoppingcart\Facades\Cart;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Laravel\Cashier\Cashier;
|
|
use Money\Currencies\ISOCurrencies;
|
|
use Money\Formatter\IntlMoneyFormatter;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register(): void
|
|
{
|
|
Cashier::ignoreMigrations();
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// Cashier shall use customers.
|
|
Cashier::useCustomerModel(Customer::class);
|
|
|
|
// * HTTPS FIX
|
|
URL::forceScheme('https');
|
|
|
|
// * HA PROXY FIX
|
|
App::singleton('clientIp', function () {
|
|
if (config('app.env') === 'local') {
|
|
return request()->getClientIp();
|
|
} else {
|
|
return request()->server('HTTP_X_FORWARDED_FOR') ??
|
|
request()->getClientIp();
|
|
}
|
|
});
|
|
|
|
// * LOCAL FORCE eg: for Carbon
|
|
setlocale(LC_ALL, \sprintf(
|
|
'%s_%s.UTF-8',
|
|
config('app.locale'),
|
|
\strtoupper(config('app.locale'))
|
|
));
|
|
Carbon::setLocale(config('app.locale'));
|
|
|
|
// * Php Money formater
|
|
App::singleton('phpMoneyFormatter', function () {
|
|
// * Number format using app locale.
|
|
$currencies = new ISOCurrencies();
|
|
$numberFormatter = new \NumberFormatter(\sprintf(
|
|
'%s_%s',
|
|
config('app.locale'),
|
|
\strtoupper(config('app.locale'))
|
|
), \NumberFormatter::CURRENCY);
|
|
return new IntlMoneyFormatter($numberFormatter, $currencies);
|
|
});
|
|
|
|
// * Basket singleton
|
|
App::singleton('basket', function () {
|
|
return Cart::instance('basket');
|
|
});
|
|
|
|
$this->sharetoView();
|
|
}
|
|
|
|
/**
|
|
* Share Vars to view
|
|
*
|
|
* @return void
|
|
*/
|
|
private function sharetoView()
|
|
{
|
|
// * View shares
|
|
// ! Add view file pathes (also needed for console xml job).
|
|
View::addNamespace('back', resource_path('views'));
|
|
View::addNamespace('theme', resource_path('theme/views'));
|
|
|
|
if (!app()->runningInConsole()) {
|
|
$appInfos = Cache::remember(
|
|
'composer',
|
|
360,
|
|
function () {
|
|
return json_decode(File::get(\app_path('../composer.json')));
|
|
}
|
|
);
|
|
// Share composer.json infos .
|
|
View::share('cpsr_name', $appInfos->name);
|
|
View::share('cpsr_version', $appInfos->version);
|
|
View::share('cpsr_license', $appInfos->license);
|
|
View::share('cpsr_time', now()->parse($appInfos->time)->isoFormat('Y'));
|
|
|
|
try {
|
|
View::share('GeneralConfigGlobal', GeneralConfig::getCachedConfigs());
|
|
} catch (\Exception $e) {
|
|
report($e);
|
|
View::share('GeneralConfigGlobal', collect());
|
|
} //end try
|
|
|
|
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
|
|
// Early boot, request wont be filled as expected.
|
|
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
|
|
Paginator::useBootstrap();
|
|
} else {
|
|
Paginator::defaultview('theme::modules.pagination');
|
|
}
|
|
|
|
// * Payment Modes
|
|
View::share('PaymentModesGlobal', PaymentMode::getCachedPaymentModes());
|
|
\app()->singleton('PaymentModesGlobal', function () {
|
|
return PaymentMode::getCachedPaymentModes();
|
|
});
|
|
// * Delivery Mode
|
|
View::share('DeliveryModesGlobal', DeliveryMode::getCachedDeliveryModes());
|
|
\app()->singleton('DeliveryModesGlobal', function () {
|
|
return DeliveryMode::getCachedDeliveryModes();
|
|
});
|
|
|
|
// * TAGS
|
|
View::share('PublishedTagsGlobal', Tag::getCachedPublishedTags());
|
|
|
|
// * RANGES
|
|
View::share('PublishedRangesGlobal', Range::getCachedPublishedRanges());
|
|
} //end if
|
|
}
|
|
}
|