Add all files
This commit is contained in:
31
app/Livewire/Components/Cart.php
Normal file
31
app/Livewire/Components/Cart.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Components;
|
||||
|
||||
use App\Classes\Cart as ClassesCart;
|
||||
use App\Livewire\Component;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
class Cart extends Component
|
||||
{
|
||||
public $cartCount;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->cartCount = ClassesCart::get()->count();
|
||||
if (ClassesCart::get()->isEmpty()) {
|
||||
$this->skipRender();
|
||||
}
|
||||
}
|
||||
|
||||
#[On('cartUpdated')]
|
||||
public function onCartUpdated()
|
||||
{
|
||||
$this->cartCount = ClassesCart::get()->count();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('components.cart');
|
||||
}
|
||||
}
|
||||
44
app/Livewire/Components/CurrencySwitch.php
Normal file
44
app/Livewire/Components/CurrencySwitch.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Components;
|
||||
|
||||
use App\Classes\Cart;
|
||||
use App\Livewire\Component;
|
||||
use App\Models\Currency;
|
||||
|
||||
class CurrencySwitch extends Component
|
||||
{
|
||||
public $currentCurrency;
|
||||
|
||||
protected $currencies = [];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->currentCurrency = session('currency', config('settings.default_currency'));
|
||||
$this->currencies = Currency::all()->map(fn ($currency) => [
|
||||
'value' => $currency->code,
|
||||
'label' => $currency->code,
|
||||
])->values()->toArray();
|
||||
if (Cart::get()->isNotEmpty() || count($this->currencies) <= 1) {
|
||||
$this->skipRender();
|
||||
}
|
||||
}
|
||||
|
||||
public function updatedCurrentCurrency($currency)
|
||||
{
|
||||
if (Cart::get()->isNotEmpty()) {
|
||||
$this->notify('You cannot change the currency while there are items in the cart.', 'error');
|
||||
$this->currentCurrency = session('currency', config('settings.default_currency'));
|
||||
|
||||
return;
|
||||
}
|
||||
session(['currency' => $currency]);
|
||||
|
||||
return $this->redirect(request()->header('Referer', '/'), navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('components.currency-switch');
|
||||
}
|
||||
}
|
||||
34
app/Livewire/Components/LanguageSwitch.php
Normal file
34
app/Livewire/Components/LanguageSwitch.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Components;
|
||||
|
||||
use App\Livewire\Component;
|
||||
|
||||
class LanguageSwitch extends Component
|
||||
{
|
||||
public $currentLocale;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->currentLocale = session('locale', config('app.locale'));
|
||||
}
|
||||
|
||||
public function updatedCurrentLocale($locale)
|
||||
{
|
||||
if (!array_key_exists($locale, config('app.available_locales', []))) {
|
||||
return;
|
||||
}
|
||||
|
||||
session(['locale' => $locale]);
|
||||
app()->setLocale($locale);
|
||||
|
||||
return $this->redirect(request()->header('Referer', '/'), navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$locales = config('app.available_locales');
|
||||
|
||||
return view('components.language-switch', compact('locales'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user