<?php
namespace App\SettingsProvider;
use App\Entity\EcommerceGeneralSettings;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\ItemInterface;
class EcommerceSettingsList
{
public function __construct(private ManagerRegistry $managerRegistry)
{
$this->cache = new FilesystemAdapter;
}
public function getCurrency(): string
{
$item = $this->cache->get('settings.currency', function (ItemInterface $item) {
return $this->settingsDatabase()->getCurrencyType() ?: '';
});
return $item ?: '';
}
public function getCurrencyOnRight(): bool
{
return $this->cache->get('settings.currencyOnRight', function (ItemInterface $item) {
return $this->settingsDatabase()->isCurrencySignOnRight() ?: true;
});
}
public function getShowCurrencySign(): bool
{
return $this->cache->get('settings.currencySign', function (ItemInterface $item) {
return $this->settingsDatabase()->isShowCurrencySign() ?: true;
});
}
public function getCurrencySignType(): string
{
$item = $this->cache->get('settings.currencySignType', function (ItemInterface $item) {
return $this->settingsDatabase()->getCurrencySignType() ?: '';
});
return $item ?: '';
}
public function getProductImagePlaceholder(): string
{
$item = $this->cache->get('settings.productImagePlaceholder', function (ItemInterface $item) {
return $this->settingsDatabase()->getProductImagePlaceholder() ?: '';
});
return $item ?: '';
}
public function getWeightUnitType(): string
{
$item = $this->cache->get('settings.weightUnitType', function (ItemInterface $item) {
return $this->settingsDatabase()->getWeightUnitType() ?: '';
});
return $item ?: '';
}
public function getLengthUnitType(): string
{
$item = $this->cache->get('settings.lengthUnitType', function (ItemInterface $item) {
return $this->settingsDatabase()->getLengthUnitType() ?: '';
});
return $item ?: '';
}
private function settingsDatabase(): EcommerceGeneralSettings
{
return $this->managerRegistry->getRepository(EcommerceGeneralSettings::class)->findOneBy([]);
}
}