/**
  * @param int $manufacturer_id
  * @param array $data
  */
 public function editManufacturer($manufacturer_id, $data)
 {
     $fields = array('name', 'sort_order');
     $update = array();
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE " . $this->db->table("manufacturers") . " SET " . implode(',', $update) . " WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
     }
     if (isset($data['manufacturer_store'])) {
         $this->db->query("DELETE FROM " . $this->db->table("manufacturers_to_stores") . " WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
         foreach ($data['manufacturer_store'] as $store_id) {
             $this->db->query("INSERT INTO " . $this->db->table("manufacturers_to_stores") . " SET manufacturer_id = '" . (int) $manufacturer_id . "', store_id = '" . (int) $store_id . "'");
         }
     }
     if (isset($data['keyword'])) {
         $data['keyword'] = SEOEncode($data['keyword'], 'manufacturer_id', $manufacturer_id);
         if ($data['keyword']) {
             $this->language->replaceDescriptions('url_aliases', array('query' => "manufacturer_id=" . (int) $manufacturer_id), array((int) $this->session->data['content_language_id'] => array('keyword' => $data['keyword'])));
         } else {
             $this->db->query("DELETE\n\t\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\t\tWHERE query = 'manufacturer_id=" . (int) $manufacturer_id . "'\n\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->session->data['content_language_id'] . "'");
         }
     }
     $this->cache->delete('manufacturer');
 }
Пример #2
0
 /**
  * function for getting auto-generated unique seo keyword
  */
 public function getSeoKeyword()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $seo_key = SEOEncode($this->request->get['seo_name'], $this->request->get['object_key_name'], (int) $this->request->get['id'], (int) $this->language->getContentLanguageID());
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->response->setOutput($seo_key);
 }
Пример #3
0
 /**
  * @param int $product_id
  * @param array $data
  */
 public function updateProduct($product_id, $data)
 {
     $fields = array("model", "sku", "location", "quantity", "minimum", "maximum", "subtract", "stock_status_id", "date_available", "manufacturer_id", "shipping", "ship_individually", "free_shipping", "shipping_price", "call_to_order", "price", "cost", "weight", "weight_class_id", "length", "width", "height", "length_class_id", "status", "tax_class_id", "sort_order");
     $preformat_fields = array("shipping_price", "price", "cost", "weight", "length", "width", "height");
     $update = array('date_modified = NOW()');
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             if (in_array($f, $preformat_fields)) {
                 $data[$f] = preformatFloat($data[$f], $this->language->get('decimal_point'));
             }
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE `" . $this->db->table("products`") . " SET " . implode(',', $update) . " WHERE product_id = '" . (int) $product_id . "'");
     }
     if (!empty($data['product_description'])) {
         foreach ($data['product_description'] as $field => $value) {
             $fields = array('name', 'description', 'meta_keywords', 'meta_description', 'blurb');
             $update = array();
             foreach ($fields as $f) {
                 if ($f == $field) {
                     $update[$f] = $value;
                 }
             }
             if (!empty($update)) {
                 $this->language->replaceDescriptions('product_descriptions', array('product_id' => (int) $product_id), array((int) $this->language->getContentLanguageID() => $update));
             }
         }
     }
     if (isset($data['featured'])) {
         $this->setFeatured($product_id, $data['featured'] ? true : false);
     }
     if (isset($data['keyword'])) {
         $data['keyword'] = SEOEncode($data['keyword'], 'product_id', $product_id);
         if ($data['keyword']) {
             $this->language->replaceDescriptions('url_aliases', array('query' => "product_id=" . (int) $product_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $data['keyword'])));
         } else {
             $this->db->query("DELETE\n\t\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\t\tWHERE query = 'product_id=" . (int) $product_id . "'\n\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
         }
     }
     if (isset($data['product_tags'])) {
         $language_id = $this->language->getContentLanguageID();
         $tags = explode(',', $data['product_tags']);
         foreach ($tags as &$tag) {
             $tag = $this->db->escape(trim($tag));
         }
         $this->language->replaceMultipleDescriptions('product_tags', array('product_id' => (int) $product_id), array((int) $language_id => array('tag' => array_unique($tags))));
     }
     $this->cache->remove('product');
 }
Пример #4
0
 /**
  * function returns text error or empty
  * @param string $query
  * @param string $keyword
  * @return string
  */
 public function isSEOkeywordExists($query, $keyword = '')
 {
     if (!$keyword) {
         return '';
     }
     $seo_key = SEOEncode($keyword);
     $db = $this->registry->get('db');
     $sql = "SELECT * FROM " . DB_PREFIX . "url_aliases WHERE query<>'" . $db->escape($query) . "' AND keyword='" . $db->escape($seo_key) . "'";
     $result = $db->query($sql);
     if ($result->num_rows) {
         $url = HTTP_CATALOG . $seo_key;
         return sprintf($this->registry->get('language')->get('error_seo_keyword'), $url, $seo_key);
     }
     return '';
 }
Пример #5
0
 private function _getForm()
 {
     $this->view->assign('error_warning', $this->error['warning']);
     $this->view->assign('error_name', $this->error['name']);
     $this->data['categories'] = $this->model_catalog_category->getCategories(0);
     $categories = array(0 => $this->language->get('text_none'));
     foreach ($this->data['categories'] as $c) {
         $categories[$c['category_id']] = $c['name'];
     }
     if (isset($this->request->get['category_id'])) {
         $category_id = $this->request->get['category_id'];
         $this->data['category_id'] = $category_id;
         unset($categories[$category_id]);
     }
     $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/category'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->view->assign('cancel', $this->html->getSecureURL('catalog/category'));
     if ($category_id && $this->request->is_GET()) {
         $category_info = $this->model_catalog_category->getCategory($category_id);
     }
     foreach ($this->fields as $f) {
         if (isset($this->request->post[$f])) {
             $this->data[$f] = $this->request->post[$f];
         } elseif (isset($category_info) && isset($category_info[$f])) {
             $this->data[$f] = $category_info[$f];
         } else {
             $this->data[$f] = '';
         }
     }
     if (isset($this->request->post['category_description'])) {
         $this->data['category_description'] = $this->request->post['category_description'];
     } elseif (isset($category_info)) {
         $this->data['category_description'] = $this->model_catalog_category->getCategoryDescriptions($category_id);
     } else {
         $this->data['category_description'] = array();
     }
     if ($this->data['status'] == '') {
         $this->data['status'] = 1;
     }
     if ($this->data['parent_id'] == '') {
         $this->data['parent_id'] = 0;
     }
     $this->loadModel('setting/store');
     $this->data['stores'] = $this->model_setting_store->getStores();
     if (isset($this->request->post['category_store'])) {
         $this->data['category_store'] = $this->request->post['category_store'];
     } elseif (isset($category_info)) {
         $this->data['category_store'] = $this->model_catalog_category->getCategoryStores($category_id);
     } else {
         $this->data['category_store'] = array(0);
     }
     $stores = array(0 => $this->language->get('text_default'));
     foreach ($this->data['stores'] as $s) {
         $stores[$s['store_id']] = $s['name'];
     }
     if (!$category_id) {
         $this->data['action'] = $this->html->getSecureURL('catalog/category/insert');
         $this->data['heading_title'] = $this->language->get('text_insert') . ' ' . $this->language->get('text_category');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('catalog/category/update', '&category_id=' . $category_id);
         $this->data['heading_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('text_category') . ' - ' . $this->data['category_description'][$this->session->data['content_language_id']]['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/category/update_field', '&id=' . $category_id);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: ', 'current' => true));
     $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' => 'data-confirm-exit="true" class="aform form-horizontal"', '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']['general']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => $this->data['status'], 'style' => 'btn_switch', 'help_url' => $this->gen_help_url('status')));
     $this->data['form']['fields']['general']['parent_category'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'parent_id', 'value' => $this->data['parent_id'], 'options' => $categories, 'style' => 'chosen'));
     $this->data['form']['fields']['general']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'category_description[' . $this->session->data['content_language_id'] . '][name]', 'value' => $this->data['category_description'][$this->session->data['content_language_id']]['name'], 'required' => true, 'style' => 'large-field', 'attr' => ' maxlength="255" ', 'help_url' => $this->gen_help_url('name')));
     $this->data['form']['fields']['general']['description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'category_description[' . $this->session->data['content_language_id'] . '][description]', 'value' => $this->data['category_description'][$this->session->data['content_language_id']]['description'], 'style' => 'xl-field', 'help_url' => $this->gen_help_url('description')));
     $this->data['form']['fields']['data']['meta_keywords'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'category_description[' . $this->session->data['content_language_id'] . '][meta_keywords]', 'value' => $this->data['category_description'][$this->session->data['content_language_id']]['meta_keywords'], 'style' => 'xl-field', 'help_url' => $this->gen_help_url('meta_keywords')));
     $this->data['form']['fields']['data']['meta_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'category_description[' . $this->session->data['content_language_id'] . '][meta_description]', 'value' => $this->data['category_description'][$this->session->data['content_language_id']]['meta_description'], 'style' => 'xl-field', 'help_url' => $this->gen_help_url('meta_description')));
     $this->data['keyword_button'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'generate_seo_keyword', 'text' => $this->language->get('button_generate'), 'attr' => 'type="button"', 'style' => 'btn btn-info'));
     $this->data['generate_seo_url'] = $this->html->getSecureURL('common/common/getseokeyword', '&object_key_name=category_id&id=' . $category_id);
     $this->data['form']['fields']['data']['keyword'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'keyword', 'value' => $this->data['keyword'], 'help_url' => $this->gen_help_url('seo_keyword'), 'attr' => ' gen-value="' . SEOEncode($this->data['category_description']['name']) . '" '));
     $this->data['form']['fields']['data']['store'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'category_store[]', 'value' => $this->data['category_store'], 'options' => $stores, 'style' => 'chosen'));
     $this->data['form']['fields']['data']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['sort_order'], 'style' => 'small-field'));
     $this->data['active'] = 'general';
     //load tabs controller
     $tabs_obj = $this->dispatch('pages/catalog/category_tabs', array($this->data));
     $this->data['category_tabs'] = $tabs_obj->dispatchGetOutput();
     unset($tabs_obj);
     if ($category_id && $this->config->get('config_embed_status')) {
         $this->data['embed_url'] = $this->html->getSecureURL('common/do_embed/categories', '&category_id=' . $category_id);
     }
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('language_id', $this->session->data['content_language_id']);
     $this->view->assign('language_code', $this->session->data['language']);
     $this->addChild('responses/common/resource_library/get_resources_html', 'resources_html', 'responses/common/resource_library_scripts.tpl');
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'categories', 'object_id' => $category_id, 'types' => array('image')));
     $this->view->assign('current_url', $this->html->currentURL());
     $this->view->assign('resources_scripts', $resources_scripts->dispatchGetOutput());
     $this->view->assign('rl', $this->html->getSecureURL('common/resource_library', '&object_name=&object_id&type=image&mode=single'));
     $this->processTemplate('pages/catalog/category_form.tpl');
 }
Пример #6
0
 /**
  * @param int $category_id
  * @param array $data
  */
 public function editCategory($category_id, $data)
 {
     $fields = array('parent_id', 'sort_order', 'status');
     $update = array('date_modified = NOW()');
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE " . $this->db->table("categories") . " SET " . implode(',', $update) . " WHERE category_id = '" . (int) $category_id . "'");
     }
     if (!empty($data['category_description'])) {
         foreach ($data['category_description'] as $language_id => $value) {
             $update = array();
             if (isset($value['name'])) {
                 $update["name"] = $value['name'];
             }
             if (isset($value['description'])) {
                 $update["description"] = $value['description'];
             }
             if (isset($value['meta_keywords'])) {
                 $update["meta_keywords"] = $value['meta_keywords'];
             }
             if (isset($value['meta_description'])) {
                 $update["meta_description"] = $value['meta_description'];
             }
             if (!empty($update)) {
                 // insert or update
                 $this->language->replaceDescriptions('category_descriptions', array('category_id' => (int) $category_id), array($language_id => $update));
             }
         }
     }
     if (isset($data['category_store'])) {
         $this->db->query("DELETE FROM " . $this->db->table("categories_to_stores") . " WHERE category_id = '" . (int) $category_id . "'");
         foreach ($data['category_store'] as $store_id) {
             $this->db->query("INSERT INTO " . $this->db->table("categories_to_stores") . " SET category_id = '" . (int) $category_id . "', store_id = '" . (int) $store_id . "'");
         }
     }
     if (isset($data['keyword'])) {
         $data['keyword'] = SEOEncode($data['keyword']);
         if ($data['keyword']) {
             $this->language->replaceDescriptions('url_aliases', array('query' => "category_id=" . (int) $category_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $data['keyword'])));
         } else {
             $this->db->query("DELETE\n\t\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\t\tWHERE query = 'category_id=" . (int) $category_id . "'\n\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
         }
     }
     $this->cache->delete('category');
 }
Пример #7
0
 protected function migrateProducts()
 {
     $this->load->model('tool/image');
     $language_id = $this->getDefaultLanguageId();
     $store_id = $this->config->get('config_store_id');
     $category_id_map = array();
     $manufacturer_id_map = array();
     $products = $this->cartObj->getProducts();
     if (!$products) {
         $errors = $this->cartObj->getErrors();
         $class = 'error';
         if (!$errors) {
             $errors = $this->language->get('text_no_products');
             $class = 'attention';
         }
         $this->addLog($errors, $class);
     }
     $categories = $this->cartObj->getCategories();
     if (!$categories) {
         $errors = $this->cartObj->getErrors();
         $class = 'error';
         if (!$errors) {
             $errors = $this->language->get('text_no_categories');
             $class = 'attention';
         }
         $this->addLog($errors, $class);
     }
     $manufacturers = $this->cartObj->getManufacturers();
     if (!$manufacturers) {
         $errors = $this->cartObj->getErrors();
         $class = 'error';
         if (!$errors) {
             $errors = $this->language->get('text_no_brands');
             $class = 'attention';
         }
         $this->addLog($errors, $class);
     }
     // import categories
     $categories = $this->cartObj->getCategories();
     $this->pic_count = 0;
     foreach ($categories as $data) {
         $data['name'] = strip_tags($data['name']);
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "categories\n                                        SET parent_id = '" . (int) $data['parent_id'] . "',\n                                            sort_order = '" . (int) $data['sort_order'] . "',\n                                            status = '1',\n                                            date_modified = NOW(),\n                                            date_added = NOW()", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         $category_id = $this->db->getLastId();
         $category_id_map[$data['category_id']] = $category_id;
         //IMAGE PROCESSING
         $this->_migrateImages($data, 'categories', $category_id);
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "category_descriptions\n\t\t\t\t\t \t\t\t\t     SET category_id = '" . (int) $category_id . "',\n\t\t\t\t\t\t\t\t\t\t     language_id = '" . (int) $language_id . "',\n\t\t\t\t\t\t\t\t\t\t     name = '" . $this->db->escape($data['name']) . "',\n\t\t\t\t\t\t\t\t\t\t     description = '" . $this->db->escape($data['description']) . "'", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "categories_to_stores\n\t\t\t\t\t\t\t\t\t\t   (category_id,store_id)\n\t\t\t\t\t\t\t\t\t\t VALUES ('" . (int) $category_id . "','" . (int) $store_id . "')", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
     }
     //update parent id according to new map
     $query = $this->db->query("SELECT category_id, parent_id FROM " . DB_PREFIX . "categories ");
     foreach ($query->rows as $result) {
         if (empty($category_id_map[$result['parent_id']])) {
             continue;
         }
         $result = $this->db->query("UPDATE " . DB_PREFIX . "categories\n\t\t\t\t\t\t\t\t\t\t    SET parent_id = '" . $category_id_map[$result['parent_id']] . "'\n\t\t\t\t\t\t\t\t\t\t    WHERE category_id = '" . (int) $result['category_id'] . "'", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
     }
     $this->addLog(count($categories) . ' categories imported (' . $this->pic_count . ' pictures)', 'success');
     // import manufacturers
     $this->pic_count = 0;
     foreach ($manufacturers as $data) {
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "manufacturers\n                                        SET name = '" . $this->db->escape($data['name']) . "'", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         $manufacturer_id = $this->db->getLastId();
         $manufacturer_id_map[$data['manufacturer_id']] = $manufacturer_id;
         //IMAGE PROCESSING
         $this->_migrateImages($data, 'manufacturers', $manufacturer_id);
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "manufacturers_to_stores\n                                        SET manufacturer_id = '" . (int) $manufacturer_id . "', store_id = '" . (int) $store_id . "'", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
     }
     $this->addLog(count($manufacturers) . ' brands imported (' . $this->pic_count . ' pictures)', 'success');
     // import products
     $this->pic_count = 0;
     foreach ($products as $data) {
         $data['manufacturer_id'] = empty($manufacturer_id_map[$data['manufacturer_id']]) ? '' : $manufacturer_id_map[$data['manufacturer_id']];
         $date_added = has_value($data['date_added']) ? "'" . $this->db->escape($data['date_added']) . "'" : 'NOW()';
         $date_modified = has_value($data['date_modified']) ? "'" . $this->db->escape($data['date_modified']) . "'" : 'NOW()';
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "products\n\t\t\t\t\t\t\t\t\t\tSET model = '" . $this->db->escape($data['model']) . "',\n\t\t\t\t\t\t\t\t\t\t\tsku\t= '" . $this->db->escape($data['sku']) . "',\n\t\t\t\t\t\t\t\t\t\t\tlocation = '" . $this->db->escape($data['location']) . "',\n\t\t\t\t\t\t\t\t\t\t\tquantity = '" . (int) $data['quantity'] . "',\n\t\t\t\t\t\t\t\t\t\t\tstock_status_id = '" . (int) $data['stock_status_id'] . "',\n\t\t\t\t\t\t\t\t\t\t\tdate_available = '" . $this->db->escape($data['date_available']) . "',\n\t\t\t\t\t\t\t\t\t\t\tmanufacturer_id = '" . (int) $data['manufacturer_id'] . "',\n\t\t\t\t\t\t\t\t\t\t\tshipping = '" . (int) $data['shipping'] . "',\n\t\t\t\t\t\t\t\t\t\t\tprice = '" . (double) $data['price'] . "',\n\t\t\t\t\t\t\t\t\t\t\tweight = '" . (double) $data['weight'] . "',\n\t\t\t\t\t\t\t\t\t\t\tweight_class_id = '" . (int) $data['weight_class_id'] . "',\n\t\t\t\t\t\t\t\t\t\t\tlength = '" . (double) $data['length'] . "',\n\t\t\t\t\t\t\t\t\t\t\tlength_class_id = '" . (int) $data['length_class_id'] . "',\n\t\t\t\t\t\t\t\t\t\t\theight = '" . (double) $data['height'] . "',\n\t\t\t\t\t\t\t\t\t\t\tstatus = '" . (int) $data['status'] . "',\n\t\t\t\t\t\t\t\t\t\t\tviewed = '" . (int) $data['viewed'] . "',\n\t\t\t\t\t\t\t\t\t\t\tminimum = '" . (int) $data['minimum'] . "',\n\t\t\t\t\t\t\t\t\t\t\tsubtract = '" . (int) $data['subtract'] . "',\n\t\t\t\t\t\t\t\t\t\t\ttax_class_id = '" . (int) $data['tax_class_id'] . "',\n\t\t\t\t\t\t\t\t\t\t\tsort_order = '" . (int) $data['sort_order'] . "',\n\t\t\t\t\t\t\t\t\t\t\tdate_added = " . $date_added . ",\n\t\t\t\t\t\t\t\t\t\t\tdate_modified = " . $date_modified . "", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         $product_id = $this->db->getLastId();
         $product_id_map[$data['product_id']] = $product_id;
         $product_prices_map[$data['product_id']] = (double) $data['price'];
         //IMAGE PROCESSING
         $this->_migrateImages($data, 'products', $product_id);
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "product_descriptions\n\t\t\t\t\t\t\t\t\t\t  SET product_id = '" . (int) $product_id . "',\n\t\t\t\t\t\t\t\t\t\t  \t  language_id = '" . (int) $language_id . "',\n\t\t\t\t\t\t\t\t\t\t\t  name = '" . $this->db->escape($data['name']) . "',\n\t\t\t\t\t\t\t\t\t\t\t  meta_keywords = '" . $this->db->escape($data['meta_keyword']) . "',\n\t\t\t\t\t\t\t\t\t\t\t  meta_description = '" . $this->db->escape($data['meta_description']) . "',\n\t\t\t\t\t\t\t\t\t\t\t  description = '" . $this->db->escape($data['description']) . "'", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         // add seo keyword
         if ($this->config->get('enable_seo_url')) {
             if (!$data['seo_keyword']) {
                 $seo_key = SEOEncode($data['name'], 'product_id', $product_id);
             } else {
                 $seo_key = SEOEncode($data['seo_keyword'], 'product_id', $product_id);
             }
             $this->language->replaceDescriptions('url_aliases', array('query' => "product_id=" . (int) $product_id), array((int) $language_id => array('keyword' => $seo_key)));
         }
         $result = $this->db->query("INSERT INTO " . DB_PREFIX . "products_to_stores\n\t\t\t                              SET product_id = '" . (int) $product_id . "', store_id = '" . (int) $store_id . "'", true);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         if (isset($data['product_category'])) {
             foreach ($data['product_category'] as $category_id) {
                 if (!(int) $category_id_map[$category_id]) {
                     continue;
                 }
                 $result = $this->db->query("INSERT INTO " . DB_PREFIX . "products_to_categories\n                                                    (product_id,category_id)\n                                                VALUES ('" . (int) $product_id . "', '" . (int) $category_id_map[$category_id] . "')", true);
                 if ($result === false) {
                     $this->addLog($this->db->error);
                 }
             }
         }
         // products review
         if ($data['reviews']) {
             foreach ($data['reviews'] as $review) {
                 if (!(int) $product_id_map[(int) $review['product_id']]) {
                     continue;
                 }
                 $sql = "INSERT INTO " . DB_PREFIX . "reviews\n\t                                             (`product_id`, `customer_id`, `author`,\n\t                                             `text`,`rating`,`status`,`date_added`,`date_modified`)\n\t                                            VALUES ('" . (int) $product_id_map[$review['product_id']] . "',\n\t                                            \t\t'" . (int) $customer_id_map[$data['review_customer_id']] . "',\n\t                                            \t\t'" . $this->db->escape($review['review_author']) . "',\n\t                                            \t\t'" . $this->db->escape($review['review_text']) . "',\n\t                                            \t\t'" . (int) $review['review_rating'] . "',\n\t                                            \t\t'" . (int) $review['review_status'] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($review['review_date_added']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($review['review_date_modified']) . "'\n\t                                            \t\t);";
                 $result = $this->db->query($sql, true);
                 if ($result === false) {
                     $this->addLog($this->db->error);
                 }
             }
         }
     }
     //end of product foreach
     if (method_exists($this->cartObj, 'getProductOptions')) {
         $options = $this->cartObj->getProductOptions();
     }
     $options['product_options'] = (array) $options['product_options'];
     foreach ($options['product_options'] as $product_option) {
         //options
         $required = has_value($product_option['required']) ? $product_option['required'] : 0;
         $sql = "INSERT INTO " . DB_PREFIX . "product_options (product_id, sort_order,status,element_type,required)\n\t\t\t\t\tVALUES('" . $product_id_map[$product_option['product_id']] . "','" . $product_option['sort_order'] . "','1','" . $this->db->escape($product_option['element_type']) . "', '" . (int) $required . "');";
         $result = $this->db->query($sql);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         $product_option_id = $this->db->getLastId();
         $key = $product_option['product_id'] . '_' . $product_option['product_option_id'];
         $key = empty($product_option['product_option_id']) ? $product_option['product_id'] . '_new_' . $product_option['products_text_attributes_id'] : $key;
         $product_option_id_map[$key] = $product_option_id;
         //option description
         $sql = "INSERT INTO " . DB_PREFIX . "product_option_descriptions (product_option_id, language_id, product_id, name)\n\t\t\t\t\tVALUES('" . $product_option_id . "', 1, '" . $product_id_map[$product_option['product_id']] . "','" . $this->db->escape($product_option['product_option_name']) . "');";
         $result = $this->db->query($sql);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
     }
     $options['product_option_values'] = (array) $options['product_option_values'];
     //option value
     foreach ($options['product_option_values'] as $product_option_value) {
         $opt_price = 0;
         if ($product_option_value['price_prefix'] == '+') {
             $opt_price = $product_option_value['price'];
         } else {
             if ($product_option_value['price_prefix'] == '-') {
                 $opt_price = '-' . $product_option_value['price'];
             }
         }
         $key = $product_option_value['product_id'] . '_' . $product_option_value['product_option_id'];
         if ($product_option_value['products_text_attributes_id']) {
             $key = $product_option_value['product_id'] . '_new_' . $product_option_value['products_text_attributes_id'];
         }
         $sql = "INSERT INTO " . DB_PREFIX . "product_option_values (product_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tproduct_option_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tprice,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tquantity,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tweight,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tprefix)\n\t\t\t\t\tVALUES('" . $product_id_map[$product_option_value['product_id']] . "',\n\t\t\t\t\t'" . $product_option_id_map[$key] . "',\n\t\t\t\t\t'" . $opt_price . "',\n\t\t\t\t\t'" . $product_option_value['quantity'] . "',\n\t\t\t\t\t'" . $product_option_value['weight'] . "',\n\t\t\t\t\t'\$');";
         $result = $this->db->query($sql);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
         $product_option_value_id = $this->db->getLastId();
         $product_option_value_id_map[$product_option_value['product_option_value_id']] = $product_option_value_id;
         $sql = "INSERT INTO " . DB_PREFIX . "product_option_value_descriptions (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tproduct_option_value_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlanguage_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tproduct_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname)\n\t\t\t\t\tVALUES(\n\t\t\t\t\t'" . $product_option_value_id . "',\n\t\t\t\t\t'1',\n\t\t\t\t\t'" . $product_id_map[$product_option_value['product_id']] . "',\n\t\t\t\t\t'" . $this->db->escape($product_option_value['product_option_value_name']) . "');";
         $this->db->query($sql);
         if ($result === false) {
             $this->addLog($this->db->error);
         }
     }
     $this->addLog(count($products) . ' products imported (' . $this->pic_count . ' pictures)', 'success');
     return true;
 }
Пример #8
0
 private function _getForm()
 {
     if (isset($this->request->get['product_id']) && $this->request->is_GET()) {
         $product_id = $this->request->get['product_id'];
         $product_info = $this->model_catalog_product->getProduct($product_id);
         $product_info['featured'] = $product_info['featured'] ? 1 : 0;
     }
     $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($product_id);
     $this->data['error'] = $this->error;
     $this->data['cancel'] = $this->html->getSecureURL('catalog/product');
     $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/product'), 'text' => $product_id ? $this->language->get('text_edit') . '&nbsp;' . $this->language->get('text_product') . ' - ' . $this->data['product_description'][$this->session->data['content_language_id']]['name'] : $this->language->get('text_insert'), 'separator' => ' :: ', 'current' => true));
     $this->loadModel('catalog/category');
     $this->data['categories'] = array();
     $results = $this->model_catalog_category->getCategories(0, $this->session->data['current_store_id']);
     foreach ($results as $r) {
         $this->data['categories'][$r['category_id']] = $r['name'];
     }
     $this->loadModel('setting/store');
     $this->data['stores'] = array(0 => $this->language->get('text_default'));
     $results = $this->model_setting_store->getStores();
     foreach ($results as $r) {
         $this->data['stores'][$r['store_id']] = $r['name'];
     }
     $this->loadModel('catalog/manufacturer');
     $this->data['manufacturers'] = array(0 => $this->language->get('text_none'));
     $results = $this->model_catalog_manufacturer->getManufacturers();
     foreach ($results as $r) {
         $this->data['manufacturers'][$r['manufacturer_id']] = $r['name'];
     }
     $this->loadModel('localisation/stock_status');
     $this->data['stock_statuses'] = array();
     $results = $this->model_localisation_stock_status->getStockStatuses();
     foreach ($results as $r) {
         $this->data['stock_statuses'][$r['stock_status_id']] = $r['name'];
     }
     $this->loadModel('localisation/tax_class');
     $this->data['tax_classes'] = array(0 => $this->language->get('text_none'));
     $results = $this->model_localisation_tax_class->getTaxClasses();
     foreach ($results as $r) {
         $this->data['tax_classes'][$r['tax_class_id']] = $r['title'];
     }
     $this->loadModel('localisation/weight_class');
     $this->data['weight_classes'] = array();
     $results = $this->model_localisation_weight_class->getWeightClasses();
     foreach ($results as $r) {
         $this->data['weight_classes'][$r['weight_class_id']] = $r['title'];
     }
     $this->loadModel('localisation/length_class');
     $this->data['length_classes'] = array();
     $results = $this->model_localisation_length_class->getLengthClasses();
     foreach ($results as $r) {
         $this->data['length_classes'][$r['length_class_id']] = $r['title'];
     }
     $fields = array('product_category', 'featured', 'product_store', 'model', 'call_to_order', 'sku', 'location', 'keyword', 'image', 'manufacturer_id', 'shipping', 'ship_individually', 'shipping_price', 'free_shipping', 'quantity', 'minimum', 'maximum', 'subtract', 'sort_order', 'stock_status_id', 'price', 'cost', 'status', 'tax_class_id', 'weight', 'weight_class_id', 'length', 'width', 'height');
     foreach ($fields as $f) {
         if (isset($this->request->post[$f])) {
             $this->data[$f] = $this->request->post[$f];
         } elseif (isset($product_info)) {
             $this->data[$f] = $product_info[$f];
         }
     }
     if (isset($this->request->post['product_category'])) {
         $this->data['product_category'] = $this->request->post['product_category'];
     } elseif (isset($product_info)) {
         $this->data['product_category'] = $this->model_catalog_product->getProductCategories($product_id);
     } else {
         $this->data['product_category'] = array();
     }
     if (isset($this->request->post['product_store'])) {
         $this->data['product_store'] = $this->request->post['product_store'];
     } elseif (isset($product_info)) {
         $this->data['product_store'] = $this->model_catalog_product->getProductStores($product_id);
     } else {
         $this->data['product_store'] = array(0);
     }
     if (isset($this->request->post['product_description'])) {
         $this->data['product_description'] = $this->request->post['product_description'];
     } elseif (isset($product_info)) {
         $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($product_id, $this->session->data['content_language_id']);
     } else {
         $this->data['product_description'] = array();
     }
     if (isset($this->request->post['featured'])) {
         $this->data['featured'] = $this->request->post['featured'];
     } elseif (isset($product_info)) {
         $this->data['featured'] = $product_info['featured'];
     } else {
         $this->data['featured'] = 0;
     }
     if (isset($this->request->post['product_tags'])) {
         $this->data['product_tags'] = $this->request->post['product_tags'];
     } elseif (isset($product_info)) {
         $this->data['product_tags'] = $this->model_catalog_product->getProductTags($product_id, $this->session->data['content_language_id']);
     } else {
         $this->data['product_tags'] = '';
     }
     $this->loadModel('tool/image');
     if (isset($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) {
         $this->data['preview'] = $this->model_tool_image->resize($product_info['image'], 100, 100);
     } else {
         $this->data['preview'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
     }
     if ($this->data['stock_status_id'] == '') {
         $this->data['stock_status_id'] = $this->config->get('config_stock_status_id');
     }
     if (isset($this->request->post['date_available'])) {
         $this->data['date_available'] = $this->request->post['date_available'];
     } elseif (isset($product_info)) {
         $this->data['date_available'] = $product_info['date_available'];
     } else {
         $this->data['date_available'] = dateInt2ISO(time() - 86400);
     }
     $weight_info = $this->model_localisation_weight_class->getWeightClassDescriptionByUnit($this->config->get('config_weight_class'));
     if (isset($this->request->post['weight_class_id'])) {
         $this->data['weight_class_id'] = $this->request->post['weight_class_id'];
     } elseif (isset($product_info)) {
         $this->data['weight_class_id'] = $product_info['weight_class_id'];
     } elseif (isset($weight_info)) {
         $this->data['weight_class_id'] = $weight_info['weight_class_id'];
     } else {
         $this->data['weight_class_id'] = '';
     }
     $length_info = $this->model_localisation_length_class->getLengthClassDescriptionByUnit($this->config->get('config_length_class'));
     if (isset($this->request->post['length_class_id'])) {
         $this->data['length_class_id'] = $this->request->post['length_class_id'];
     } elseif (isset($product_info)) {
         $this->data['length_class_id'] = $product_info['length_class_id'];
     } elseif (isset($length_info)) {
         $this->data['length_class_id'] = $length_info['length_class_id'];
     } else {
         $this->data['length_class_id'] = '';
     }
     if ($this->data['status'] == '') {
         $this->data['status'] = 1;
     }
     if ($this->data['quantity'] == '') {
         $this->data['quantity'] = 1;
     }
     if ($this->data['minimum'] == '') {
         $this->data['minimum'] = 1;
     }
     if ($this->data['sort_order'] == '') {
         $this->data['sort_order'] = 1;
     }
     $this->data['active'] = 'details';
     if (!isset($product_id)) {
         $this->data['action'] = $this->html->getSecureURL('catalog/product/insert');
         $this->data['form_title'] = $this->language->get('text_insert') . $this->language->get('text_product');
         $this->data['update'] = '';
         $form = new AForm('ST');
         $this->data['summary_form'] = '';
     } else {
         $this->data['action'] = $this->html->getSecureURL('catalog/product/update', '&product_id=' . $product_id);
         $this->data['form_title'] = $this->language->get('text_edit') . '&nbsp;' . $this->language->get('text_product');
         $this->data['update'] = $this->html->getSecureURL('listing_grid/product/update_field', '&id=' . $product_id);
         $form = new AForm('HS');
         $this->data['active'] = 'general';
         //load tabs controller
         $tabs_obj = $this->dispatch('pages/catalog/product_tabs', array($this->data));
         $this->data['product_tabs'] = $tabs_obj->dispatchGetOutput();
         unset($tabs_obj);
         $this->addChild('pages/catalog/product_summary', 'summary_form', 'pages/catalog/product_summary.tpl');
     }
     $form->setForm(array('form_name' => 'productFrm', 'update' => $this->data['update']));
     $this->data['form']['id'] = 'productFrm';
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'productFrm', 'action' => $this->data['action'], 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
     $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']['general']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => $this->data['status'], 'style' => 'btn_switch btn-group-sm', 'help_url' => $this->gen_help_url('?p=62')));
     $this->data['form']['fields']['general']['featured'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'featured', 'value' => $this->data['featured'], 'style' => 'btn_switch btn-group-sm', 'help_url' => $this->gen_help_url('?p=62')));
     $this->data['form']['fields']['general']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product_description[name]', 'value' => $this->data['product_description']['name'], 'required' => true, 'help_url' => $this->gen_help_url('?p=62')));
     $this->data['form']['fields']['general']['description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'product_description[description]', 'value' => $this->data['product_description']['description']));
     $this->data['form']['fields']['general']['meta_keywords'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'product_description[meta_keywords]', 'value' => $this->data['product_description']['meta_keywords'], 'help_url' => $this->gen_help_url('?p=62')));
     $this->data['form']['fields']['general']['meta_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'product_description[meta_description]', 'value' => $this->data['product_description']['meta_description']));
     $this->data['form']['fields']['general']['blurb'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'product_description[blurb]', 'value' => $this->data['product_description']['blurb']));
     $this->data['form']['fields']['general']['tags'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'product_tags', 'value' => $this->data['product_tags']));
     $this->data['form']['fields']['general']['category'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'product_category[]', 'value' => $this->data['product_category'], 'options' => $this->data['categories'], 'style' => 'chosen', 'placeholder' => $this->language->get('text_select_category')));
     $this->data['form']['fields']['general']['store'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'product_store[]', 'value' => $this->data['product_store'], 'options' => $this->data['stores'], 'style' => 'chosen', 'placeholder' => $this->language->get('entry_store')));
     $this->data['form']['fields']['data']['manufacturer'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'manufacturer_id', 'value' => $this->data['manufacturer_id'], 'options' => $this->data['manufacturers'], 'style' => 'chosen', 'placeholder' => $this->language->get('entry_manufacturer')));
     $this->data['form']['fields']['data']['model'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'model', 'value' => $this->data['model'], 'required' => false));
     $this->data['form']['fields']['data']['call_to_order'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'call_to_order', 'value' => $this->data['call_to_order'], 'style' => 'btn_switch btn-group-sm', 'help_url' => $this->gen_help_url('?p=62')));
     $this->data['form']['fields']['data']['price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'price', 'value' => moneyDisplayFormat($this->data['price']), 'style' => 'small-field'));
     $this->data['form']['fields']['data']['cost'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'cost', 'value' => moneyDisplayFormat($this->data['cost']), 'style' => 'small-field'));
     $this->data['form']['fields']['data']['tax_class'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'tax_class_id', 'value' => $this->data['tax_class_id'], 'options' => $this->data['tax_classes'], 'help_url' => $this->gen_help_url('?p=62'), 'style' => 'medium-field'));
     $this->data['form']['fields']['data']['subtract'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'subtract', 'value' => $this->data['subtract'], 'options' => array(1 => $this->language->get('text_yes'), 0 => $this->language->get('text_no')), 'help_url' => $this->gen_help_url('?p=62'), 'style' => 'medium-field'));
     $this->data['form']['fields']['data']['quantity'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity', 'value' => (int) $this->data['quantity'], 'style' => 'col-xs-1 small-field'));
     $this->data['form']['fields']['data']['minimum'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'minimum', 'value' => (int) $this->data['minimum'], 'style' => 'small-field'));
     $this->data['form']['fields']['data']['maximum'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'maximum', 'value' => (int) $this->data['maximum'], 'style' => 'small-field'));
     $this->data['form']['fields']['data']['stock_status'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'stock_status_id', 'value' => $this->data['stock_status_id'], 'options' => $this->data['stock_statuses'], 'style' => 'small-field'));
     $this->data['form']['fields']['data']['sku'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sku', 'value' => $this->data['sku'], 'help_url' => $this->gen_help_url('?p=62')));
     $this->data['form']['fields']['data']['location'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'location', 'value' => $this->data['location']));
     //prepend button to generate keyword
     $this->data['keyword_button'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'generate_seo_keyword', 'text' => $this->language->get('button_generate'), 'attr' => 'type="button"', 'style' => 'btn btn-info'));
     $this->data['generate_seo_url'] = $this->html->getSecureURL('common/common/getseokeyword', '&object_key_name=product_id&id=' . $product_id);
     $this->data['form']['fields']['data']['keyword'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'keyword', 'value' => $this->data['keyword'], 'help_url' => $this->gen_help_url('?p=62'), 'attr' => ' gen-value="' . SEOEncode($this->data['product_description']['name']) . '" '));
     $this->data['form']['fields']['data']['date_available'] = $form->getFieldHtml(array('type' => 'date', 'name' => 'date_available', 'value' => dateISO2Display($this->data['date_available']), 'default' => dateNowDisplay(), 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'future', 'style' => 'small-field'));
     $this->data['form']['fields']['data']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['sort_order'], 'style' => 'tiny-field'));
     $this->data['form']['fields']['data']['shipping'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'shipping', 'style' => 'btn_switch btn-group-sm', 'value' => isset($this->data['shipping']) ? $this->data['shipping'] : 1));
     $this->data['form']['fields']['data']['free_shipping'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'free_shipping', 'style' => 'btn_switch btn-group-sm', 'value' => isset($this->data['free_shipping']) ? $this->data['free_shipping'] : 0));
     $this->data['form']['fields']['data']['ship_individually'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'ship_individually', 'style' => 'btn_switch btn-group-sm', 'value' => isset($this->data['ship_individually']) ? $this->data['ship_individually'] : 0));
     $this->data['form']['fields']['data']['shipping_price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'shipping_price', 'value' => moneyDisplayFormat($this->data['shipping_price']), 'style' => 'tiny-field'));
     $this->data['form']['fields']['data']['length'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'length', 'value' => $this->data['length'], 'style' => 'tiny-field'));
     $this->data['form']['fields']['data']['width'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'width', 'value' => $this->data['width'], 'attr' => ' autocomplete="false"', 'style' => 'tiny-field'));
     $this->data['form']['fields']['data']['height'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'height', 'value' => $this->data['height'], 'attr' => ' autocomplete="false"', 'style' => 'tiny-field'));
     if ($product_id && !$this->data['length_class_id']) {
         $this->data['length_classes'][0] = $this->language->get('text_none');
     }
     $this->data['form']['fields']['data']['length_class'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'length_class_id', 'value' => $this->data['length_class_id'], 'options' => $this->data['length_classes'], 'style' => 'small-field'));
     if ($product_id && $this->data['shipping'] && (!(double) $this->data['weight'] || !$this->data['weight_class_id']) && !(double) $this->data['shipping_price']) {
         if (!$this->data['weight_class_id']) {
             $this->data['error']['weight_class'] = $this->language->get('error_weight_class');
         }
         if (!(double) $this->data['weight']) {
             $this->data['error']['weight'] = $this->language->get('error_weight_value');
         }
     }
     if ($product_id && !$this->data['weight_class_id']) {
         $this->data['weight_classes'][0] = $this->language->get('text_none');
     }
     $this->data['form']['fields']['data']['weight'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'weight', 'value' => $this->data['weight'], 'attr' => ' autocomplete="false"', 'style' => 'tiny-field'));
     $this->data['form']['fields']['data']['weight_class'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'weight_class_id', 'value' => $this->data['weight_class_id'], 'options' => $this->data['weight_classes'], 'style' => 'small-field'));
     $this->data['product_id'] = $product_id;
     if ($product_id && $this->config->get('config_embed_status')) {
         $this->data['embed_url'] = $this->html->getSecureURL('common/do_embed/product', '&product_id=' . $product_id);
     }
     $this->data['text_clone'] = $this->language->get('text_clone');
     $this->data['clone_url'] = $this->html->getSecureURL('catalog/product/copy', '&product_id=' . $this->request->get['product_id']);
     $this->data['form_language_switch'] = $this->html->getContentLanguageSwitcher();
     $this->data['language_id'] = $this->session->data['content_language_id'];
     $this->data['language_code'] = $this->session->data['language'];
     $this->data['help_url'] = $this->gen_help_url('?p=62');
     $this->data['rl'] = $this->html->getSecureURL('common/resource_library', '&object_name=&object_id&type=image&mode=url');
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/catalog/product_form.tpl');
 }
Пример #9
0
 private function _getForm()
 {
     $this->view->assign('token', $this->session->data['token']);
     $this->view->assign('error_warning', $this->error['warning']);
     $this->view->assign('error_name', $this->error['name']);
     $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/manufacturer'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->view->assign('cancel', $this->html->getSecureURL('catalog/manufacturer'));
     if (isset($this->request->get['manufacturer_id']) && $this->request->is_GET()) {
         $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
     }
     foreach ($this->fields as $f) {
         if (isset($this->request->post[$f])) {
             $this->data[$f] = $this->request->post[$f];
         } elseif (isset($manufacturer_info) && isset($manufacturer_info[$f])) {
             $this->data[$f] = $manufacturer_info[$f];
         } else {
             $this->data[$f] = '';
         }
     }
     $this->loadModel('setting/store');
     $this->data['stores'] = $this->model_setting_store->getStores();
     if (isset($this->request->post['manufacturer_store'])) {
         $this->data['manufacturer_store'] = $this->request->post['manufacturer_store'];
     } elseif (isset($manufacturer_info)) {
         $this->data['manufacturer_store'] = $this->model_catalog_manufacturer->getManufacturerStores($this->request->get['manufacturer_id']);
     } else {
         $this->data['manufacturer_store'] = array(0);
     }
     $stores = array(0 => $this->language->get('text_default'));
     foreach ($this->data['stores'] as $s) {
         $stores[$s['store_id']] = $s['name'];
     }
     if (!isset($this->request->get['manufacturer_id'])) {
         $this->data['action'] = $this->html->getSecureURL('catalog/manufacturer/insert');
         $this->data['heading_title'] = $this->language->get('text_insert') . $this->language->get('text_manufacturer');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('catalog/manufacturer/update', '&manufacturer_id=' . $this->request->get['manufacturer_id']);
         $this->data['heading_title'] = $this->language->get('text_edit') . $this->language->get('text_manufacturer') . ' - ' . $this->data['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/manufacturer/update_field', '&id=' . $this->request->get['manufacturer_id']);
         $form = new AForm('HS');
         $this->data['manufacturer_edit'] = $this->html->getSecureURL('catalog/manufacturer/update', '&manufacturer_id=' . $this->request->get['manufacturer_id']);
         $this->data['tab_edit'] = $this->language->get('entry_edit');
         $this->data['tab_layout'] = $this->language->get('entry_layout');
         $this->data['manufacturer_layout'] = $this->html->getSecureURL('catalog/manufacturer_layout', '&manufacturer_id=' . $this->request->get['manufacturer_id']);
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: ', 'current' => true));
     $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' => 'data-confirm-exit="true" class="aform form-horizontal"', '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']['general']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'name', 'value' => $this->data['name'], 'required' => true, 'style' => 'large-field', 'help_url' => $this->gen_help_url('name')));
     $this->data['form']['fields']['general']['manufacturer_store'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'manufacturer_store[]', 'value' => $this->data['manufacturer_store'], 'options' => $stores, 'style' => 'chosen', 'help_url' => $this->gen_help_url('manufacturer_store')));
     $this->data['form']['fields']['general']['keyword'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'generate_seo_keyword', 'text' => $this->language->get('button_generate'), 'attr' => 'type="button"', 'style' => 'btn btn-info'));
     $this->data['generate_seo_url'] = $this->html->getSecureURL('common/common/getseokeyword', '&object_key_name=category_id&id=' . $category_id);
     $this->data['form']['fields']['general']['keyword'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'keyword', 'value' => $this->data['keyword'], 'help_url' => $this->gen_help_url('seo_keyword'), 'attr' => ' gen-value="' . SEOEncode($this->data['category_description']['name']) . '" '));
     $this->data['form']['fields']['general']['sort_order'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'sort_order', 'value' => $this->data['sort_order'], 'style' => 'small-field'));
     $this->view->assign('help_url', $this->gen_help_url('manufacturer_edit'));
     $this->view->batchAssign($this->data);
     $this->addChild('responses/common/resource_library/get_resources_html', 'resources_html', 'responses/common/resource_library_scripts.tpl');
     $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'manufacturers', 'object_id' => $this->request->get['manufacturer_id'], 'types' => array('image', 'audio', 'video', 'pdf')));
     $this->view->assign('resources_scripts', $resources_scripts->dispatchGetOutput());
     $this->processTemplate('pages/catalog/manufacturer_form.tpl');
 }
 /**
  * @param int $content_id
  * @param string $field
  * @param mixed $value
  * @param null|int $parent_content_id
  * @return bool
  */
 public function editContentField($content_id, $field, $value, $parent_content_id = null)
 {
     $content_id = (int) $content_id;
     $language_id = (int) $this->language->getContentLanguageID();
     if (!$language_id) {
         return false;
     }
     switch ($field) {
         case 'status':
             $this->db->query("UPDATE " . $this->db->table("contents") . " \n\t\t\t\t\t\t\t\t\tSET `status` = '" . (int) $value . "'\n\t\t\t\t\t\t\t\t\tWHERE content_id = '" . (int) $content_id . "'");
             break;
         case 'sort_order':
             $this->db->query("UPDATE " . $this->db->table("contents") . " \n\t\t\t\t\t\t\t\tSET `sort_order` = '" . (int) $value . "'\n\t\t\t\t\t\t\t\tWHERE content_id = '" . (int) $content_id . "'\n\t\t\t\t\t\t\t\t\tAND parent_content_id='" . (int) $parent_content_id . "'");
             break;
         case 'title':
         case 'description':
         case 'content':
             $this->language->replaceDescriptions('content_descriptions', array('content_id' => (int) $content_id), array((int) $language_id => array($field => $value)));
             break;
         case 'keyword':
             $value = SEOEncode($value, 'content_id', $content_id);
             if ($value) {
                 $this->language->replaceDescriptions('url_aliases', array('query' => "content_id=" . (int) $content_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $value)));
             } else {
                 $this->db->query("DELETE\n\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\t\t\tWHERE query = 'content_id=" . (int) $content_id . "'\n\t\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
             }
             break;
         case 'parent_content_id':
             // prevent deleting while updating with parent_id==content_id
             $value = (array) $value;
             foreach ($value as $k => $v) {
                 list($void, $parent_id) = explode('_', $v);
                 if ($parent_id == $content_id) {
                     continue;
                 }
                 $tmp[$parent_id] = $parent_id;
             }
             $value = $tmp;
             if (sizeof($value) == 1 && current($value) == $content_id) {
                 break;
             }
             $query = "SELECT parent_content_id, sort_order, status\n\t\t\t\t\t\t\tFROM " . $this->db->table("contents") . " \n\t\t\t\t\t\t\tWHERE content_id='" . $content_id . "'";
             $result = $this->db->query($query);
             if ($result->num_rows) {
                 $status = $result->row['status'];
                 foreach ($result->rows as $row) {
                     $sort_orders[$row['parent_content_id']] = $row['sort_order'];
                 }
             }
             $query = "DELETE FROM " . $this->db->table("contents") . " WHERE content_id='" . $content_id . "'";
             $this->db->query($query);
             $value = !$value ? array(0) : $value;
             foreach ($value as $parent_content_id) {
                 $parent_content_id = (int) $parent_content_id;
                 if ($parent_content_id == $content_id) {
                     continue;
                 }
                 $query = "INSERT INTO " . $this->db->table("contents") . " (content_id,parent_content_id, sort_order, status)\n\t\t\t\t\t\t\t\t\tVALUES ('" . $content_id . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $parent_content_id . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . (int) $sort_orders[$parent_content_id] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $status . "');";
                 $this->db->query($query);
             }
             break;
         case 'store_id':
             $query = "DELETE FROM " . $this->db->table("contents_to_stores") . " WHERE content_id='" . $content_id . "'";
             $this->db->query($query);
             foreach ($value as $store_id) {
                 if (has_value($store_id)) {
                     $query = "INSERT INTO " . $this->db->table("contents_to_stores") . " (content_id,store_id)\n\t\t\t\t\t\t\t\t\t\tVALUES ('" . $content_id . "','" . (int) $store_id . "')";
                     $this->db->query($query);
                 }
             }
             break;
     }
     $this->cache->delete('contents');
     return true;
 }