docs/api/source-catalog.model.setting.setting.html
| 1: | <?php |
| 2: | namespace Opencart\Catalog\Model\Setting; |
| 3: | /** |
| 4: | * Class Setting |
| 5: | * |
| 6: | * @package Opencart\Catalog\Model\Setting |
| 7: | */ |
| 8: | class Setting extends \Opencart\System\Engine\Model { |
| 9: | /** |
| 10: | * Get Settings |
| 11: | * |
| 12: | * @param int $store_id |
| 13: | * |
| 14: | * @return array<int, array<string, mixed>> |
| 15: | */ |
| 16: | public function getSettings(int $store_id = 0): array { |
| 17: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "setting WHERE store\_id = '" . (int)$store_id . "' OR store_id = 0 ORDER BY store_id ASC"); |
| 18: | |
| 19: | return $query->rows; |
| 20: | } |
| 21: | |
| 22: | /** |
| 23: | * Get Setting |
| 24: | * |
| 25: | * @param string $code |
| 26: | * @param int $store_id |
| 27: | * |
| 28: | * @return array<string, mixed> |
| 29: | */ |
| 30: | public function getSetting(string $code, int $store_id = 0): array { |
| 31: | $setting_data = []; |
| 32: | |
| 33: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "setting WHERE store\_id = '" . (int)$store_id . "' AND code = '" . $this->db->escape($code) . "'"); |
| 34: | |
| 35: | foreach ($query->rows as $result) { |
| 36: | if (!$result['serialized']) { |
| 37: | $setting_data[$result['key']] = $result['value']; |
| 38: | } else { |
| 39: | $setting_data[$result['key']] = json_decode($result['value'], true); |
| 40: | } |
| 41: | } |
| 42: | |
| 43: | return $setting_data; |
| 44: | } |
| 45: | |
| 46: | /** |
| 47: | * Get Value |
| 48: | * |
| 49: | * @param string $key |
| 50: | * @param int $store_id |
| 51: | * |
| 52: | * @return string |
| 53: | */ |
| 54: | public function getValue(string $key, int $store_id = 0): string { |
| 55: | $query = $this->db->query("SELECT value FROM " . DB\_PREFIX . "setting WHERE store\_id = '" . (int)$store_id . "' AND key = '" . $this->db->escape($key) . "'"); |
| 56: | |
| 57: | if ($query->num_rows) { |
| 58: | return $query->row['value']; |
| 59: | } else { |
| 60: | return ''; |
| 61: | } |
| 62: | } |
| 63: | } |
| 64: | |
OpenCart API API documentation generated by ApiGen dev-master