/** * Build a categories tree * * @param array $indexedCategories Array with categories where product is indexed (in order to check checkbox) * @param array $categories Categories to list * @param array $current Current category * @param integer $id_category Current category id */ function recurseCategoryForInclude($indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL) { global $done; static $irow; $id_obj = intval(Tools::getValue($this->id)); if (!isset($done[$current['infos']['id_parent']])) { $done[$current['infos']['id_parent']] = 0; } $done[$current['infos']['id_parent']] += 1; $todo = sizeof($categories[$current['infos']['id_parent']]); $doneC = $done[$current['infos']['id_parent']]; $level = $current['infos']['level_depth'] + 1; $img = $level == 1 ? 'lv1.gif' : 'lv' . $level . '_' . ($todo == $doneC ? 'f' : 'b') . '.gif'; echo ' <tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td> ' . ($id_category == 1 ? ' ' : '<input type="checkbox" name="categoryBox[]" class="categoryBox' . ($id_category_default != NULL ? ' id_category_default' : '') . '" id="categoryBox_' . $id_category . '" value="' . $id_category . '"' . ((in_array($id_category, $indexedCategories) or intval(Tools::getValue('id_category')) == $id_category and !intval($id_obj)) ? ' checked="checked"' : '') . ' />') . ' </td> <td> ' . $id_category . ' </td> <td> <img src="../img/admin/' . $img . '" alt="" /> <label for="categoryBox_' . $id_category . '" class="t">' . stripslashes(Category::hideCategoryPosition($current['infos']['name'])) . '</label> </td> </tr>'; if (isset($categories[$id_category])) { foreach ($categories[$id_category] as $key => $row) { if ($key != 'infos') { $this->recurseCategoryForInclude($indexedCategories, $categories, $categories[$id_category][$key], $key); } } } }
/** * Returns module content * * @param array $params Parameters * @return string Content */ function hookHome($params) { global $smarty, $cookie; /* ONLY FOR THEME OLDER THAN v1.0 */ global $link; $smarty->assign(array('categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link)); /* ELSE */ $id_customer = intval($params['cookie']->id_customer); $maxdepth = 1; if (!($result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . intval($params['cookie']->id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE 1' . (intval($maxdepth) != 0 ? ' AND `level_depth` <= ' . intval($maxdepth) : '') . ' AND (c.`active` = 1 OR c.`id_category`= 1) AND cg.`id_group` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . ' ORDER BY `level_depth` ASC, cl.`name` ASC'))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as $row) { ${$row}['name'] = Category::hideCategoryPosition($row['name']); $resultParents[$row['id_parent']][] = $row; $resultIds[$row['id_category']] = $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, 1); $smarty->assign('blockCategTree', $blockCategTree); return $this->display(__FILE__, 'home_menu.tpl'); }
public function display($token = NULL) { global $currentIndex, $cookie; $this->getList(intval($cookie->id_lang), !Tools::getValue($this->table . 'Orderby') ? 'name' : NULL, !Tools::getValue($this->table . 'Orderway') ? 'ASC' : NULL); echo '<h3>' . (!$this->_listTotal ? $this->l('There are no subcategories') : $this->_listTotal . ' ' . ($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subcategory'))) . ' ' . $this->l('in category') . ' "' . stripslashes(Category::hideCategoryPosition($this->_category->getName())) . '"</h3>'; echo '<a href="' . __PS_BASE_URI__ . substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) . '?tab=AdminCatalog&add' . $this->table . '&id_parent=' . Tools::getValue('id_category') . '&token=' . ($token != NULL ? $token : $this->token) . '"><img src="../img/admin/add.gif" border="0" /> ' . $this->l('Add a new subcategory') . '</a> <div style="margin:10px;">'; $this->displayList($token); echo '</div>'; }
function hookLeftColumn($params) { global $smarty, $cookie; /* ONLY FOR THEME OLDER THAN v1.0 */ global $link; $smarty->assign(array('categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link)); /* ELSE */ $id_customer = intval($params['cookie']->id_customer); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!($result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . intval($params['cookie']->id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE 1' . (intval($maxdepth) != 0 ? ' AND `level_depth` <= ' . intval($maxdepth) : '') . ' AND (c.`active` = 1 OR c.`id_category`= 1) AND cg.`id_group` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . ' ORDER BY `level_depth` ASC, cl.`name` ASC'))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as $row) { ${$row}['name'] = Category::hideCategoryPosition($row['name']); $resultParents[$row['id_parent']][] = $row; $resultIds[$row['id_category']] = $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (isset($_GET['id_category'])) { $cookie->last_visited_category = intval($_GET['id_category']); $smarty->assign('currentCategoryId', intval($_GET['id_category'])); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) and Validate::isLoadedObject($product)) { $cookie->last_visited_category = intval($product->id_category_default); } } $smarty->assign('currentCategoryId', intval($cookie->last_visited_category)); } $smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories.tpl')) { $smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); } else { $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl'); } $smarty->assign('isDhtml', $isDhtml); /* /ONLY FOR THEME OLDER THAN v1.0 */ return $this->display(__FILE__, 'blockcategories.tpl'); }
function prepareDisplay($params) { global $smarty, $cookie; /* ONLY FOR THEME OLDER THAN v1.0 */ global $link; $smarty->assign(array('categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link)); /* ELSE */ $id_customer = intval($params['cookie']->id_customer); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!($result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . intval($params['cookie']->id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` ctg ON (ctg.`id_category` = c.`id_category`) ' . ($id_customer ? 'INNER JOIN `' . _DB_PREFIX_ . 'customer_group` cg ON (cg.`id_group` = ctg.`id_group` AND cg.`id_customer` = ' . intval($id_customer) . ')' : '') . ' WHERE 1' . (intval($maxdepth) != 0 ? ' AND `level_depth` <= ' . intval($maxdepth) : '') . ' AND (c.`active` = 1 OR c.`id_category`= 1) ' . (!$id_customer ? 'AND ctg.`id_group` = 1' : '') . ' ORDER BY `level_depth` ASC, cl.`name` ASC'))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as $row) { ${$row}['name'] = Category::hideCategoryPosition($row['name']); $resultParents[$row['id_parent']][] = $row; $resultIds[$row['id_category']] = $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (isset($_GET['id_category'])) { $cookie->last_visited_category = intval($_GET['id_category']); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) and Validate::isLoadedObject($product)) { $cookie->last_visited_category = intval($product->id_category_default); } } } if (isset($cookie->last_visited_category)) { $smarty->assign('currentCategoryId', $cookie->last_visited_category); $smarty->assign('currentCategoryPath', array_reverse($this->findCurrentCategoryPath($blockCategTree, $cookie->last_visited_category))); } $smarty->assign('blockCategTree', $blockCategTree); $smarty->assign('isDhtml', $isDhtml); /* /ONLY FOR THEME OLDER THAN v1.0 */ }
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[2]))))) { $category = new Category(intval($regs[2]), intval($cookie->id_lang)); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[5]))))) { $category = new Category(intval($regs[5]), intval($cookie->id_lang)); } } } if (!$category) { $category = new Category($product->id_category_default, intval($cookie->id_lang)); } if (isset($category) and Validate::isLoadedObject($category)) { $smarty->assign(array('category' => $category, 'subCategories' => $category->getSubCategories(intval($cookie->id_lang), true), 'id_category_current' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)))); } $smarty->assign(array('return_link' => (isset($category->id) and $category->id) ? Tools::safeOutput($link->getCategoryLink($category)) : 'javascript: history.back();', 'path' => (isset($category->id) and $category->id) ? Tools::getFullPath(intval($category->id), $product->name) : Tools::getFullPath(intval($product->id_category_default), $product->name))); $lang = Configuration::get('PS_LANG_DEFAULT'); if (Pack::isPack(intval($product->id), intval($lang)) and !Pack::isInStock(intval($product->id), intval($lang))) { $product->quantity = 0; } /* /Quantity discount management */ $smarty->assign(array('quantity_discounts' => QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct()), 'product' => $product, 'homeSize' => Image::getSize('home'), 'jqZoomEnabled' => $jqZoomEnabled, 'product_manufacturer' => new Manufacturer(intval($product->id_manufacturer)), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => floatval($productPriceWithoutEcoTax), 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $product->isAvailableWhenOutOfStock(intval($product->out_of_stock)), 'last_qties' => intval($configs['PS_LAST_QTIES']), 'group_reduction' => (100 - Group::getReduction(intval($cookie->id_customer))) / 100, 'col_img_dir' => _PS_COL_IMG_DIR_, 'HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent'))); $images = $product->getImages(intval($cookie->id_lang)); $productImages = array(); foreach ($images as $k => $image) { if ($image['cover']) { $smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = intval($product->id) . '-' . $cover['id_image'];
$smarty->assign('largeSceneImageType', isset($largeSceneImageType) ? $largeSceneImageType : NULL); } $category->name = Category::hideCategoryPosition($category->name); $category->description = nl2br2($category->description); $subCategories = $category->getSubCategories(intval($cookie->id_lang)); $smarty->assign('category', $category); if (Db::getInstance()->numRows()) { $smarty->assign('subcategories', $subCategories); } if ($category->id != 1) { $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true); include dirname(__FILE__) . '/pagination.php'; $smarty->assign('nb_products', $nbProducts); $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay); } $smarty->assign(array('products' => (isset($cat_products) and $cat_products) ? $cat_products : NULL, 'id_category' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)), 'path' => Tools::getPath(intval($category->id), $category->name))); } } $smarty->assign(array('allow_oosp' => intval(Configuration::get('PS_ORDER_OUT_OF_STOCK')), 'suppliers' => Supplier::getSuppliers(), 'errors' => $errors)); $smarty->assign(array('homeSize' => Image::getSize('home'))); if (isset($subCategories)) { $smarty->assign(array('subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); } $smarty->display(_PS_THEME_DIR_ . 'category.tpl'); include dirname(__FILE__) . '/footer.php'; } catch (Exception $e) { echo $e->getMessage(); echo "<br><bR>"; foreach ($e->getTrace() as $line) { echo "{$line['class']}.{$line['function']} @ {$line['file']}:{$line['line']}<br>"; }
public static function indexation($full = false) { $db = Db::getInstance(); if ($full) { $db->Execute('TRUNCATE ' . _DB_PREFIX_ . 'search_index'); $db->Execute('TRUNCATE ' . _DB_PREFIX_ . 'search_word'); $db->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET indexed = 0'); } else { $db->Execute('DELETE FROM ' . _DB_PREFIX_ . 'search_index WHERE id_product IN (SELECT id_product FROM ' . _DB_PREFIX_ . 'product WHERE indexed = 0)'); } $weightArray = array('pname' => Configuration::get('PS_SEARCH_WEIGHT_PNAME'), 'reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'description_short' => Configuration::get('PS_SEARCH_WEIGHT_SHORTDESC'), 'description' => Configuration::get('PS_SEARCH_WEIGHT_DESC'), 'cname' => Configuration::get('PS_SEARCH_WEIGHT_CNAME'), 'mname' => Configuration::get('PS_SEARCH_WEIGHT_MNAME'), 'tags' => Configuration::get('PS_SEARCH_WEIGHT_TAG'), 'attributes' => Configuration::get('PS_SEARCH_WEIGHT_ATTRIBUTE'), 'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE')); $products = $db->ExecuteS(' SELECT p.id_product, pl.id_lang, pl.name as pname, p.reference, p.ean13, pl.description_short, pl.description, cl.name as cname, m.name as mname FROM ' . _DB_PREFIX_ . 'product p LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = p.id_category_default AND pl.id_lang = cl.id_lang) LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON m.id_manufacturer = p.id_manufacturer WHERE p.indexed = 0', false); while ($product = $db->nextRow($products)) { $product['tags'] = self::getTags($db, $product['id_product'], $product['id_lang']); $product['attributes'] = self::getAttributes($db, $product['id_product'], $product['id_lang']); $product['features'] = self::getFeatures($db, $product['id_product'], $product['id_lang']); $pArray = array(); foreach ($product as $key => $value) { if (strncmp($key, 'id_', 3)) { if ($key == 'cname') { $value = Category::hideCategoryPosition($value); } $words = explode(' ', self::sanitize($value, $product['id_lang'], true)); foreach ($words as $word) { if (!empty($word)) { $word = substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH); if (!isset($pArray[$word])) { $pArray[$word] = $weightArray[$key]; } else { $pArray[$word] += $weightArray[$key]; } } } } } $queryArray = array(); $queryArray2 = array(); foreach ($pArray as $word => $weight) { $queryArray[] = '(' . intval($product['id_lang']) . ',\'' . pSQL($word) . '\')'; $queryArray2[] = '(' . intval($product['id_product']) . ',(SELECT id_word FROM ' . _DB_PREFIX_ . 'search_word WHERE word = \'' . pSQL($word) . '\' AND id_lang = ' . intval($product['id_lang']) . ' LIMIT 1),' . intval($weight) . ')'; } if (sizeof($queryArray) and sizeof($queryArray2)) { if (!($rows = $db->Execute('INSERT IGNORE INTO ' . _DB_PREFIX_ . 'search_word (id_lang, word) VALUES ' . implode(',', $queryArray))) or $rows != sizeof($queryArray)) { Tools::d(array(mysql_error(), $queryArray)); } if (!($rows = $db->Execute('INSERT INTO ' . _DB_PREFIX_ . 'search_index (id_product, id_word, weight) VALUES ' . implode(',', $queryArray2) . ' ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)')) or $rows != sizeof($queryArray2)) { Tools::d(array(mysql_error(), $queryArray2)); } } $db->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET indexed = 1 WHERE id_product = ' . intval($product['id_product'])); } $db->Execute('DELETE FROM ' . _DB_PREFIX_ . 'search_word WHERE id_word NOT IN (SELECT id_word FROM ' . _DB_PREFIX_ . 'search_index)'); return true; }
public static function getChildren($id_parent, $id_lang, $active = true) { if (!Validate::isBool($active)) { die(Tools::displayError()); } $result = Db::getInstance()->ExecuteS(' SELECT c.`id_category`, cl.`name`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON c.`id_category` = cl.`id_category` WHERE `id_lang` = ' . intval($id_lang) . ' AND c.`id_parent` = ' . intval($id_parent) . ' ' . ($active ? 'AND `active` = 1' : '') . ' ORDER BY `name` ASC'); /* Modify SQL result */ $resultsArray = array(); foreach ($result as $row) { $row['name'] = Category::hideCategoryPosition($row['name']); $resultsArray[] = $row; } return $resultsArray; }
else location.href = eltVal; } </script> <select onchange="quickSelect(this);" style="font-size: 1em; margin:5px 20px 0px 0px;"> <?php $quicks = QuickAccess::getQuickAccesses(intval($cookie->id_lang)); echo '<option value="0">' . translate('Quick access') . '</option>'; foreach ($quicks as &$quick) { preg_match('/tab=(.+)(&.+)?$/', $quick['link'], $adminTab); if (isset($adminTab[1])) { if (strpos($adminTab[1], '&')) { $adminTab[1] = substr($adminTab[1], 0, strpos($adminTab[1], '&')); } $quick['link'] .= '&token=' . Tools::getAdminToken($adminTab[1] . intval(Tab::getIdFromClassName($adminTab[1])) . intval($cookie->id_employee)); } echo '<option value="' . $quick['link'] . ($quick['new_window'] ? '_blank' : '') . '">> ' . Category::hideCategoryPosition($quick['name']) . '</option>'; } ?> </select> <img src="../img/admin/nav-user.gif" alt="<?php echo translate('user'); ?> " /> <a href="index.php?logout" title="<?php echo translate('logout'); ?> "> <b><?php echo Tools::substr($cookie->firstname, 0, 1) . '. ' . htmlentities($cookie->lastname, ENT_COMPAT, 'UTF-8'); ?> </b>
public function categoryImport() { $catMoved = array(); $this->receiveTab(); $handle = $this->openCsvFile(); $defaultLanguageId = intval(Configuration::get('PS_LANG_DEFAULT')); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) { if (Tools::getValue('convert')) { $this->utf8_encode_array($line); } $info = self::getMaskedRow($line); self::setDefaultValues($info); $category = new Category(); self::array_walk($info, array('AdminImport', 'fillInfo'), $category); if (isset($category->parent) and is_numeric($category->parent)) { if (isset($catMoved[$category->parent])) { $category->parent = $catMoved[$category->parent]; } $category->id_parent = $category->parent; } elseif (isset($category->parent) and is_string($category->parent)) { $categoryParent = Category::searchByName($defaultLanguageId, $category->parent, true); if ($categoryParent['id_category']) { $category->id_parent = intval($categoryParent['id_category']); } else { $categoryToCreate = new Category(); $categoryToCreate->name = self::createMultiLangField($category->parent); $categoryToCreate->active = 1; $categoryToCreate->id_parent = 1; // Default parent is home for unknown category to create if (($fieldError = $categoryToCreate->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $categoryToCreate->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $categoryToCreate->add()) { $category->id_parent = $categoryToCreate->id; } else { $this->_errors[] = $categoryToCreate->name[$defaultLanguageId] . (isset($categoryToCreate->id) ? ' (' . $categoryToCreate->id . ')' : '') . ' ' . Tools::displayError('cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } } if (isset($category->image) and !empty($category->image)) { if (!self::copyImg($category->id, NULL, $category->image, 'categories')) { $this->_warnings[] = $category->image . ' ' . Tools::displayError('cannot be copied'); } } $valid_link = Validate::isLinkRewrite($category->link_rewrite); $bak = $category->link_rewrite; if (isset($category->link_rewrite) and empty($category->link_rewrite) or !$valid_link) { $category->link_rewrite = Tools::link_rewrite(Category::hideCategoryPosition($category->name[$defaultLanguageId])); } if (!$valid_link) { $this->_warnings[] = Tools::displayError('Rewrited link for') . ' ' . $bak . (isset($info['id']) ? ' (ID ' . $info['id'] . ') ' : '') . ' ' . Tools::displayError('was re-written as') . ' ' . $category->link_rewrite; } $category->link_rewrite = self::createMultiLangField($category->link_rewrite); $res = false; if (($fieldError = $category->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $category->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $categoryAlreadyCreated = Category::searchByName($defaultLanguageId, $category->name[$defaultLanguageId], true); // If category already in base, get id category back if ($categoryAlreadyCreated['id_category']) { $catMoved[$category->id] = intval($categoryAlreadyCreated['id_category']); $category->id = intval($categoryAlreadyCreated['id_category']); } // If id category AND id category already in base, trying to update if ($category->id and $category->categoryExists($category->id)) { $res = $category->update(); } // If no id_category or update failed if (!$res and $res = $category->add()) { $category->addGroups(array(1)); } } // If both failed, mysql error if (!$res) { $this->_errors[] = $info['name'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } $this->closeCsvFile($handle); }
public static function getFullPath($id_category, $end) { global $cookie; $pipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>'; $category = new Category(intval($id_category), intval($cookie->id_lang)); if (!Validate::isLoadedObject($category)) { die(self::displayError()); } if ($id_category == 1) { return htmlentities($end, ENT_NOQUOTES, 'UTF-8'); } return self::getPath($id_category, Category::hideCategoryPosition($category->name), true) . ' <span class="navigation-pipe">' . $pipe . '</span> <span class="navigation_product">' . htmlentities($end, ENT_NOQUOTES, 'UTF-8') . '</span>'; }
</div> <script type="text/javascript">$('#flagsLanguage img[class!=selected_language]').css('opacity', '0.3')</script> <div style="float: right; margin: 11px 0px 0px 20px; text-align:right;"> <img src="../img/admin/quick.gif" style="margin-top:5px;" /> <select onchange="if (this.value == '0') return ; else if (this.value.substr(-1) == 0) document.location = this.value.substr(0, this.value.length - 1); else window.open(this.value.substr(0, this.value.length - 1), 'PrestaShop', '');" style="font-size: 1em; margin:5px 20px 0px 0px;"> <?php global $cookie; $quicks = QuickAccess::getQuickAccesses(intval($cookie->id_lang)); echo '<option value="0">' . translate('Quick access') . '</option>'; echo '<option value="0">---</option>'; foreach ($quicks as $quick) { preg_match('/tab=(.+)&/', $quick['link'], $adminTab); if (isset($adminTab[1])) { $quick['link'] .= '&token=' . Tools::getAdminToken($adminTab[1] . intval(Tab::getIdFromClassName($adminTab[1])) . intval($cookie->id_employee)); } echo '<option value="' . $quick['link'] . intval($quick['new_window']) . '">' . Category::hideCategoryPosition($quick['name']) . '</option>'; } ?> </select> <img src="../img/admin/nav-user.gif" alt="<?php echo translate('user'); ?> " /> <a href="index.php?logout" title="<?php echo translate('logout'); ?> "> <b><?php echo Tools::substr($cookie->firstname, 0, 1) . '. ' . htmlentities(Tools::strtoupper($cookie->lastname), ENT_COMPAT, 'UTF-8'); ?> </b>
/** * Return path to a product category * * @param string $urlBase Start URL * @param integer $id_category Start category * @param string $path Current path * @param string $highlight String to highlight (in XHTML/CSS) */ function getPath($urlBase, $id_category, $path = '', $highlight = '') { global $cookie; $category = new Category($id_category, intval($cookie->id_lang)); if (!$category->id) { return $path; } $name = $highlight != NULL ? str_ireplace($highlight, '<span class="highlight">' . $highlight . '</span>', Category::hideCategoryPosition($category->name)) : Category::hideCategoryPosition($category->name); $edit = '<a href="' . $urlBase . '&id_category=' . $category->id . '&addcategory&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '"><img src="../img/admin/edit.gif" alt="Modify" /></a> '; if ($category->id == 1) { $edit = '<a href="' . $urlBase . '&id_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '"><img src="../img/admin/home.gif" alt="Home" /></a> '; } $path = $edit . '<a href="' . $urlBase . '&id_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '">' . $name . '</a> > ' . $path; if ($category->id == 1) { return substr($path, 0, strlen($path) - 3); } return getPath($urlBase, $category->id_parent, $path); }
/** * getPath() method write breadcrumbs of product for category * * Forced to redo the function from Tools here as it works with cookie * for language, not a passed parameter in the function * * @param int $iCatId * @param int $iCatId * @param string $sPath * @return string */ public static function getPath($iCatId, $iLangId, $sPath = '') { $mReturn = ''; if ($iCatId == 1) { $mReturn = $sPath; } else { // get pipe $sPipe = Configuration::get('PS_NAVIGATION_PIPE'); if (empty($sPipe)) { $sPipe = '>'; } $sFullPath = ''; /* Old way: v1.2 - v1.3 */ if (version_compare(_PS_VERSION_, '1.4.1') == -1) { // instantiate $oCategory = new Category((int) $iCatId, (int) $iLangId); if (Validate::isLoadedObject($oCategory)) { $sCatName = Category::hideCategoryPosition($oCategory->name); // htmlentities because this method generates some view if ($sPath != $sCatName) { $sDisplayedPath = htmlentities($sCatName, ENT_NOQUOTES, 'UTF-8') . $sPipe . $sPath; } else { $sDisplayedPath = htmlentities($sPath, ENT_NOQUOTES, 'UTF-8'); } $mReturn = self::getPath((int) $oCategory->id_parent, $iLangId, trim($sDisplayedPath, $sPipe)); } } else { $aCurrentCategory = Db::getInstance()->getRow(' SELECT id_category, level_depth, nleft, nright FROM ' . _DB_PREFIX_ . 'category WHERE id_category = ' . (int) $iCatId); if (isset($aCurrentCategory['id_category'])) { $sQuery = ' SELECT c.id_category, cl.name, cl.link_rewrite FROM ' . _DB_PREFIX_ . 'category c'; // use case 1.5 if (version_compare(_PS_VERSION_, '1.5', '>')) { Shop::addSqlAssociation('category', 'c', false); } $sQuery .= ' LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category AND cl.`id_lang` = ' . (int) $iLangId . (version_compare(_PS_VERSION_, '1.5', '>') ? Shop::addSqlRestrictionOnLang('cl') : '') . ')'; $sQuery .= ' WHERE c.nleft <= ' . (int) $aCurrentCategory['nleft'] . ' AND c.nright >= ' . (int) $aCurrentCategory['nright'] . ' AND cl.id_lang = ' . (int) $iLangId . ' AND c.id_category != 1 ORDER BY c.level_depth ASC LIMIT ' . (int) $aCurrentCategory['level_depth']; $aCategories = Db::getInstance()->ExecuteS($sQuery); $iCount = 1; $nCategories = count($aCategories); foreach ($aCategories as $aCategory) { $sFullPath .= htmlentities($aCategory['name'], ENT_NOQUOTES, 'UTF-8') . (($iCount++ != $nCategories or !empty($sPath)) ? '<span class="navigation-pipe">' . $sPipe . '</span>' : ''); } $mReturn = $sFullPath . $sPath; } } } return $mReturn; }
function getTree($resultParents, $resultIds, $id_category = 1, $currentDepth = 0) { //print_r($resultParents[$id_category]); global $link; $children = array(); if (isset($resultParents[$id_category]) and sizeof($resultParents[$id_category]) and (Configuration::get('BLOCK_CATEG_ACCORD_MAX_DEPTH') == 0 or $currentDepth < Configuration::get('BLOCK_CATEG_ACCORD_MAX_DEPTH'))) { foreach ($resultParents[$id_category] as $subcat) { $children[] = $this->getTree($resultParents, $resultIds, $subcat['id_category'], $currentDepth + 1); } } if (!isset($resultIds[$id_category])) { return false; } return array('id' => $id_category, 'name' => Category::hideCategoryPosition($resultIds[$id_category]['name']), 'parent' => $resultIds[$id_category]['id_parent'], 'children' => $children); }