| 1: | <?php
|
| 2: | namespace Opencart\Catalog\Model\Account;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class CustomField extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function getCustomField(int $custom_field_id): array {
|
| 17: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` `cf` LEFT JOIN `" . DB_PREFIX . "custom_field_description` `cfd` ON (`cf`.`custom_field_id` = `cfd`.`custom_field_id`) WHERE `cf`.`status` = '1' AND `cf`.`custom_field_id` = '" . (int)$custom_field_id . "' AND `cfd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
| 18: |
|
| 19: | return $query->row;
|
| 20: | }
|
| 21: |
|
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: |
|
| 29: | public function getCustomFields(int $customer_group_id = 0): array {
|
| 30: | $custom_field_data = [];
|
| 31: |
|
| 32: | if (!$customer_group_id) {
|
| 33: | $custom_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` `cfd` ON (`cf`.`custom_field_id` = `cfd`.`custom_field_id`) WHERE `cf`.`status` = '1' AND `cfd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `cf`.`sort_order` ASC");
|
| 34: | } else {
|
| 35: | $custom_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` `cfcg` LEFT JOIN `" . DB_PREFIX . "custom_field` `cf` ON (`cfcg`.`custom_field_id` = `cf`.`custom_field_id`) LEFT JOIN `" . DB_PREFIX . "custom_field_description` `cfd` ON (`cf`.`custom_field_id` = `cfd`.`custom_field_id`) WHERE `cf`.`status` = '1' AND `cfd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `cfcg`.`customer_group_id` = '" . (int)$customer_group_id . "' ORDER BY `cf`.`sort_order` ASC");
|
| 36: | }
|
| 37: |
|
| 38: | foreach ($custom_field_query->rows as $custom_field) {
|
| 39: | $custom_field_value_data = [];
|
| 40: |
|
| 41: | if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio' || $custom_field['type'] == 'checkbox') {
|
| 42: | $custom_field_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` `cfv` LEFT JOIN `" . DB_PREFIX . "custom_field_value_description` `cfvd` ON (`cfv`.`custom_field_value_id` = `cfvd`.`custom_field_value_id`) WHERE `cfv`.`custom_field_id` = '" . (int)$custom_field['custom_field_id'] . "' AND `cfvd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `cfv`.`sort_order` ASC");
|
| 43: |
|
| 44: | foreach ($custom_field_value_query->rows as $custom_field_value) {
|
| 45: | $custom_field_value_data[] = [
|
| 46: | 'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
|
| 47: | 'name' => $custom_field_value['name']
|
| 48: | ];
|
| 49: | }
|
| 50: | }
|
| 51: |
|
| 52: | $custom_field_data[] = [
|
| 53: | 'custom_field_id' => $custom_field['custom_field_id'],
|
| 54: | 'custom_field_value' => $custom_field_value_data,
|
| 55: | 'name' => $custom_field['name'],
|
| 56: | 'type' => $custom_field['type'],
|
| 57: | 'value' => $custom_field['value'],
|
| 58: | 'validation' => $custom_field['validation'],
|
| 59: | 'location' => $custom_field['location'],
|
| 60: | 'required' => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true,
|
| 61: | 'sort_order' => $custom_field['sort_order']
|
| 62: | ];
|
| 63: | }
|
| 64: |
|
| 65: | return $custom_field_data;
|
| 66: | }
|
| 67: | }
|
| 68: | |