shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

custom_field.php (3028B)


      1 <?php
      2 class ModelAccountCustomField extends Model {
      3 	public function getCustomField($custom_field_id) {
      4 		$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') . "'");
      5 
      6 		return $query->row;
      7 	}
      8 
      9 	public function getCustomFields($customer_group_id = 0) {
     10 		$custom_field_data = array();
     11 
     12 		if (!$customer_group_id) {
     13 			$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') . "' AND cf.status = '1' ORDER BY cf.sort_order ASC");
     14 		} else {
     15 			$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");
     16 		}
     17 
     18 		foreach ($custom_field_query->rows as $custom_field) {
     19 			$custom_field_value_data = array();
     20 
     21 			if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio' || $custom_field['type'] == 'checkbox') {
     22 				$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");
     23 
     24 				foreach ($custom_field_value_query->rows as $custom_field_value) {
     25 					$custom_field_value_data[] = array(
     26 						'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
     27 						'name'                  => $custom_field_value['name']
     28 					);
     29 				}
     30 			}
     31 
     32 			$custom_field_data[] = array(
     33 				'custom_field_id'    => $custom_field['custom_field_id'],
     34 				'custom_field_value' => $custom_field_value_data,
     35 				'name'               => $custom_field['name'],
     36 				'type'               => $custom_field['type'],
     37 				'value'              => $custom_field['value'],
     38 				'validation'         => $custom_field['validation'],
     39 				'location'           => $custom_field['location'],
     40 				'required'           => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true,
     41 				'sort_order'         => $custom_field['sort_order']
     42 			);
     43 		}
     44 
     45 		return $custom_field_data;
     46 	}
     47 }