| 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 |
'company_name' => 'getCompanyName', |
| 31 |
'legal_registration_id' => 'getLegalRegistrationId', |
| 32 |
'seller_vat_id' => 'getSellerVatId', |
| 33 |
'seller_tax_id' => 'getSellerTaxId', |
| 34 |
]; |
| 35 |
|
| 36 |
public function parse($accessor = null, $code = null): ?string |
| 37 |
{ |
| 38 |
return $this->get($accessor, $code); |
| 39 |
} |
| 40 |
|
| 41 |
public function getStoreLogoLink(): ?string |
| 42 |
{ |
| 43 |
return $this->storeSettings->get('store_logo.url'); |
| 44 |
} |
| 45 |
|
| 46 |
public function getStoreLogo(): ?string |
| 47 |
{ |
| 48 |
$storeLogo = $this->storeSettings->get('store_logo.url'); |
| 49 |
if(empty($storeLogo)){ |
| 50 |
return ''; |
| 51 |
} |
| 52 |
$storeName = $this->getStoreName(); |
| 53 |
return "<img style='max-height: 50px' src='{$storeLogo}' alt='{$storeName}'>"; |
| 54 |
} |
| 55 |
|
| 56 |
public function getStoreName(): ?string |
| 57 |
{ |
| 58 |
return $this->storeSettings->get('store_name'); |
| 59 |
} |
| 60 |
|
| 61 |
public function getStoreBrandHtml(): ?string |
| 62 |
{ |
| 63 |
$storeLogoLink = $this->getStoreLogoLink(); |
| 64 |
$storeName = $this->getStoreName(); |
| 65 |
|
| 66 |
if (!$storeLogoLink) { |
| 67 |
return $storeName; |
| 68 |
} |
| 69 |
|
| 70 |
return $this->getStoreLogo(); |
| 71 |
} |
| 72 |
|
| 73 |
public function getStoreAddress() |
| 74 |
{ |
| 75 |
return $this->storeSettings->get('store_address1'); |
| 76 |
} |
| 77 |
|
| 78 |
public function getStoreAddressLine2() |
| 79 |
{ |
| 80 |
return $this->storeSettings->get('store_address2'); |
| 81 |
} |
| 82 |
|
| 83 |
public function getStoreCountry() |
| 84 |
{ |
| 85 |
$country = $this->storeSettings->get('store_country'); |
| 86 |
return AddressHelper::getCountryNameByCode($country); |
| 87 |
} |
| 88 |
|
| 89 |
public function getStoreState() |
| 90 |
{ |
| 91 |
$state = $this->storeSettings->get('store_state'); |
| 92 |
$country = $this->storeSettings->get('store_country'); |
| 93 |
return AddressHelper::getStateNameByCode($state,$country); |
| 94 |
} |
| 95 |
|
| 96 |
public function getStoreCity() |
| 97 |
{ |
| 98 |
return $this->storeSettings->get('store_city'); |
| 99 |
} |
| 100 |
|
| 101 |
public function getStorePostcode() |
| 102 |
{ |
| 103 |
return $this->storeSettings->get('store_postcode'); |
| 104 |
} |
| 105 |
|
| 106 |
public function getCompanyName(): ?string |
| 107 |
{ |
| 108 |
return $this->storeSettings->get('company_name'); |
| 109 |
} |
| 110 |
|
| 111 |
public function getLegalRegistrationId(): ?string |
| 112 |
{ |
| 113 |
return $this->storeSettings->get('legal_registration_id'); |
| 114 |
} |
| 115 |
|
| 116 |
public function getSellerVatId(): ?string |
| 117 |
{ |
| 118 |
return $this->storeSettings->get('seller_vat_id'); |
| 119 |
} |
| 120 |
|
| 121 |
public function getSellerTaxId(): ?string |
| 122 |
{ |
| 123 |
return $this->storeSettings->get('seller_tax_id'); |
| 124 |
} |
| 125 |
} |
| 126 |
|