Beispiel #1
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');
 }
Beispiel #2
0
 /**
  * @param int $product_id
  * @param int $product_option_id
  */
 public function deleteProductOption($product_id, $product_option_id)
 {
     $am = new AAttribute_Manager();
     $attribute = $am->getAttributeByProductOptionId($product_option_id);
     $group_attribute = $am->getAttributes(array('limit' => null), 0, $attribute['attribute_id']);
     if (count($group_attribute)) {
         //delete children options/values
         $children = $this->db->query("SELECT product_option_id FROM " . $this->db->table("product_options") . "\n\t\t\t\tWHERE product_id = '" . (int) $product_id . "'\n\t\t\t\t\tAND group_id = '" . (int) $product_option_id . "'");
         foreach ($children->rows as $g_attribute) {
             $this->_deleteProductOption($product_id, $g_attribute['product_option_id']);
         }
     }
     $this->_deleteProductOption($product_id, $product_option_id);
     $this->cache->remove('product');
 }