| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\ShortCodeParser\Parsers; |
| 4 |
|
| 5 |
use FluentCart\Api\StoreSettings; |
| 6 |
use FluentCart\App\Helpers\AddressHelper; |
| 7 |
use FluentCart\App\Services\Localization\LocalizationManager; |
| 8 |
|
| 9 |
class SettingsParser extends BaseParser |
| 10 |
{ |
| 11 |
private StoreSettings $storeSettings; |
| 12 |
|
| 13 |
|
| 14 |
public function __construct($data) |
| 15 |
{ |
| 16 |
$this->storeSettings = new StoreSettings(); |
| 17 |
parent::__construct($data); |
| 18 |
} |
| 19 |
|
| 20 |
protected array $methodMap = [ |
| 21 |
'store_logo' => 'getStoreLogo', |
| 22 |
'store_brand' => 'getStoreBrandHtml', |
| 23 |
'store_name' => 'getStoreName', |
| 24 |
'store_address' => 'getStoreAddress', |
| 25 |
'store_address2' => 'getStoreAddressLine2', |
| 26 |
'store_country' => 'getStoreCountry', |
| 27 |
'store_state' => 'getStoreState', |
| 28 |
'store_city' => 'getStoreCity', |
| 29 |
'store_postcode' => 'getStorePostcode', |
| 30 |
]; |
| 31 |
|
| 32 |
public function parse($accessor = null, $code = null): ?string |
| 33 |
{ |
| 34 |
return $this->get($accessor, $code); |
| 35 |
} |
| 36 |
|
| 37 |
public function getStoreLogoLink(): ?string |
| 38 |
{ |
| 39 |
return $this->storeSettings->get('store_logo.url'); |
| 40 |
} |
| 41 |
|
| 42 |
public function getStoreLogo(): ?string |
| 43 |
{ |
| 44 |
$storeLogo = $this->storeSettings->get('store_logo.url'); |
| 45 |
if(empty($storeLogo)){ |
| 46 |
return ''; |
| 47 |
} |
| 48 |
$storeName = $this->getStoreName(); |
| 49 |
return "<img style='max-height: 50px' src='{$storeLogo}' alt='{$storeName}'>"; |
| 50 |
} |
| 51 |
|
| 52 |
public function getStoreName(): ?string |
| 53 |
{ |
| 54 |
return $this->storeSettings->get('store_name'); |
| 55 |
} |
| 56 |
|
| 57 |
public function getStoreBrandHtml(): ?string |
| 58 |
{ |
| 59 |
$storeLogoLink = $this->getStoreLogoLink(); |
| 60 |
$storeName = $this->getStoreName(); |
| 61 |
|
| 62 |
if (!$storeLogoLink) { |
| 63 |
return $storeName; |
| 64 |
} |
| 65 |
|
| 66 |
return $this->getStoreLogo(); |
| 67 |
} |
| 68 |
|
| 69 |
public function getStoreAddress() |
| 70 |
{ |
| 71 |
return $this->storeSettings->get('store_address1'); |
| 72 |
} |
| 73 |
|
| 74 |
public function getStoreAddressLine2() |
| 75 |
{ |
| 76 |
return $this->storeSettings->get('store_address2'); |
| 77 |
} |
| 78 |
|
| 79 |
public function getStoreCountry() |
| 80 |
{ |
| 81 |
$country = $this->storeSettings->get('store_country'); |
| 82 |
return AddressHelper::getCountryNameByCode($country); |
| 83 |
} |
| 84 |
|
| 85 |
public function getStoreState() |
| 86 |
{ |
| 87 |
$state = $this->storeSettings->get('store_state'); |
| 88 |
$country = $this->storeSettings->get('store_country'); |
| 89 |
return AddressHelper::getStateNameByCode($state,$country); |
| 90 |
} |
| 91 |
|
| 92 |
public function getStoreCity() |
| 93 |
{ |
| 94 |
return $this->storeSettings->get('store_city'); |
| 95 |
} |
| 96 |
|
| 97 |
public function getStorePostcode() |
| 98 |
{ |
| 99 |
return $this->storeSettings->get('store_postcode'); |
| 100 |
} |
| 101 |
} |
| 102 |
|