/** * @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; }
/** * Form to edit product from order */ public function orderProductForm() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadModel('catalog/product'); $this->loadModel('sale/order'); $this->loadLanguage('catalog/product'); $this->loadLanguage('sale/order'); $this->load->library('json'); $elements_with_options = HtmlElementFactory::getElementsWithOptions(); $order_product_id = (int) $this->request->get['order_product_id']; $order_id = (int) $this->request->get['order_id']; $order_info = $this->model_sale_order->getOrder($order_id); $tax = new ATax($this->registry); $tax->setZone($order_info['country_id'], $order_info['zone_id']); $product_id = (int) $this->request->get['product_id']; $preset_values = array(); if ($order_product_id) { //if unknown product_id but order_product_id we know $order_product_info = $this->model_sale_order->getOrderProducts($order_id, $order_product_id); $preset_values['price'] = $this->currency->format($order_product_info[0]['price'], $order_info['currency'], $order_info['value'], false); $preset_values['total'] = $this->currency->format($order_product_info[0]['price'] * $order_product_info[0]['quantity'], $order_info['currency'], $order_info['value'], false); $preset_values['quantity'] = $order_product_info[0]['quantity']; if (!$product_id) { $product_id = $order_product_info[0]['product_id']; } $product_info = $this->model_catalog_product->getProduct($product_id); $order_product_options = $this->model_sale_order->getOrderOptions($order_id, $order_product_id); foreach ($order_product_options as $v) { if ($v['element_type'] == 'R') { $preset_values[$v['product_option_id']] = $v['product_option_value_id']; } elseif (in_array($v['element_type'], $elements_with_options)) { $preset_values[$v['product_option_id']][] = $v['product_option_value_id']; } else { $preset_values[$v['product_option_id']] = $v['value']; } } $this->data['text_title'] = $this->language->get('text_edit_order_product'); $form_action = $this->html->getSecureURL('sale/order/update', '&order_id=' . $order_id . '&order_product_id=' . $order_product_id); } else { $product_info = $this->model_catalog_product->getProduct($product_id); $this->data['text_title'] = sprintf($this->language->get('text_add_product_to_order'), $order_id); $preset_values['quantity'] = $product_info['minimum'] ? $product_info['minimum'] : 1; $preset_values['price'] = $this->currency->format($product_info['price'], $order_info['currency'], $order_info['value'], false); $preset_values['total'] = $this->currency->format($product_info['price'] * $preset_values['quantity'], $order_info['currency'], $order_info['value'], false); $form_action = $this->html->getSecureURL('sale/order/update', '&order_id=' . $order_id . '&product_id=' . $product_id); } $this->data['product_href'] = $this->html->getSecureURL('catalog/product/update', '&product_id=' . $product_id); $form = new AForm('HT'); $form->setForm(array('form_name' => 'orderProductFrm')); $this->data['form']['id'] = 'orderProductFrm'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'orderProductFrm', 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"', 'action' => $form_action)); $this->data['text_title'] .= ' - ' . $product_info['name']; // Prepare options and values for display $product_options = $this->model_catalog_product->getOrderProductOptions($product_id); $option_values_prices = array(); foreach ($product_options as $option) { if (in_array($option['element_type'], array('U'))) { continue; } //skip files for now. TODO: add edit file-option in the future $values = $prices = array(); $price = $preset_value = $default_value = ''; foreach ($option['option_value'] as $option_value) { //default value $default_value = $option_value['default'] && !$order_product_id ? $option_value['product_option_value_id'] : $default_value; //early saved value $preset_value = $preset_values[$option['product_option_id']]; //when adds new product in the order if (!$order_product_id) { if ($option_value['default'] == 1) { $preset_value = $option_value['product_option_value_id']; } elseif (!in_array($option['element_type'], $elements_with_options)) { $preset_value = $option_value['name']; } } //Apply option price modifier if ($option_value['prefix'] == '%') { $price = $tax->calculate($product_info['price'] * $option_value['price'] / 100, $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); } else { $price = $tax->calculate($option_value['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); } if ($price != 0) { $price = $this->currency->format($price); } else { $price = ''; } //Check stock and status $opt_stock_message = ''; if ($option_value['subtract']) { if ($option_value['quantity'] <= 0) { //show out of stock message $opt_stock_message = ' (' . $this->language->get('text_product_out_of_stock') . ')'; } else { if ($this->config->get('config_stock_display')) { $opt_stock_message = ' (' . $option_value['quantity'] . " " . $this->language->get('text_product_in_stock') . ')'; } } } $values[$option_value['product_option_value_id']] = $option_value['name'] . ' ' . $price . ' ' . $opt_stock_message; } //if not values are build, nothing to show if (count($values)) { //add price to option name if it is not element with options if (!in_array($option['element_type'], $elements_with_options)) { $option['name'] .= ' <small>' . $price . '</small>'; if ($opt_stock_message) { $option['name'] .= '<br />' . $opt_stock_message; } } //set default selection is nothing selected if (!has_value($preset_value) && $option['element_type'] != 'C') { if (has_value($default_value)) { $preset_value = $default_value; } } //show hidden option for admin if ($option['html_type'] == 'hidden') { $option['html_type'] = 'input'; } $value = $preset_value; //for checkbox with empty value if ($value == '' && $option['element_type'] == 'C') { $value = $default_value; $value = $value == '' ? 1 : $value; } $option_data = array('type' => $option['html_type'], 'name' => !in_array($option['element_type'], HtmlElementFactory::getMultivalueElements()) ? 'product[0][option][' . $option['product_option_id'] . ']' : 'product[0][option][' . $option['product_option_id'] . '][]', 'value' => $value, 'options' => $values, 'placeholder' => $option['option_placeholder'], 'regexp_pattern' => $option['regexp_pattern'], 'error_text' => $option['error_text'], 'attr' => ' data-option-id ="' . $option['product_option_id'] . '"'); if ($option['element_type'] == 'C') { // note: 0 and 1 must be stirng to prevent collision with 'yes'. (in php 'yes'==1) ;-) $option_data['label_text'] = !in_array($value, array('0', '1')) ? $value : ''; $option_data['checked'] = $preset_value ? true : false; } $options[] = array('name' => $option['name'], 'html' => $form->getFieldHtml($option_data)); } } $this->data['options'] = $options; // main product image $resource = new AResource('image'); $thumbnail = $resource->getMainThumb('products', $product_id, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'), true); $this->data['image'] = $thumbnail; $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $order_product_id ? $this->language->get('button_save') : $this->language->get('button_add'))); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'))); $this->data['form']['fields']['price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product[0][price]', 'value' => $preset_values['price'], 'attr' => ' readonly')); if (!$options && $product_info['subtract']) { if ($product_info['quantity']) { $this->data['column_quantity'] = $this->language->get('column_quantity') . ' (' . $this->language->get('text_product_in_stock') . ': ' . $product_info['quantity'] . ')'; } else { $this->data['column_quantity'] = $this->language->get('column_quantity') . ' (' . $this->language->get('text_product_out_of_stock') . ')'; } } $this->data['form']['fields']['quantity'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product[0][quantity]', 'value' => $preset_values['quantity'], 'attr' => ' size="4"')); $this->data['form']['fields']['total'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product[0][total]', 'value' => $preset_values['total'], 'attr' => 'readonly')); $this->data['form']['fields']['product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'product_id', 'value' => $product_id)); $this->data['form']['fields']['order_product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'order_product_id', 'value' => (int) $order_product_id)); //url to storefront response controller. Note: if admin under ssl - use https for url and otherwise $order_store_id = $order_info['store_id']; $this->loadModel('setting/store'); $store_info = $this->model_setting_store->getStore($order_store_id); if (HTTPS === true && $store_info['config_ssl_url']) { $total_calc_url = $store_info['config_ssl_url'] . 'index.php?rt=r/product/product/calculateTotal'; } elseif (HTTPS === true && !$store_info['config_ssl_url']) { $total_calc_url = str_replace('http://', 'https://', $store_info['config_url']) . 'index.php?rt=r/product/product/calculateTotal'; } else { $total_calc_url = $store_info['config_url'] . 'index.php?rt=r/product/product/calculateTotal'; } $this->data['total_calc_url'] = $total_calc_url; //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->view->batchAssign($this->data); $this->processTemplate('responses/product/product_form.tpl'); }
/** * method that return part of attribute form for download attribute * @internal param array $param * @param array $params */ public function getDownloadAttributeSubform($params = array()) { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->data = array_merge($this->data, $params['data']); unset($this->data['form']['fields']); // remove form fields that do not needed here $this->data['elements_with_options'] = HtmlElementFactory::getElementsWithOptions(); $results = HtmlElementFactory::getAvailableElements(); $element_types = array('' => $this->language->get('text_select')); foreach ($results as $key => $type) { // allowed field types if (in_array($key, array('I', 'T', 'S', 'M', 'R', 'C'))) { $element_types[$key] = $type['type']; } } $form = $params['aform']; $attribute_manager = $params['attribute_manager']; $this->data['form']['fields']['element_type'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'element_type', 'value' => $this->data['element_type'], 'required' => true, 'options' => $element_types)); $this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['sort_order'], 'style' => 'small-field')); $this->data['form']['fields']['show_to_customer'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'settings[show_to_customer]', 'value' => 1, 'checked' => $this->data['settings'] && $this->data['settings']['show_to_customer'] ? true : false, 'style' => 'btn_switch')); //Build atribute values part of the form if ($this->request->get['attribute_id']) { $this->data['child_count'] = $attribute_manager->totalChildren($this->request->get['attribute_id']); if ($this->data['child_count'] > 0) { $children_attr = $attribute_manager->getAttributes(array(), 0, $this->request->get['attribute_id']); foreach ($children_attr as $attr) { $this->data['children'][] = array('name' => $attr['name'], 'link' => $this->html->getSecureURL('catalog/attribute/update', '&attribute_id=' . $attr['attribute_id'])); } } $attribute_values = $attribute_manager->getAttributeValues($this->request->get['attribute_id']); foreach ($attribute_values as $atr_val) { $atr_val_id = $atr_val['attribute_value_id']; $attributes_fields[$atr_val_id]['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_orders[' . $atr_val_id . ']', 'value' => $atr_val['sort_order'], 'style' => 'small-field')); $attributes_fields[$atr_val_id]['values'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'values[' . $atr_val_id . ']', 'value' => $atr_val['value'], 'style' => 'medium-field')); $attributes_fields[$atr_val_id]['attribute_value_ids'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'attribute_value_ids[' . $atr_val_id . ']', 'value' => $atr_val_id, 'style' => 'medium-field')); } } if (!$attributes_fields) { $attributes_fields[0]['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_orders[]', 'value' => '', 'style' => 'small-field no-save')); $attributes_fields[0]['values'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'values[]', 'value' => '', 'style' => 'medium-field no-save')); $attributes_fields[0]['attribute_value_ids'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'attribute_value_ids[' . $atr_val_id . ']', 'value' => 'new', 'style' => 'medium-field')); } $this->data['form']['attribute_values'] = $attributes_fields; $this->view->batchAssign($this->data); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->processTemplate('responses/catalog/global_attribute_product_option_subform.tpl'); }
/** * @param int $attribute_id * @param array $data */ public function updateAttribute($attribute_id, $data) { //Note: update is done per 1 language $language_id = $this->session->data['content_language_id']; $fields = array('attribute_type_id', 'attribute_group_id', 'attribute_parent_id', 'element_type', 'required', 'sort_order', 'settings', 'status', 'regexp_pattern'); $elements_with_options = HtmlElementFactory::getElementsWithOptions(); $attribute = $this->getAttribute($attribute_id, $language_id); //check if we change element type and clean options if it does not require it if (isset($data['element_type']) && $data['element_type'] != $attribute['element_type']) { if (!in_array($data['element_type'], $elements_with_options)) { $sql = "DELETE FROM `" . DB_PREFIX . "global_attributes_values`\n\t\t\t\t\t\tWHERE attribute_id = '" . (int) $attribute_id . "'"; $this->db->query($sql); $sql = "DELETE FROM `" . DB_PREFIX . "global_attributes_value_descriptions`\n\t\t\t\t\t\tWHERE attribute_id = '" . (int) $attribute_id . "'"; $this->db->query($sql); } } if (has_value($data['settings'])) { $data['settings'] = serialize($data['settings']); } $update = array(); foreach ($fields as $f) { if (isset($data[$f])) { $update[] = "{$f} = '" . $this->db->escape($data[$f]) . "'"; } } if (!empty($update)) { $sql = "UPDATE " . DB_PREFIX . "global_attributes\n SET " . implode(',', $update) . "\n WHERE attribute_id = '" . (int) $attribute_id . "'"; $this->db->query($sql); } $update = array(); if (isset($data['name'])) { $update['name'] = $data['name']; } if (isset($data['error_text'])) { $update['error_text'] = $data['error_text']; } $this->language->replaceDescriptions('global_attributes_descriptions', array('attribute_id' => (int) $attribute_id), array($language_id => $update)); //Update Attribute Values if (!empty($data['values']) && in_array($data['element_type'], $elements_with_options)) { foreach ($data['values'] as $atr_val_id => $value) { //Check if new or update if ($data['attribute_value_ids'][$atr_val_id] == 'delete') { //delete the description $this->deleteAllAttributeValueDescriptions($atr_val_id); //delete value if no other language $this->deleteAttributeValues($atr_val_id); } else { if ($data['attribute_value_ids'][$atr_val_id] == 'new') { // New need to create $attribute_value_id = $this->addAttributeValue($attribute_id, $data['sort_orders'][$atr_val_id]); if ($attribute_value_id) { $this->addAttributeValueDescription($attribute_id, $attribute_value_id, $language_id, $value); } } else { //Existing need to update $this->updateAttributeValue($atr_val_id, $data['sort_orders'][$atr_val_id]); $this->updateAttributeValueDescription($attribute_id, $atr_val_id, $language_id, $value); } } } } $this->clearCache(); }
/** * @param int $order_id * @param array $data */ public function editOrderProduct($order_id, $data) { $order_id = (int) $order_id; $order_product_id = (int) $data['order_product_id']; $product_id = (int) $data['product_id']; if (!$product_id || !$order_id) { return false; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); $order_info = $this->getOrder($order_id); $elements_with_options = HtmlElementFactory::getElementsWithOptions(); if (isset($data['product'])) { foreach ($data['product'] as $product) { if ($product['quantity'] <= 0) { // stupid situation return false; } //check is product exists $exists = $this->db->query("SELECT op.product_id, op.quantity\n\t\t\t\t\t\t\t\t\t\t\t\t FROM " . $this->db->table("order_products") . " op\n\t\t\t\t\t\t\t\t\t\t\t\t WHERE op.order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t AND op.product_id='" . (int) $product_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t AND op.order_product_id = '" . (int) $order_product_id . "'"); if ($exists->num_rows) { //update order quantity $this->db->query("UPDATE " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t SET price = '" . $this->db->escape(preformatFloat($product['price'], $this->language->get('decimal_point')) / $order_info['value']) . "',\n\t\t\t\t\t\t\t\t\t\t \t total = '" . $this->db->escape(preformatFloat($product['total'], $this->language->get('decimal_point')) / $order_info['value']) . "',\n\t\t\t\t\t\t\t\t\t\t\t quantity = '" . $this->db->escape($product['quantity']) . "'\n\t\t\t\t\t\t\t\t\t\t WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $order_product_id . "'"); //update stock quantity $old_qnt = $exists->row['quantity']; $stock_qnt = $product_info['quantity']; $qnt_diff = $old_qnt - $product['quantity']; if ($qnt_diff != 0) { if ($qnt_diff < 0) { $new_qnt = $stock_qnt - abs($qnt_diff); } else { $new_qnt = $stock_qnt + $qnt_diff; } if ($product_info['subtract']) { $this->db->query("UPDATE " . $this->db->table("products") . "\n\t\t\t\t\t\t\t\t\t\t\t SET quantity = '" . $new_qnt . "'\n\t\t\t\t\t\t\t\t\t\t\t WHERE product_id = '" . (int) $product_id . "' AND subtract = 1"); } } } else { // add new product into order $product_query = $this->db->query("SELECT *, p.product_id\n\t\t\t\t\t\t\t FROM " . $this->db->table("products") . " p\n\t\t\t\t\t\t\t LEFT JOIN " . $this->db->table("product_descriptions") . " pd\n\t\t\t\t\t\t\t ON (p.product_id = pd.product_id AND pd.language_id=" . $this->language->getContentLanguageID() . ")\n\t\t\t\t\t\t\t WHERE p.product_id='" . (int) $product_id . "'"); $this->db->query("INSERT INTO " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\tSET order_id = '" . (int) $order_id . "',\n\t\t\t\t\t\t\t\tproduct_id = '" . (int) $product_id . "',\n\t\t\t\t\t\t\t\tname = '" . $this->db->escape($product_query->row['name']) . "',\n\t\t\t\t\t\t\t\tmodel = '" . $this->db->escape($product_query->row['model']) . "',\n\t\t\t\t\t\t\t\tprice = '" . $this->db->escape(preformatFloat($product['price'], $this->language->get('decimal_point')) / $order_info['value']) . "',\n\t\t\t\t\t\t\t\ttotal = '" . $this->db->escape(preformatFloat($product['total'], $this->language->get('decimal_point')) / $order_info['value']) . "',\n\t\t\t\t\t\t\t\tquantity = '" . (int) $product['quantity'] . "'"); $order_product_id = $this->db->getLastId(); //update stock quantity $qnt_diff = -$product['quantity']; $stock_qnt = $product_query->row['quantity']; $new_qnt = $stock_qnt - (int) $product['quantity']; if ($product_info['subtract']) { $this->db->query("UPDATE " . $this->db->table("products") . "\n\t\t\t\t\t\t\t\t\t\t SET quantity = '" . $new_qnt . "'\n\t\t\t\t\t\t\t\t\t\t WHERE product_id = '" . (int) $product_id . "' AND subtract = 1"); } } if ($product['option']) { //first of all find previous order options // if empty result - order products just added $order_product_options = $this->getOrderOptions($order_id, $order_product_id); $prev_subtract_options = array(); //array with previous option values with enabled stock tracking foreach ($order_product_options as $old_value) { if (!$old_value['subtract']) { continue; } $prev_subtract_options[(int) $old_value['product_option_id']][] = (int) $old_value['product_option_value_id']; } $po_ids = array(); foreach ($product['option'] as $k => $option) { $po_ids[] = (int) $k; } //get all data of given product options from db $sql = "SELECT *, pov.product_option_value_id, povd.name as option_value_name, pod.name as option_name\n\t\t\t\t\t\t\t\tFROM " . $this->db->table('product_options') . " po\n\t\t\t\t\t\t\t\tLEFT JOIN " . $this->db->table('product_option_descriptions') . " pod\n\t\t\t\t\t\t\t\t\tON (pod.product_option_id = po.product_option_id AND pod.language_id=" . $this->language->getContentLanguageID() . ")\n\t\t\t\t\t\t\t\tLEFT JOIN " . $this->db->table('product_option_values') . " pov\n\t\t\t\t\t\t\t\t\tON po.product_option_id = pov.product_option_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . $this->db->table('product_option_value_descriptions') . " povd\n\t\t\t\t\t\t\t\t ON (povd.product_option_value_id = pov.product_option_value_id AND povd.language_id=" . $this->language->getContentLanguageID() . ")\n\t\t\t\t\t\t\t\tWHERE po.product_option_id IN (" . implode(',', $po_ids) . ")\n\t\t\t\t\t\t\t\tORDER BY po.product_option_id"; $result = $this->db->query($sql); $exclude_list = array(); //list of option value that we do not resave $option_value_info = array(); foreach ($result->rows as $row) { //skip files if (in_array($row['element_type'], array('U'))) { $exclude_list[] = (int) $row['product_option_value_id']; } $option_value_info[$row['product_option_id'] . '_' . $row['product_option_value_id']] = $row; //compond key for cases when val_id is null $option_types[$row['product_option_id']] = $row['element_type']; } //delete old options and then insert new $sql = "DELETE FROM " . $this->db->table('order_options') . "\n\t\t\t\t\t\t\t\tWHERE order_id = " . $order_id . " AND order_product_id=" . (int) $order_product_id; if ($exclude_list) { $sql .= " AND product_option_value_id NOT IN (" . implode(', ', $exclude_list) . ")"; } $this->db->query($sql); foreach ($product['option'] as $opt_id => $values) { if (!is_array($values)) { // for non-multioptional elements //do not save empty inputs and texareas if (in_array($option_types[$opt_id], array('I', 'T')) && $values == '') { continue; } elseif ($option_types[$opt_id] == 'S') { $values = array($values); } else { foreach ($option_value_info as $o) { if ($o['product_option_id'] == $opt_id) { if (!in_array($option_types[$opt_id], $elements_with_options)) { $option_value_info[$o['product_option_id'] . '_' . $o['product_option_value_id']]['option_value_name'] = $values; } $values = array($o['product_option_value_id']); break; } } } } foreach ($values as $value) { $arr_key = $opt_id . '_' . $value; $sql = "INSERT INTO " . $this->db->table('order_options') . "\n\t\t\t\t\t\t\t\t\t\t\t(`order_id`,\n\t\t\t\t\t\t\t\t\t\t\t`order_product_id`,\n\t\t\t\t\t\t\t\t\t\t\t`product_option_value_id`,\n\t\t\t\t\t\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t\t\t\t\t\t`value`,\n\t\t\t\t\t\t\t\t\t\t\t`price`,\n\t\t\t\t\t\t\t\t\t\t\t`prefix`)\n\t\t\t\t\t\t\t\t\t\tVALUES\t('" . $order_id . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . (int) $order_product_id . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . (int) $value . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($option_value_info[$arr_key]['option_name']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($option_value_info[$arr_key]['option_value_name']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($option_value_info[$arr_key]['price']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($option_value_info[$arr_key]['prefix']) . "')"; $this->db->query($sql); if ($option_value_info[$arr_key]['subtract']) { $curr_subtract_options[(int) $opt_id][] = (int) $value; } } //reduce product quantity for option value that not assigned to product anymore $prev_arr = has_value($prev_subtract_options[$opt_id]) ? $prev_subtract_options[$opt_id] : array(); $curr_arr = has_value($curr_subtract_options[$opt_id]) ? $curr_subtract_options[$opt_id] : array(); if ($prev_arr || $curr_arr) { //increase qnt for old option values foreach ($prev_arr as $v) { if (!in_array($v, $curr_arr)) { $sql = "UPDATE " . $this->db->table("product_option_values") . "\n\t\t\t\t\t\t\t\t\t\t SET quantity = (quantity + " . $product['quantity'] . ")\n\t\t\t\t\t\t\t\t\t\t WHERE product_option_value_id = '" . (int) $v . "'\n\t\t\t\t\t\t\t\t\t\t AND subtract = 1"; $this->db->query($sql); } } //decrease qnt for new option values foreach ($curr_arr as $v) { if (!in_array($v, $prev_arr)) { $sql = "UPDATE " . $this->db->table("product_option_values") . "\n\t\t\t\t\t\t\t\t\t\t SET quantity = (quantity - " . $product['quantity'] . ")\n\t\t\t\t\t\t\t\t\t\t WHERE product_option_value_id = '" . (int) $v . "'\n\t\t\t\t\t\t\t\t\t\t AND subtract = 1"; $this->db->query($sql); } } //if qnt changed for the same option values $intersect = array_intersect($curr_arr, $prev_arr); if ($intersect && $qnt_diff != 0) { if ($qnt_diff < 0) { $sql_incl = "(quantity - " . abs($qnt_diff) . ")"; } else { $sql_incl = "(quantity + " . abs($qnt_diff) . ")"; } foreach ($intersect as $v) { $sql = "UPDATE " . $this->db->table("product_option_values") . "\n\t\t\t\t\t\t\t\t\t\t SET quantity = " . $sql_incl . "\n\t\t\t\t\t\t\t\t\t\t WHERE product_option_value_id = '" . (int) $v . "'\n\t\t\t\t\t\t\t\t\t\t AND subtract = 1"; $this->db->query($sql); } } } } } //end processing options } } //fix order total and subtotal $sql = "SELECT SUM(total) as subtotal\n\t\t\t\tFROM " . $this->db->table('order_products') . "\n\t\t\t\tWHERE order_id=" . $order_id; $result = $this->db->query($sql); $subtotal = $result->row['subtotal']; $text = $this->currency->format($subtotal, $order_info['currency'], $order_info['value']); $sql = "UPDATE " . $this->db->table('order_totals') . "\n\t\t SET `value`='" . $subtotal . "', `text` = '" . $text . "'\n\t\t\t\tWHERE order_id=" . $order_id . " AND type='subtotal'"; $this->db->query($sql); $sql = "SELECT SUM(`value`) as total\n\t\t\t\tFROM " . $this->db->table('order_totals') . "\n\t\t\t\tWHERE order_id=" . $order_id . " AND type<>'total'"; $result = $this->db->query($sql); $total = $result->row['total']; $text = $this->currency->format($total, $order_info['currency'], $order_info['value']); $sql = "UPDATE " . $this->db->table('order_totals') . "\n\t\t SET `value`='" . $subtotal . "', `text` = '" . $text . "'\n\t\t\t\tWHERE order_id=" . $order_id . " AND type='total'"; $this->db->query($sql); $this->cache->delete('product'); }
/** * Collect product information for cart based on user selections * Function can be used to get totals and other product information * (based on user selection) as it is before getting into cart or after * @param int $product_id * @param int $quantity * @param array $options * @return array */ public function buildProductDetails($product_id, $quantity = 0, $options = array()) { if (!has_value($product_id) || !is_numeric($product_id) || $quantity == 0) { return array(); } $stock = TRUE; $this->load->model('catalog/product'); $elements_with_options = HtmlElementFactory::getElementsWithOptions(); $product_query = $this->model_catalog_product->getProductDataForCart($product_id); if (count($product_query) <= 0 || $product_query['call_to_order']) { return array(); } $option_price = 0; $option_data = array(); $groups = array(); //Process each option and value foreach ($options as $product_option_id => $product_option_value_id) { //skip empty values if ($product_option_value_id == '' || is_array($product_option_value_id) && !$product_option_value_id) { continue; } //Detect option element type. If single value (text, input) process diferently. $option_attribute = $this->attribute->getAttributeByProductOptionId($product_option_id); if ($option_attribute) { $element_type = $option_attribute['element_type']; $option_query['name'] = $option_attribute['name']; } else { //Not global attribute based option, select element type from options table $option_query = $this->model_catalog_product->getProductOption($product_id, $product_option_id); $element_type = $option_query['element_type']; } if (!in_array($element_type, $elements_with_options)) { //This is single value element, get all values and expect only one $option_value_query = $this->model_catalog_product->getProductOptionValues($product_id, $product_option_id); $option_value_query = $option_value_query[0]; //Set value from input $option_value_query['name'] = $this->db->escape($options[$product_option_id]); } else { //is multivalue option type if (is_array($product_option_value_id)) { $option_value_queries = array(); foreach ($product_option_value_id as $val_id) { $option_value_queries[$val_id] = $this->model_catalog_product->getProductOptionValue($product_id, $val_id); } } else { $option_value_query = $this->model_catalog_product->getProductOptionValue($product_id, (int) $product_option_value_id); } } if ($option_value_query) { //if group option load price from parent value if ($option_value_query['group_id'] && !in_array($option_value_query['group_id'], $groups)) { $group_value_query = $this->model_catalog_product->getProductOptionValue($product_id, $option_value_query['group_id']); $option_value_query['prefix'] = $group_value_query['prefix']; $option_value_query['price'] = $group_value_query['price']; $groups[] = $option_value_query['group_id']; } $option_data[] = array('product_option_value_id' => $option_value_query['product_option_value_id'], 'name' => $option_query['name'], 'value' => $option_value_query['name'], 'prefix' => $option_value_query['prefix'], 'price' => $option_value_query['price'], 'sku' => $option_value_query['sku'], 'weight' => $option_value_query['weight'], 'weight_type' => $option_value_query['weight_type']); //check if need to track stock and we have it if ($option_value_query['subtract'] && $option_value_query['quantity'] < $quantity) { $stock = FALSE; } $op_stock_trackable += $option_value_query['subtract']; unset($option_value_query); } else { if ($option_value_queries) { foreach ($option_value_queries as $item) { $option_data[] = array('product_option_value_id' => $item['product_option_value_id'], 'name' => $option_query['name'], 'value' => $item['name'], 'prefix' => $item['prefix'], 'price' => $item['price'], 'sku' => $item['sku'], 'weight' => $item['weight'], 'weight_type' => $item['weight_type']); //check if need to track stock and we have it if ($item['subtract'] && $item['quantity'] < $quantity) { $stock = FALSE; } $op_stock_trackable += $option_value_query['subtract']; } unset($option_value_queries); } } } // end of options build //needed for promotion $discount_quantity = 0; // this is used to calculate total QTY of 1 product in the cart // check is product is in cart and calculate quantity to define item price with product discount foreach ($this->session->data['cart'] as $k => $v) { $array2 = explode(':', $k); if ($array2[0] == $product_id) { $discount_quantity += $v['qty']; } } if (!$discount_quantity) { $discount_quantity = $quantity; } //Apply group and quantity discount first and if non, reply product discount $price = $this->promotion->getProductQtyDiscount($product_id, $discount_quantity); if (!$price) { $price = $this->promotion->getProductSpecial($product_id); } //Still no special price, use regulr price if (!$price) { $price = $product_query['price']; } foreach ($option_data as $item) { if ($item['prefix'] == '%') { $option_price += $price * $item['price'] / 100; } else { $option_price += $item['price']; } } // product downloads $download_data = $this->download->getProductOrderDownloads($product_id); //check if we need to check main product stock. Do only if no stock trakable options selected if (!$op_stock_trackable && $product_query['subtract'] && $product_query['quantity'] < $quantity) { $stock = FALSE; } $result = array('product_id' => $product_query['product_id'], 'name' => $product_query['name'], 'model' => $product_query['model'], 'shipping' => $product_query['shipping'], 'option' => $option_data, 'download' => $download_data, 'quantity' => $quantity, 'minimum' => $product_query['minimum'], 'maximum' => $product_query['maximum'], 'stock' => $stock, 'price' => $price + $option_price, 'total' => ($price + $option_price) * $quantity, 'tax_class_id' => $product_query['tax_class_id'], 'weight' => $product_query['weight'], 'weight_class' => $product_query['weight_class'], 'length' => $product_query['length'], 'width' => $product_query['width'], 'height' => $product_query['height'], 'length_class' => $product_query['length_class'], 'ship_individually' => $product_query['ship_individually'], 'shipping_price' => $product_query['shipping_price'], 'free_shipping' => $product_query['free_shipping'], 'sku' => $product_query['sku']); return $result; }
public function load_field() { $this->loadLanguage('forms_manager/forms_manager'); $this->loadModel('tool/forms_manager'); $this->data['error_warning'] = $this->session->data['warning']; if (isset($this->session->data['warning'])) { unset($this->session->data['warning']); } $this->view->assign('success', $this->session->data['success']); unset($this->session->data['success']); $this->data['language_id'] = $this->session->data['content_language_id']; $this->data['field_data'] = $this->model_tool_forms_manager->getField($this->request->get['field_id']); $this->data['element_types'] = HtmlElementFactory::getAvailableElements(); $this->data['elements_with_options'] = HtmlElementFactory::getElementsWithOptions(); $this->data['no_set_values_elements'] = array('K' => 'captcha', 'D' => 'date', 'A' => 'IPaddress', 'O' => 'countries', 'Z' => 'zones'); $this->data['selectable'] = in_array($this->data['field_data']['element_type'], $this->data['elements_with_options']) ? 1 : 0; $this->data['field_type'] = $this->data['element_types'][$this->data['field_data']['element_type']]['type']; $this->data['field_name'] = $this->html->buildInput(array('name' => 'field_name', 'value' => $this->data['field_data']['field_name'], 'required' => true)); $this->data['field_description'] = $this->html->buildElement(array('type' => 'input', 'name' => 'field_description', 'value' => $this->data['field_data']['name'], 'required' => true)); $this->data['field_note'] = $this->html->buildElement(array('type' => 'input', 'name' => 'field_note', 'value' => $this->data['field_data']['description'])); $this->data['entry_status'] = $this->language->get('forms_manager_status'); $this->data['status'] = $this->html->buildElement(array('type' => 'checkbox', 'name' => 'status', 'value' => $this->data['field_data']['status'], 'style' => 'btn_switch btn-group-xs')); $this->data['field_sort_order'] = $this->html->buildElement(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['field_data']['sort_order'], 'style' => 'small-field')); $this->data['required'] = $this->html->buildElement(array('type' => 'checkbox', 'name' => 'required', 'value' => $this->data['field_data']['required'] == 'Y' ? 1 : 0, 'style' => 'btn_switch btn-group-xs')); if (!in_array($this->data['field_data']['element_type'], array('U', 'K'))) { $this->data['field_regexp_pattern'] = $this->html->buildElement(array('type' => 'input', 'name' => 'regexp_pattern', 'value' => $this->data['field_data']['regexp_pattern'], 'style' => 'large-field')); $this->data['field_error_text'] = $this->html->buildElement(array('type' => 'input', 'name' => 'error_text', 'value' => $this->data['field_data']['error_text'], 'style' => 'large-field')); } if ($this->data['field_data']['element_type'] == 'U') { $this->data['field_settings'] = $this->_file_upload_settings_form(); } $this->data['hidden_element_type'] = $this->html->buildElement(array('type' => 'hidden', 'name' => 'element_type', 'value' => $this->data['field_data']['element_type'])); $this->data['button_remove_field'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('tool/forms_manager/removeField', '&form_id=' . $this->request->get['form_id'] . '&field_id=' . $this->request->get['field_id']), 'text' => $this->language->get('button_remove_field'))); $this->data['button_save'] = $this->html->buildElement(array('type' => 'button', 'text' => $this->language->get('button_save'))); $this->data['button_reset'] = $this->html->buildElement(array('type' => 'button', 'text' => $this->language->get('button_reset'))); $this->data['update_field_values'] = $this->html->getSecureURL('forms_manager/fields/update_field_values', '&form_id=' . $this->request->get['form_id'] . '&field_id=' . $this->request->get['field_id']); $this->data['remove_field_link'] = $this->html->getSecureURL('forms_manager/fields/remove_field', '&form_id=' . $this->request->get['form_id'] . '&field_id=' . $this->request->get['field_id']); // form of option values list $form = new AForm('HT'); $form->setForm(array('form_name' => 'update_field_values')); $this->data['form']['id'] = 'update_field_values'; $this->data['update_field_values_form']['open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'update_field_values', 'action' => $this->data['update_field_values'])); //form of option $form = new AForm('HT'); $form->setForm(array('form_name' => 'field_value_form')); $this->data['form']['id'] = 'field_value_form'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'field_value_form', 'action' => $this->data['update_field_values'])); //Load option values rows $this->data['field_values'] = array(); if (!in_array($this->data['field_data']['element_type'], array('U', 'K'))) { if (!empty($this->data['field_data']['values'])) { usort($this->data['field_data']['values'], array('self', '_sort_by_sort_order')); foreach ($this->data['field_data']['values'] as $key => $item) { $item['id'] = $key; $this->data['field_values'][$key]['row'] = $this->_field_value_form($item, $form); } } else { $this->data['field_values']['new']['row'] = $this->_field_value_form(array(), $form); } } $this->data['new_field_row'] = ''; if (in_array($this->data['field_data']['element_type'], $this->data['elements_with_options']) || $this->data['empty_values'] && !in_array($this->data['field_type'], $this->data['no_set_values_elements'])) { $this->data['new_value_row'] = $this->_field_value_form(array(), $form); } $this->data['new_value_row'] = $this->_field_value_form(array(), $form); $this->view->batchAssign($this->data); $this->processTemplate('responses/forms_manager/field_values.tpl'); }
public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->loadModel('tool/seo_url'); $this->loadModel('catalog/category'); if (isset($this->request->get['path'])) { $path = ''; foreach (explode('_', $this->request->get['path']) as $path_id) { $category_info = $this->model_catalog_category->getCategory($path_id); if (!$path) { $path = $path_id; } else { $path .= '_' . $path_id; } if ($category_info) { $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/category', '&path=' . $path, '&encode'), 'text' => $category_info['name'], 'separator' => $this->language->get('text_separator'))); } } } $this->loadModel('catalog/manufacturer'); if (isset($this->request->get['manufacturer_id'])) { $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']); if ($manufacturer_info) { $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $this->request->get['manufacturer_id'], '&encode'), 'text' => $manufacturer_info['name'], 'separator' => $this->language->get('text_separator'))); } } if (isset($this->request->get['keyword'])) { $url = ''; if (isset($this->request->get['category_id'])) { $url .= '&category_id=' . $this->request->get['category_id']; } if (isset($this->request->get['description'])) { $url .= '&description=' . $this->request->get['description']; } $this->document->addBreadcrumb(array('href' => $this->html->getURL('product/search', '&keyword=' . $this->request->get['keyword'] . $url, '&encode'), 'text' => $this->language->get('text_search'), 'separator' => $this->language->get('text_separator'))); } $key = array(); //key of product from cart if (has_value($this->request->get['key'])) { $key = explode(':', $this->request->get['key']); $product_id = (int) $key[0]; } elseif (has_value($this->request->get['product_id'])) { $product_id = (int) $this->request->get['product_id']; } else { $product_id = 0; } $urls = array('is_group_option' => $this->html->getURL('r/product/product/is_group_option', '&product_id=' . $product_id, '&encode')); $this->view->assign('urls', $urls); $this->loadModel('catalog/product'); $promoton = new APromotion(); $product_info = $this->model_catalog_product->getProduct($product_id); //can not locate product? get out if (!$product_info) { $this->_product_not_found($product_id); return null; } $url = $this->_build_url(); $this->view->assign('error', ''); if (isset($this->session->data['error'])) { $this->view->assign('error', $this->session->data['error']); unset($this->session->data['error']); } $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/product', $url . '&product_id=' . $product_id, '&encode'), 'text' => $product_info['name'], 'separator' => $this->language->get('text_separator'))); $this->document->setTitle($product_info['name']); $this->document->setKeywords($product_info['meta_keywords']); $this->document->setDescription($product_info['meta_description']); $this->document->addLink(array('href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, '&encode'), 'rel' => 'canonical')); $this->data['heading_title'] = $product_info['name']; $this->data['minimum'] = $product_info['minimum']; $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']); $this->data['maximum'] = $product_info['maximum']; $this->data['text_maximum'] = sprintf($this->language->get('text_maximum'), $product_info['maximum']); $this->data['option_resources_url'] = $this->html->getURL('r/product/product/get_option_resources'); $this->data['calc_total_url'] = $this->html->getURL('r/product/product/calculateTotal'); $this->data['product_review_url'] = $this->html->getURL('product/review/review', '&product_id=' . $product_id); $this->data['product_review_write_url'] = $this->html->getURL('product/review/write', '&product_id=' . $product_id); $this->data['product_wishlist_add_url'] = $this->html->getURL('product/wishlist/add', '&product_id=' . $product_id); $this->data['product_wishlist_remove_url'] = $this->html->getURL('product/wishlist/remove', '&product_id=' . $product_id); $this->data['captcha_url'] = $this->html->getURL('common/captcha'); $this->loadModel('catalog/review'); $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($product_id)); if ($this->config->get('enable_reviews')) { $average = $this->model_catalog_review->getAverageRating($product_id); } else { $average = false; } $this->data['review_status'] = $this->config->get('enable_reviews'); $this->data['text_stars'] = sprintf($this->language->get('text_stars'), $average); $this->data['rating_element'] = HtmlElementFactory::create(array('type' => 'rating', 'name' => 'rating', 'value' => '', 'options' => array(1 => 1, 2, 3, 4, 5), 'pack' => true)); $this->data['review_name'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'name')); $this->data['review_text'] = HtmlElementFactory::create(array('type' => 'textarea', 'name' => 'text', 'attr' => ' rows="8" cols="50" ')); $this->data['review_captcha'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'captcha', 'attr' => '')); $this->data['review_button'] = HtmlElementFactory::create(array('type' => 'button', 'name' => 'review_submit', 'text' => $this->language->get('button_submit'), 'style' => 'btn-primary', 'icon' => 'fa fa-comment')); $this->data['product_info'] = $product_info; $form = new AForm(); $form->setForm(array('form_name' => 'product')); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'product', 'action' => $this->html->getSecureURL('checkout/cart'))); $product_price = $product_info['price']; $discount = $promoton->getProductDiscount($product_id); if ($discount) { $product_price = $discount; $this->data['price_num'] = $this->tax->calculate($discount, $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); $this->data['special'] = FALSE; } else { $this->data['price_num'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); $special = $promoton->getProductSpecial($product_id); if ($special) { $product_price = $special; $this->data['special_num'] = $this->tax->calculate($special, $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); } else { $this->data['special'] = FALSE; } } $this->data['price'] = $this->currency->format($this->data['price_num']); if (isset($this->data['special_num'])) { $this->data['special'] = $this->currency->format($this->data['special_num']); } $product_discounts = $promoton->getProductDiscounts($product_id); $discounts = array(); foreach ($product_discounts as $discount) { $discounts[] = array('quantity' => $discount['quantity'], 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax')))); } $this->data['discounts'] = $discounts; $this->data['product_price'] = $product_price; $this->data['tax_class_id'] = $product_info['tax_class_id']; if (!$product_info['call_to_order']) { $this->data['form']['minimum'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity', 'value' => $product_info['minimum'] ? (int) $product_info['minimum'] : 1, 'style' => 'short', 'attr' => ' size="3" ')); $this->data['form']['add_to_cart'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'add_to_cart', 'text' => $this->language->get('button_add_to_cart'), 'style' => 'button1')); } $this->data['form']['product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'product_id', 'value' => $product_id)); $this->data['form']['redirect'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'redirect', 'value' => $this->html->getURL('product/product', $url . '&product_id=' . $product_id, '&encode'))); $this->data['model'] = $product_info['model']; $this->data['manufacturer'] = $product_info['manufacturer']; $this->data['manufacturers'] = $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $product_info['manufacturer_id'], '&encode'); $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'); $this->data['product_id'] = $product_id; $this->data['average'] = $average; $resource = new AResource('image'); $thumbnail = $resource->getMainThumb('manufacturers', $product_info['manufacturer_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), true); if (!preg_match('/no_image/', $thumbnail['thumb_url'])) { $this->data['manufacturer_icon'] = $thumbnail['thumb_url']; } // Preapare options and values for display $elements_with_options = HtmlElementFactory::getElementsWithOptions(); $options = array(); $product_options = $this->model_catalog_product->getProductOptions($product_id); //get info from cart if key presents $cart_product_info = array(); if ($key) { $cart_product_info = $this->cart->getProduct($this->request->get['key']); } foreach ($product_options as $option) { $values = array(); $name = $price = ''; $default_value = $cart_product_info['options'][$option['product_option_id']]; if ($option['element_type'] == 'R') { $default_value = is_array($default_value) ? current($default_value) : (string) $default_value; } $preset_value = $default_value; foreach ($option['option_value'] as $option_value) { $default_value = $option_value['default'] && !$default_value ? $option_value['product_option_value_id'] : $default_value; // for case when trying to add to cart withot required options. we get option-array back inside _GET if (has_value($this->request->get['option'][$option['product_option_id']])) { $default_value = $this->request->get['option'][$option['product_option_id']]; } $name = $option_value['name']; //check if we disable options based on out of stock setting if ($option_value['subtract'] && $this->config->get('config_nostock_autodisable') && $option_value['quantity'] <= 0) { continue; } //Apply option price modifier if ($option_value['prefix'] == '%') { $price = $this->tax->calculate($product_price * $option_value['price'] / 100, $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); if ($price != 0) { $price = $this->currency->format($price); } else { $price = ''; } } else { $price = $this->tax->calculate($option_value['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax')); if ($price != 0) { $price = $this->currency->format($price); } else { $price = ''; } } //Check stock and status $opt_stock_message = ''; if ($option_value['subtract']) { if ($option_value['quantity'] <= 0) { //show out of stock message $opt_stock_message = $product_info['stock_status']; } else { if ($this->config->get('config_stock_display')) { $opt_stock_message = $option_value['quantity'] . " " . $this->language->get('text_instock'); } } } $values[$option_value['product_option_value_id']] = $option_value['name'] . ' ' . $price . ' ' . $opt_stock_message; } //if not values are build, nothing to show if (count($values)) { $value = ''; //add price to option name if it is not element with options if (!in_array($option['element_type'], $elements_with_options)) { $option['name'] .= ' <small>' . $price . '</small>'; if ($opt_stock_message) { $option['name'] .= '<br />' . $opt_stock_message; } $value = $default_value ? $default_value : $name; } //set default selection is nothing selected if (!has_value($value)) { if (has_value($default_value)) { $value = $default_value; } else { if (in_array($option['element_type'], $elements_with_options) && $option['element_type'] != 'S') { //set first from the list to default reset($values); $value = key($values); } } } //for checkbox with empty value if ($value == '' && $option['element_type'] == 'C') { $value = 1; } $option_data = array('type' => $option['html_type'], 'name' => !in_array($option['element_type'], HtmlElementFactory::getMultivalueElements()) ? 'option[' . $option['product_option_id'] . ']' : 'option[' . $option['product_option_id'] . '][]', 'value' => $value, 'options' => $values, 'required' => $option['required'], 'placeholder' => $option['option_placeholder'], 'regexp_pattern' => $option['regexp_pattern'], 'error_text' => $option['error_text']); if ($option['element_type'] == 'C') { if (!in_array($value, array('0', '1'))) { $option_data['label_text'] = $value; } $option_data['checked'] = $preset_value ? true : false; } $options[] = array('name' => $option['name'], 'html' => $this->html->buildElement($option_data)); } } $this->data['options'] = $options; //handle stock messages // if track stock is off. no messages needed. if ($this->model_catalog_product->isStockTrackable($product_id)) { $total_quantity = $this->model_catalog_product->hasAnyStock($product_id); $this->data['track_stock'] = true; //out of stock if no quantity and no stick checkout is disabled if ($total_quantity <= 0 && !$this->config->get('config_stock_checkout')) { $this->data['in_stock'] = false; //show out of stock message $this->data['stock'] = $product_info['stock_status']; } else { $this->data['in_stock'] = true; if ($this->config->get('config_stock_display')) { $this->data['stock'] = $product_info['quantity']; } else { $this->data['stock'] = $this->language->get('text_instock'); } } //check if we need to disable product for no stock if ($this->config->get('config_nostock_autodisable') && $total_quantity <= 0) { //set available data $pd_identifiers = "ID: " . $product_id; $pd_identifiers .= empty($product_info['model']) ? '' : " Model: " . $product_info['model']; $pd_identifiers .= empty($product_info['sku']) ? '' : " SKU: " . $product_info['sku']; $message_ttl = sprintf($this->language->get('notice_out_of_stock_ttl'), $product_info['name']); $message_txt = sprintf($this->language->get('notice_out_of_stock_body'), $product_info['name'], $pd_identifiers); //record to message box $msg = new AMessage(); $msg->saveNotice($message_ttl, $message_txt); $this->model_catalog_product->updateStatus($product_id, 0); $this->redirect($this->html->getSEOURL('product/product', '&product_id=' . $product_info['product_id'], '&encode')); } } // main product image $sizes = array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_thumb_width'), 'height' => $this->config->get('config_image_thumb_height'))); $this->data['image_main'] = $resource->getResourceAllObjects('products', $product_id, $sizes, 1, false); if ($this->data['image_main']) { $this->data['image_main']['sizes'] = $sizes; } // additional images $sizes = array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_additional_width'), 'height' => $this->config->get('config_image_additional_height'))); $this->data['images'] = $resource->getResourceAllObjects('products', $product_id, $sizes, 0, false); $products = array(); $results = $this->model_catalog_product->getProductRelated($product_id); foreach ($results as $result) { // related product image $sizes = array('main' => array('width' => $this->config->get('config_image_related_width'), 'height' => $this->config->get('config_image_related_height')), 'thumb' => array('width' => $this->config->get('config_image_related_width'), 'height' => $this->config->get('config_image_related_height'))); $image = $resource->getResourceAllObjects('products', $result['product_id'], $sizes, 1); if ($this->config->get('enable_reviews')) { $rating = $this->model_catalog_review->getAverageRating($result['product_id']); } else { $rating = false; } $special = FALSE; $discount = $promoton->getProductDiscount($result['product_id']); if ($discount) { $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], (bool) $this->config->get('config_tax'))); } else { $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], (bool) $this->config->get('config_tax'))); $special = $promoton->getProductSpecial($result['product_id']); if ($special) { $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], (bool) $this->config->get('config_tax'))); } } $options = $this->model_catalog_product->getProductOptions($result['product_id']); if ($options) { $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'); } else { if ($this->config->get('config_cart_ajax')) { $add = '#'; } else { $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode'); } } $products[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'image' => $image, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add); } $this->data['related_products'] = $products; if ($this->config->get('config_customer_price')) { $display_price = TRUE; } elseif ($this->customer->isLogged()) { $display_price = TRUE; } else { $display_price = FALSE; } $this->data['display_price'] = $display_price; $this->model_catalog_product->updateViewed($product_id); $tags = array(); $results = $this->model_catalog_product->getProductTags($product_id); foreach ($results as $result) { if ($result['tag']) { $tags[] = array('tag' => $result['tag'], 'href' => $this->html->getURL('product/search', '&keyword=' . $result['tag'], '&encode')); } } $this->data['tags'] = $tags; //downloads before order if allowed if ($this->config->get('config_download')) { $dwn = new ADownload(); $download_list = $dwn->getDownloadsBeforeOrder($product_id); if ($download_list) { foreach ($download_list as $download) { $href = $this->html->getURL('account/download/startdownload', '&download_id=' . $download['download_id']); $download['attributes'] = $this->download->getDownloadAttributesValuesForCustomer($download['download_id']); $download['button'] = $form->getFieldHtml(array('type' => 'button', 'id' => 'download_' . $download['download_id'], 'href' => $href, 'title' => $this->language->get('text_start_download'), 'text' => $this->language->get('text_start_download'))); $downloads[] = $download; } $this->data['downloads'] = $downloads; } } #check if product is in a wishlist $this->data['is_customer'] = false; if ($this->customer->isLogged() || $this->customer->isUnauthCustomer()) { $this->data['is_customer'] = true; $whishlist = $this->customer->getWishList(); if ($whishlist[$product_id]) { $this->data['in_wishlist'] = true; } } $this->view->setTemplate('pages/product/product.tpl'); $this->view->batchAssign($this->data); $this->processTemplate(); //init controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
/** * @param int $download_id * @param string $mode - can be "full" - all download attributes (with empty values too), * "to_customer" - download atributes with values that allowed to display for customers, * "to_display" - all download atributes with values * @return array */ public function getDownloadAttributesValues($download_id, $mode = 'full') { if (!(int) $download_id) { return array(); } $output = array(); $attr = new AAttribute('download_attribute'); $attributes = $attr->getAttributes(); $ids = array(); foreach ($attributes as &$attribute) { if ($mode == 'to_customer') { $attribute['settings'] = unserialize($attribute['settings']); if (!$attribute['settings']['show_to_customer']) { continue; } } $ids[] = (int) $attribute['attribute_id']; $attribute['attribute_values'] = $attr->getAttributeValues($attribute['attribute_id']); } unset($attribute); if ($ids) { $result = $this->db->query("SELECT dav.attribute_id, dav.attribute_value_ids as value\n\t\t\t\t\t\t\t\t\t\t FROM " . $this->db->table('download_attribute_values') . " dav\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . $this->db->table('global_attributes') . " ga\n\t\t\t\t\t\t\t\t\t\t ON ga.attribute_id = dav.attribute_id\n\t\t\t\t\t\t\t\t\t\t WHERE dav.attribute_id IN (" . implode(',', $ids) . ") AND dav.download_id = '" . $download_id . "'\n\t\t\t\t\t\t\t\t\t\t ORDER BY ga.sort_order ASC"); $attributes_with_options = HtmlElementFactory::getElementsWithOptions(); foreach ($result->rows as $row) { if (!in_array($row['attribute_id'], $ids)) { continue; } $row['value'] = unserialize($row['value']); if (in_array($attributes[$row['attribute_id']]['element_type'], $attributes_with_options)) { foreach ($attributes[$row['attribute_id']]['attribute_values'] as $values) { if (is_array($row['value']) && in_array($values['attribute_value_id'], $row['value'])) { // do not include empty value for display for customer if (!$row['value'] && in_array($mode, array('to_customer', 'to_display'))) { continue 1; } $output[$attributes[$row['attribute_id']]['name']][] = $values['value']; } elseif (!is_array($row['value']) && $values['attribute_value_id'] == $row['value']) { // do not include empty value for display for customer if (!$row['value'] && in_array($mode, array('to_customer', 'to_display'))) { continue 1; } $output[$attributes[$row['attribute_id']]['name']] = $values['value']; } } } else { // do not include empty value for display for customer or admin display if (!has_value($row['value']) && in_array($mode, array('to_customer', 'to_display'))) { continue; } $output[$attributes[$row['attribute_id']]['name']] = $row['value']; // for checkbox value show text yes or no if ($attributes[$row['attribute_id']]['element_type'] == 'C') { $output[$attributes[$row['attribute_id']]['name']] = $row['value'] ? $this->language->get('text_yes') : $this->language->get('text_no'); } } } } return $output; }
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'); }
/** * @param array $file_data * @param string $tpl */ public function buildDownloadForm($file_data, $tpl) { $this->data = array(); //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('catalog/files'); $this->loadModel('localisation/order_status'); $this->loadModel('catalog/download'); $product_id = $file_data['product_id']; $order_statuses = $this->model_localisation_order_status->getOrderStatuses(); $this->data['date_added'] = dateISO2Display($file_data['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format')); $this->data['date_modified'] = dateISO2Display($file_data['date_modified'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format')); $this->data['action'] = $this->html->getSecureURL('r/product/product/processDownloadForm', '&product_id=' . $product_id); $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('text_product'); $this->data['download_id'] = (int) $file_data['download_id']; if ($this->data['download_id']) { $form = new AForm('HS'); $this->data['update'] = $this->html->getSecureURL('listing_grid/download/update_field', '&id=' . $this->data['download_id']); } else { $form = new AForm('HT'); } $form->setForm(array('form_name' => 'downloadFrm' . $file_data['download_id'], 'update' => $this->data['update'])); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'downloadFrm' . $file_data['download_id'], 'attr' => 'confirm-exit="true"', 'action' => $this->data['action'])); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => (int) $this->data['download_id'] ? $this->language->get('button_save') : $this->language->get('text_add'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id), 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $rl = new AResource('download'); $rl_dir = $rl->getTypeDir(); $resource_id = $rl->getIdFromHexPath(str_replace($rl_dir, '', $file_data['filename'])); $resource_info = $rl->getResource($resource_id); $thumbnail = $rl->getResourceThumb($resource_id, 30, 30); if ($resource_info['resource_path']) { $this->data['icon'] = $this->html->buildResourceImage(array('url' => $thumbnail, 'width' => 30, 'height' => 30, 'attr' => 'alt="' . $resource_info['title'] . '"')); } else { $this->data['icon'] = $resource_info['resource_code']; } if ($resource_id) { $this->data['preview']['href'] = $this->html->getSecureURL('common/resource_library/get_resource_preview', '&resource_id=' . $resource_id, true); $this->data['preview']['path'] = 'resources/' . $file_data['filename']; } $r = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'download', 'wrapper_id' => 'download_' . (int) $this->data['download_id'], 'resource_id' => $resource_id, 'field' => 'download_rl_path_' . $this->data['download_id'])); $this->data['resource'] = $r->dispatchGetOutput(); $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'downloads', 'object_id' => (int) $this->data['download_id'], 'types' => 'download', 'mode' => 'url')); $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput(); $this->data['form']['fields']['download_rl_path'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_rl_path_' . $this->data['download_id'], 'value' => htmlspecialchars($file_data['filename'], ENT_COMPAT, 'UTF-8'))); $this->data['form']['fields']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => 1, 'checked' => $file_data['status'] ? true : false, 'style' => 'btn_switch')); $orders_count = $this->model_catalog_download->getTotalOrdersWithProduct($product_id); if ($orders_count) { $this->data['push_to_customers'] = $this->html->buildElement(array('type' => 'button', 'name' => 'push_to_customers', 'title' => sprintf($this->language->get('text_push_to_orders'), $orders_count), 'text' => $this->language->get('text_push'), 'href' => $this->html->getSecureURL('r/product/product/pushToCustomers', '&product_id=' . $product_id . '&download_id=' . $this->data['download_id']), 'style' => 'button2', 'attr' => 'data-orders-count="' . $orders_count . '"')); } $this->data['maplist'] = array(); $file_data['map_list'] = (array) $file_data['map_list']; foreach ($file_data['map_list'] as $map_id => $map_name) { if ($map_id == $product_id) { continue; } $this->data['maplist'][] = array('href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $map_id . '&download_id=' . $this->data['download_id'], true), 'text' => $map_name); } if (!sizeof($this->data['maplist'])) { $this->data['already_shared'] = false; } else { $this->data['already_shared'] = true; } $this->data['delete_unmap_href'] = $this->html->getSecureURL('catalog/product_files', '&act=' . ($file_data['shared'] ? 'unmap' : 'delete') . '&product_id=' . $product_id . '&download_id=' . $this->data['download_id'], true); $this->data['form']['fields']['shared'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'shared', 'value' => $file_data['shared'], 'attr' => $this->data['already_shared'] ? ' disabled=disabled' : '')); if ($file_data['shared']) { $this->data['text_attention_shared'] = $this->language->get('attention_shared'); } $this->data['form']['fields']['download_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'download_id', 'value' => $this->data['download_id'])); $this->data['form']['fields']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $file_data['name'], 'attr' => ' maxlength="64" ')); $this->data['form']['fields']['mask'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'mask', 'value' => $file_data['mask'])); $this->data['form']['fields']['max_downloads'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'max_downloads', 'value' => $file_data['max_downloads'], 'style' => 'small-field')); $this->data['form']['fields']['activate'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate', 'value' => $file_data['activate'], 'options' => array('' => $this->language->get('text_select'), 'before_order' => $this->language->get('text_before_order'), 'immediately' => $this->language->get('text_immediately'), 'order_status' => $this->language->get('text_on_order_status'), 'manually' => $this->language->get('text_manually')), 'required' => true, 'style' => 'download_activate no-save')); $options = array('' => $this->language->get('text_select')); foreach ($order_statuses as $order_status) { $options[$order_status['order_status_id']] = $order_status['name']; } $this->data['form']['fields']['order_statuses'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'activate_order_status_id', 'value' => $file_data['activate_order_status_id'], 'options' => $options, 'required' => true, 'style' => 'no-save')); $this->data['form']['fields']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'style' => 'small-field', 'value' => $file_data['sort_order'])); $this->data['form']['fields']['expire_days'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'expire_days', 'style' => 'small-field', 'value' => $file_data['expire_days'])); /* * DOWNLOAD ATTRIBUTES PIECE OF FORM * */ $attributes = $this->model_catalog_download->getDownloadAttributes($this->data['download_id']); $elements = HtmlElementFactory::getAvailableElements(); $html_multivalue_elements = HtmlElementFactory::getMultivalueElements(); $html_elements_with_options = HtmlElementFactory::getElementsWithOptions(); if (!$attributes) { $attr_mng = new AAttribute_Manager('download_attribute'); $attr_type_id = $attr_mng->getAttributeTypeID('download_attribute'); $this->data['text_no_download_attributes_yet'] = sprintf($this->language->get('text_no_download_attributes_yet'), $this->html->getSecureURL('catalog/attribute/insert', '&attribute_type_id=' . $attr_type_id)); } else { foreach ($attributes as $attribute) { $html_type = $elements[$attribute['element_type']]['type']; if (!$html_type || !$attribute['status']) { continue; } $values = $value = array(); //values that was setted if (in_array($attribute['element_type'], $html_elements_with_options) && $attribute['element_type'] != 'R') { if (is_array($attribute['selected_values'])) { foreach ($attribute['selected_values'] as $val) { $value[$val] = $val; } } else { $value = $attribute['selected_values']; } } else { if (isset($attribute['selected_values'])) { $value = $attribute['selected_values']; if ($attribute['element_type'] == 'R' && is_array($value)) { $value = current($value); } } else { $value = $attribute['values'][0]['value']; } } // possible values foreach ($attribute['values'] as $val) { $values[$val['attribute_value_id']] = $val['value']; } if (!in_array($attribute['element_type'], $html_multivalue_elements)) { $option_name = 'attributes[' . $this->data['download_id'] . '][' . $attribute['attribute_id'] . ']'; } else { $option_name = 'attributes[' . $this->data['download_id'] . '][' . $attribute['attribute_id'] . '][' . $attribute['attribute_value_id'] . ']'; } $disabled = ''; $required = $attribute['required']; $option_data = array('type' => $html_type, 'name' => $option_name, 'value' => $value, 'options' => $values, 'required' => $required, 'attr' => $disabled, 'style' => 'large-field'); if ($html_type == 'checkboxgroup') { $option_data['scrollbox'] = true; } $this->data['entry_attribute_' . $this->data['download_id'] . '_' . $attribute['attribute_id']] = $attribute['name']; $this->data['attributes'][$this->data['download_id'] . '_' . $attribute['attribute_id']] = $form->getFieldHtml($option_data); } } // for new download - create form for mapping shared downloads to product if (!$file_data['download_id']) { if (!$this->registry->has('jqgrid_script')) { $locale = $this->session->data['language']; if (!file_exists(DIR_ROOT . '/' . RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js')) { $locale = 'en'; } $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.jqGrid.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/plugins/jquery.grid.fluid.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.ba-bbq.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/grid.history.js'); //set flag to not include scripts/css twice $this->registry->set('jqgrid_script', true); } $form0 = new AForm('ST'); $form0->setForm(array('form_name' => 'SharedFrm' . $file_data['download_id'], 'update' => $this->data['update'])); $this->data['form0']['form_open'] = $form0->getFieldHtml(array('type' => 'form', 'name' => 'SharedFrm' . $file_data['download_id'], 'attr' => 'confirm-exit="true"', 'action' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id))); // exclude this product from multivalue list. why we need relate recursion? $this->session->data['multivalue_excludes']['product_id'] = $this->request->get['product_id']; $this->data['form0']['fields']['list_hidden'] = $form0->getFieldHtml(array('id' => 'popup', 'type' => 'multivalue', 'name' => 'popup', 'title' => $this->language->get('text_select_from_list'), 'selected' => $listing_data ? AJson::encode($listing_data) : "{}", 'content_url' => $this->html->getSecureUrl('catalog/download_listing', '&shared_only=1&form_name=SharedFrm' . $file_data['download_id'] . '&multivalue_hidden_id=popup'), 'postvars' => '', 'return_to' => '', 'popup_height' => 708, 'text' => array('selected' => $this->language->get('text_count_selected'), 'edit' => $this->language->get('text_save_edit'), 'apply' => $this->language->get('text_apply'), 'save' => $this->language->get('button_save'), 'reset' => $this->language->get('button_reset')))); } $this->view->batchAssign($this->data); $this->processTemplate($tpl); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }