public function get_attribute_type() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $am = new AAttribute_Manager(); $this->data['attribute_info'] = $am->getAttribute($this->request->get['attribute_id']); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->load->library('json'); $this->response->setOutput(AJson::encode($this->data['attribute_info']['attribute_type_id'])); }
/** * @param int $product_id * @param array $data * @return int */ public function addProductOption($product_id, $data) { $am = new AAttribute_Manager(); $attribute = $am->getAttribute($data['attribute_id']); if ($attribute) { $data['element_type'] = $attribute['element_type']; $data['required'] = $attribute['required']; $data['regexp_pattern'] = $attribute['regexp_pattern']; $data['sort_order'] = $attribute['sort_order']; $data['settings'] = $attribute['settings']; } $this->db->query("INSERT INTO " . $this->db->table("product_options") . "\n\t\t\t\t\t\t\t(product_id,\n\t\t\t\t\t\t\t attribute_id,\n\t\t\t\t\t\t\t element_type,\n\t\t\t\t\t\t\t required,\n\t\t\t\t\t\t\t sort_order,\n\t\t\t\t\t\t\t group_id,\n\t\t\t\t\t\t\t status,\n\t\t\t\t\t\t\t regexp_pattern,\n\t\t\t\t\t\t\t settings)\n\t\t\t\t\t\tVALUES ('" . (int) $product_id . "',\n\t\t\t\t\t\t\t'" . (int) $data['attribute_id'] . "',\n\t\t\t\t\t\t\t'" . $this->db->escape($data['element_type']) . "',\n\t\t\t\t\t\t\t'" . (int) $data['required'] . "',\n\t\t\t\t\t\t\t'" . (int) $data['sort_order'] . "',\n\t\t\t\t\t\t\t'" . (int) $data['group_id'] . "',\n\t\t\t\t\t\t\t'" . (int) $data['status'] . "',\n\t\t\t\t\t\t\t'" . $this->db->escape($data['regexp_pattern']) . "',\n\t\t\t\t\t\t\t'" . $this->db->escape($data['settings']) . "'\n\t\t\t\t\t\t\t)"); $product_option_id = $this->db->getLastId(); if (!empty($data['option_name'])) { $attributeDescriptions = array($this->language->getContentLanguageID() => array('name' => $data['option_name'], 'error_text' => $data['error_text'])); } else { $attributeDescriptions = $am->getAttributeDescriptions($data['attribute_id']); } foreach ($attributeDescriptions as $language_id => $descr) { $this->language->replaceDescriptions('product_option_descriptions', array('product_option_id' => (int) $product_option_id, 'product_id' => (int) $product_id), array($language_id => array('name' => $descr['name'], 'error_text' => $descr['error_text']))); } //add empty option value for single value attributes $elements_with_options = HtmlElementFactory::getElementsWithOptions(); if (!in_array($data['element_type'], $elements_with_options)) { $this->insertProductOptionValue($product_id, $product_option_id, '', '', array()); } $this->cache->remove('product'); return $product_option_id; }
private function _getForm() { $this->data = array(); $this->data['error'] = $this->error; $this->data['cancel'] = $this->html->getSecureURL('catalog/attribute'); $this->data['get_attribute_type'] = $this->html->getSecureURL('r/catalog/attribute/get_attribute_type'); $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/attribute'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ')); if (isset($this->request->get['attribute_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') { $attribute_info = $this->attribute_manager->getAttribute($this->request->get['attribute_id'], $this->session->data['content_language_id']); $attribute_type_info = $this->attribute_manager->getAttributeTypeInfoById((int) $attribute_info['attribute_type_id']); //load values for attributes with options $this->data['elements_with_options'] = HtmlElementFactory::getElementsWithOptions(); if (in_array($attribute_info['element_type'], $this->data['elements_with_options'])) { $values = $this->attribute_manager->getAttributeValues($this->request->get['attribute_id'], $this->session->data['content_language_id']); $attribute_info['values'] = array(); foreach ($values as $v) { $attribute_info['values'][] = addslashes(html_entity_decode($v['value'], ENT_COMPAT, 'UTF-8')); } } if (has_value($attribute_info['settings'])) { $attribute_info['settings'] = unserialize($attribute_info['settings']); } } if (has_value($this->request->get['attribute_type_id'])) { $attribute_type_info = $this->attribute_manager->getAttributeTypeInfoById((int) $this->request->get['attribute_type_id']); } $fields = array('name', 'attribute_group_id', 'attribute_type_id', 'element_type', 'sort_order', 'required', 'regexp_pattern', 'error_text', 'settings', 'status', 'values'); if ($attribute_type_info['type_key'] != 'download_attribute') { $fields[] = 'attribute_parent_id'; } foreach ($fields as $f) { if (isset($this->request->post[$f])) { $this->data[$f] = $this->request->post[$f]; } elseif (isset($attribute_info[$f])) { $this->data[$f] = $attribute_info[$f]; } else { $this->data[$f] = ''; if ($f == 'status') { $this->data[$f] = 1; } } } // build tabs on page $results = $this->attribute_manager->getAttributeTypes(); foreach ($results as $type) { $this->data['attribute_types'][$type['attribute_type_id']] = $type; } if (isset($attribute_info['attribute_type_id'])) { $attribute_type_id = (int) $attribute_info['attribute_type_id']; } else { $attribute_type_id = (int) $this->request->get_or_post('attribute_type_id'); } if (!$attribute_type_id) { $attribute_type_id = key($this->data['attribute_types']); } $this->_initTabs($attribute_type_id); //NOTE: Future inplementation /*$attribute_groups = array( '' => $this->language->get('text_select')); $results = $this->attribute_manager->getAttributeGroups(array('language_id' => $this->session->data['content_language_id'])); foreach ($results as $type) { $attribute_groups[$type['attribute_group_id']] = $type['name']; }*/ if (!isset($this->request->get['attribute_id'])) { $this->data['action'] = $this->html->getSecureURL('catalog/attribute/insert', '&attribute_type_id=' . $attribute_type_id); $this->data['heading_title'] = $this->language->get('text_insert') . $this->language->get('text_attribute'); $this->data['update'] = ''; $form = new AForm('ST'); } else { $this->data['action'] = $this->html->getSecureURL('catalog/attribute/update', '&attribute_id=' . $this->request->get['attribute_id'] . '&attribute_type_id=' . $attribute_type_id); $this->data['heading_title'] = $this->language->get('text_edit') . $this->language->get('text_attribute'); $this->data['update'] = $this->html->getSecureURL('listing_grid/attribute/update_field', '&id=' . $this->request->get['attribute_id']); $form = new AForm('HT'); $this->data['attribute_id'] = $this->request->get['attribute_id']; } $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: ')); $form->setForm(array('form_name' => 'editFrm', 'update' => $this->data['update'])); $this->data['form']['id'] = 'editFrm'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editFrm', 'attr' => 'confirm-exit="true"', 'action' => $this->data['action'])); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $this->data['form']['fields']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => $this->data['status'], 'style' => 'btn_switch')); $this->data['form']['fields']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $this->data['name'], 'required' => true, 'style' => 'large-field')); if ($attribute_type_info['type_key'] != 'download_attribute') { $parent_attributes = array('' => $this->language->get('text_select')); $results = $this->attribute_manager->getAttributes(array('attribute_type_id' => $attribute_type_id, 'limit' => null), 0, 0); foreach ($results as $type) { if (isset($this->request->get['attribute_id']) && $this->request->get['attribute_id'] == $type['attribute_id']) { continue; } $parent_attributes[$type['attribute_id']] = $type['name']; } $this->data['form']['fields']['attribute_parent'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'attribute_parent_id', 'value' => $this->data['attribute_parent_id'], 'options' => $parent_attributes)); } //NOTE: Future implementation /*$this->data['form']['fields']['attribute_group'] = $form->getFieldHtml(array( 'type' => 'selectbox', 'name' => 'attribute_group_id', 'value' => $this->data['attribute_group_id'], 'options' => $attribute_groups, ));*/ if ($this->data['attribute_types'][$attribute_type_id]['controller']) { $subform = $this->dispatch($this->data['attribute_types'][$attribute_type_id]['controller'], array(array('data' => $this->data, 'aform' => $form, 'attribute_manager' => $this->attribute_manager))); $this->data['subform'] = $subform->dispatchGetOutput(); } $this->data['insert'] = $this->html->getSecureURL('catalog/attribute/insert'); $this->data['form_language_switch'] = $this->html->getContentLanguageSwitcher(); $this->data['text_parent_note'] = $this->language->get('text_parent_note'); $this->data['help_url'] = $this->gen_help_url('global_attributes_edit'); $this->view->batchAssign($this->data); $this->processTemplate('pages/catalog/attribute_form.tpl'); }