/**
  * @param int $download_id
  * @return array
  */
 public function getDownloadAttributes($download_id)
 {
     $attr_mngr = new AAttribute_Manager('download_attribute');
     $attribute_info = $attr_mngr->getAttributeTypeInfo('download_attribute');
     $attributes = $attr_mngr->getAttributes(array('attribute_type_id' => $attribute_info['attribute_type_id'], 'sort' => 'sort_order', 'order' => 'ASC', 'limit' => null));
     $ids = array();
     foreach ($attributes as $attribute) {
         $ids[] = (int) $attribute['attribute_id'];
         $attribute['values'] = $attr_mngr->getAttributeValues($attribute['attribute_id']);
         $output[$attribute['attribute_id']] = $attribute;
     }
     if ($ids) {
         $result = $this->db->query("SELECT attribute_id, attribute_value_ids as value\n\t\t\t\t\t\t\t\t\t\t  FROM " . $this->db->table('download_attribute_values') . "\n\t\t\t\t\t\t\t\t\t\t  WHERE attribute_id IN (" . implode(',', $ids) . ") AND download_id = '" . $download_id . "'");
         foreach ($result->rows as $row) {
             if (isset($output[$row['attribute_id']])) {
                 $output[$row['attribute_id']]['selected_values'] = unserialize($row['value']);
             }
         }
     }
     return $output;
 }
Example #2
0
 /**
  * @param $form AForm
  * @return string
  */
 private function _option_value_form($form)
 {
     $this->data['option_attribute'] = $this->attribute_manager->getAttributeByProductOptionId($this->request->get['option_id']);
     $this->data['option_attribute']['values'] = '';
     $this->data['option_attribute']['type'] = 'input';
     $product_option_value_id = $this->request->get['product_option_value_id'];
     $group_attribute = array();
     if ($this->data['option_attribute']['attribute_id']) {
         $group_attribute = $this->attribute_manager->getAttributes(array(), $this->data['language_id'], $this->data['option_attribute']['attribute_id']);
     }
     $this->data['elements_with_options'] = HtmlElementFactory::getElementsWithOptions();
     //load values for attributes with options
     if (count($group_attribute)) {
         $this->data['option_attribute']['group'] = array();
         foreach ($group_attribute as $attribute) {
             $option_id = $attribute['attribute_id'];
             $this->data['option_attribute']['group'][$option_id]['name'] = $attribute['name'];
             $this->data['option_attribute']['group'][$option_id]['type'] = 'hidden';
             if (in_array($attribute['element_type'], $this->data['elements_with_options'])) {
                 $this->data['option_attribute']['group'][$option_id]['type'] = 'selectbox';
                 $values = $this->attribute_manager->getAttributeValues($attribute['attribute_id'], $this->language->getContentLanguageID());
                 foreach ($values as $v) {
                     $this->data['option_attribute']['group'][$option_id]['values'][$v['attribute_value_id']] = addslashes(html_entity_decode($v['value'], ENT_COMPAT, 'UTF-8'));
                 }
             }
         }
     } else {
         if (in_array($this->data['option_attribute']['element_type'], $this->data['elements_with_options'])) {
             $this->data['option_attribute']['type'] = 'selectbox';
             if (is_null($product_option_value_id)) {
                 // for new row values
                 $values = $this->attribute_manager->getAttributeValues($this->data['option_attribute']['attribute_id'], $this->language->getContentLanguageID());
             } else {
                 $values = $this->getProductOptionValues($this->data['option_attribute']['attribute_id'], $this->language->getContentLanguageID());
             }
             foreach ($values as $v) {
                 $this->data['option_attribute']['values'][$v['attribute_value_id']] = addslashes(html_entity_decode($v['value'], ENT_COMPAT, 'UTF-8'));
             }
         }
     }
     $this->data['cancel'] = $this->html->getSecureURL('product/product/load_option', '&product_id=' . $this->request->get['product_id'] . '&option_id=' . $this->request->get['option_id']);
     if (isset($this->request->get['product_option_value_id'])) {
         $this->data['row_id'] = 'row' . $product_option_value_id;
         $this->data['attr_val_id'] = $product_option_value_id;
         $item_info = $this->model_catalog_product->getProductOptionValue($this->request->get['product_id'], $product_option_value_id);
     } else {
         $this->data['row_id'] = 'new_row';
     }
     $fields = array('default', 'name', 'sku', 'quantity', 'subtract', 'price', 'prefix', 'sort_order', 'weight', 'weight_type', 'attribute_value_id', 'children_options');
     foreach ($fields as $f) {
         if (isset($this->request->post[$f])) {
             $this->data[$f] = $this->request->post[$f];
         } elseif (isset($item_info)) {
             $this->data[$f] = $item_info[$f];
         } else {
             $this->data[$f] = '';
         }
     }
     if (isset($this->request->post['name'])) {
         $this->data['name'] = $this->request->post['name'];
     } elseif (isset($item_info)) {
         $this->data['name'] = $item_info['language'][$this->language->getContentLanguageID()]['name'];
     }
     if (isset($this->data['option_attribute']['group'])) {
         //process grouped (parent/chiled) options
         $this->data['form']['fields']['option_value'] = '';
         foreach ($this->data['option_attribute']['group'] as $attribute_id => $data) {
             $this->data['form']['fields']['option_value'] .= '<span style="white-space: nowrap;">' . $data['name'] . '' . $form->getFieldHtml(array('type' => $data['type'], 'name' => 'attribute_value_id[' . $product_option_value_id . '][' . $attribute_id . ']', 'value' => $this->data['children_options'][$attribute_id], 'options' => $data['values'], 'attr' => '')) . '<span><br class="clr_both">';
         }
     } else {
         if (in_array($this->data['option_attribute']['element_type'], $this->data['elements_with_options'])) {
             $this->data['form']['fields']['option_value'] = $form->getFieldHtml(array('type' => $this->data['option_attribute']['type'], 'name' => 'attribute_value_id[' . $product_option_value_id . ']', 'value' => $this->data['attribute_value_id'], 'options' => $this->data['option_attribute']['values']));
         } else {
             if ($this->data['option_attribute']['element_type'] == 'U') {
                 //for file there is no option value
                 $this->data['form']['fields']['option_value'] = '';
             } else {
                 $arr = array('type' => 'input', 'name' => 'name[' . $product_option_value_id . ']', 'value' => $this->data['name']);
                 // for checkbox show error when value is empty
                 if ($this->data['option_data']['element_type'] == 'C' && $this->data['name'] == '') {
                     $arr['style'] = 'alert-danger';
                 }
                 $this->data['form']['fields']['option_value'] = $form->getFieldHtml($arr);
             }
         }
     }
     $this->data['form']['fields']['product_option_value_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'product_option_value_id[' . $product_option_value_id . ']', 'value' => $product_option_value_id));
     if (in_array($this->data['option_data']['element_type'], $this->data['elements_with_options'])) {
         $this->data['form']['fields']['default'] = $form->getFieldHtml(array('type' => 'radio', 'name' => 'default_value', 'id' => 'default_' . $product_option_value_id, 'value' => $this->data['default'] ? $product_option_value_id : '', 'options' => array($product_option_value_id => '')));
         $this->data['with_default'] = 1;
     }
     $this->data['form']['fields']['sku'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sku[' . $product_option_value_id . ']', 'value' => $this->data['sku']));
     $this->data['form']['fields']['quantity'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity[' . $product_option_value_id . ']', 'value' => $this->data['quantity'], 'style' => 'small-field'));
     $this->data['form']['fields']['subtract'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'subtract[' . $product_option_value_id . ']', 'value' => $this->data['subtract'], 'options' => array(1 => $this->language->get('text_yes'), 0 => $this->language->get('text_no'))));
     $this->data['form']['fields']['price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'price[' . $product_option_value_id . ']', 'value' => moneyDisplayFormat($this->data['price']), 'style' => 'medium-field'));
     $this->data['prefix'] = trim($this->data['prefix']);
     $currency_symbol = $this->currency->getCurrency($this->config->get('config_currency'));
     $currency_symbol = $currency_symbol['symbol_left'] . $currency_symbol['symbol_right'];
     if (!$this->data['prefix']) {
         $this->data['prefix'] = $currency_symbol;
     }
     $this->data['form']['fields']['prefix'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'prefix[' . $product_option_value_id . ']', 'value' => $this->data['prefix'], 'options' => array('$' => $currency_symbol, '%' => '%'), 'style' => 'small-field'));
     $this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order[' . $product_option_value_id . ']', 'value' => $this->data['sort_order'], 'style' => 'small-field'));
     $this->data['form']['fields']['weight'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'weight[' . $product_option_value_id . ']', 'value' => $this->data['weight'], 'style' => 'small-field'));
     //build available weight units for options
     $wht_options = array('%' => '%');
     $this->loadModel('localisation/weight_class');
     $selected_unit = trim($this->data['weight_type']);
     $prd_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
     $prd_weight_info = $this->model_localisation_weight_class->getWeightClass($prd_info['weight_class_id']);
     $wht_options[$prd_weight_info['unit']] = $prd_weight_info['title'];
     if (empty($selected_unit)) {
         //no weight yet, use product weight unit as default
         $selected_unit = trim($prd_weight_info['unit']);
     } else {
         if ($selected_unit != trim($prd_weight_info['unit']) && $selected_unit != '%') {
             //main product type has changed. Show what weight unit we have in option
             $weight_info = $this->model_localisation_weight_class->getWeightClassDescriptionByUnit($selected_unit);
             $wht_options[$selected_unit] = $weight_info['title'];
         }
     }
     $this->data['form']['fields']['weight_type'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'weight_type[' . $product_option_value_id . ']', 'value' => $selected_unit, 'options' => $wht_options));
     $resources_html = $this->dispatch('responses/common/resource_library/get_resources_html');
     $this->data['resources_html'] = $resources_html->dispatchGetOutput();
     $this->view->batchAssign($this->data);
     return $this->view->fetch('responses/product/option_value_row.tpl');
 }
Example #3
0
 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');
 }