docs/api/source-catalog.model.account.custom_field.html
| 1: | <?php |
| 2: | namespace Opencart\Catalog\Model\Account; |
| 3: | /** |
| 4: | * Class CustomField |
| 5: | * |
| 6: | * @package Opencart\Catalog\Model\Account |
| 7: | */ |
| 8: | class CustomField extends \Opencart\System\Engine\Model { |
| 9: | /** |
| 10: | * Get Custom Field |
| 11: | * |
| 12: | * @param int $custom_field_id |
| 13: | * |
| 14: | * @return array<string, mixed> |
| 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: | * Get Custom Fields |
| 24: | * |
| 25: | * @param int $customer_group_id |
| 26: | * |
| 27: | * @return array<int, array<string, mixed>> |
| 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: | |
OpenCart API API documentation generated by ApiGen dev-master