Side antal 1 2 3
Hej,Er der nogen som kan hjælpe mig med at lave et script hvor jeg får side antal vist på siden med produkter?
<?php
if (!defined('CC_INI_SET')) die("Access Denied");
// include lang file
$lang = getLang("includes".CC_DS."content".CC_DS."viewCat.inc.php");
$page = (isset($_GET['page'])) ? sanitizeVar($_GET['page']) : 0;
$view_cat = new XTemplate ("content".CC_DS."viewCat.tpl");
$view_cat->assign("LANG_DIR_LOC", $lang['viewCat']['location']);
////////////////////////
// BUILD SUB CATEGORIES
////////////////////////
if (isset($_GET['catId'])) {
$_GET['catId'] = sanitizeVar($_GET['catId']);
## build query
$emptyCat = ($config['show_empty_cat']==true) ? '' : ' AND noProducts >= 1';
$query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_father_id = ".$db->mySQLSafe($_GET['catId'])." AND hide = 0".$emptyCat." ORDER BY priority,cat_name ASC";
## get category array in foreign innit
$resultsForeign = $db->select("SELECT cat_master_id as cat_id, cat_name FROM ".$glob['dbprefix']."CubeCart_cats_lang WHERE cat_lang = '" . LANG_FOLDER . "'");
## query database
$subCategories = false;
$subCategories = $db->select($query);
}
if (isset($_GET['catId']) && $_GET['catId']>0 && $subCategories == true) {
## loop results
for ($i=0; $i<count($subCategories); $i++) {
if (is_array($resultsForeign)) {
for ($k=0; $k<count($resultsForeign); $k++) {
if ($resultsForeign[$k]['cat_id'] == $subCategories[$i]['cat_id']) {
$subCategories[$i]['cat_name'] = $resultsForeign[$k]['cat_name'];
}
}
}
if (empty($subCategories[$i]['cat_image'])) {
$view_cat->assign("IMG_CATEGORY", $GLOBALS['rootRel']."skins/". SKIN_FOLDER . "/styleImages/catnophoto.gif");
} else {
$view_cat->assign("IMG_CATEGORY", imgPath($subCategories[$i]['cat_image'],$thumb=0,$path="rel"));
}
$view_cat->assign("TXT_LINK_CATID",$subCategories[$i]['cat_id']);
$view_cat->assign("TXT_CATEGORY", validHTML($subCategories[$i]['cat_name']));
$view_cat->assign("NO_PRODUCTS", $subCategories[$i]['noProducts']);
$view_cat->parse("view_cat.sub_cats.sub_cats_loop");
}
$view_cat->parse("view_cat.sub_cats");
}
////////////////////////////
// BUILD PRODUCTS
////////////////////////////
## New! Product sorting by field
$allowedSort = array('price', 'description', 'name', 'productCode');
if (isset($_GET['sort_by']) && in_array($_GET['sort_by'], $allowedSort)) {
switch ($_GET['sort_order']) {
case 'high':
$orderType = 'DESC';
$orderText = '&uarr';
$sortIcon = 'bullet_arrow_up.gif';
break;
case 'low':
$orderType = 'ASC';
$orderText = '&darr';
$sortIcon = 'bullet_arrow_down.gif';
break;
default:
$orderType = 'ASC';
$sortIcon = 'bullet_arrow_down.gif';
}
$orderSort = sprintf(' ORDER BY %s %s', $_GET['sort_by'], $orderType);
} else {
$orderSort = sprintf(' ORDER BY name ASC');
}
## build query
if (!empty($_REQUEST['searchStr'])) {
/* SPIFFING NEW SEARCH FUNCTIONALITY - Version 1.1 */
$indexes = $db->getFulltextIndex('inventory', 'I'); //array('inventory', 'inv_lang'));
if (!empty($_REQUEST['priceMin']) && is_numeric($_REQUEST['priceMin'])) $where[] = sprintf("I.price >= %s", $_REQUEST['priceMin']);
if (!empty($_REQUEST['priceMax']) && is_numeric($_REQUEST['priceMax'])) $where[] = sprintf("I.price <= %s", $_REQUEST['priceMax']);
if (isset($_REQUEST['inStock'])) $where[] = "((I.useStockLevel = 0) OR (I.useStockLevel = 1 AND I.stock_level > 0))";
if (!empty($_REQUEST['category'])) {
if (is_array($_REQUEST['category'])) {
foreach ($_REQUEST['category'] as $cat_id) {
if (is_numeric($cat_id)) $cats[] = $cat_id;
}
$where[] = sprintf("I.cat_id IN (%s)", implode(',', $cats));
} else if (is_numeric($_REQUEST['category'])) {
$where[] = sprintf("I.cat_id = '%d'", $_REQUEST['category']);
}
}
if (is_array($indexes)) {
switch ($config['searchMode']) {
case 'boolean':
$mode = ' IN BOOLEAN MODE';
break;
case 'expansion':
$mode = ' WITH QUERY EXPANSION';
break;
default:
$mode = '';
}
if (is_array($where)) $whereString = sprintf('AND %s', implode(' AND ', $where));
if (!empty($_REQUEST['searchStr'])) {
if (!empty($orderSort)) {
$orderSort = str_replace(' ORDER BY', '', $orderSort);
} else {
$orderSort = 'SearchScore DESC';
}
$matchString = sprintf("MATCH (%s) AGAINST(%s%s)", implode(',', $indexes), $db->mySQLsafe($_REQUEST['searchStr']), $mode);
$search = sprintf("SELECT I.*, %2\$s AS SearchScore FROM %1\$sCubeCart_inventory AS I LEFT JOIN %1\$sCubeCart_category AS C ON C.cat_id = I.cat_id WHERE I.cat_id > 0 AND C.hide = 0 AND (%2\$s) >= %4\$f %3\$s ORDER BY %5\$s", $glob['dbprefix'], $matchString, $whereString, 0.5, $orderSort);
} else {
$search = sprintf("SELECT I.* FROM %sCubeCart_inventory AS I WHERE I.cat_id > 0 %s %s", $glob['dbprefix'], $whereString, $orderSort);
}
$productListQuery = $search;
}
$productResults = $db->select($productListQuery, $config['productPages'], $page);
## FALLBACK - If search doesn't work, try the old v3 style search
if (!$productResults) {
$searchwords = split ( "[ ,]", sanitizeVar($_REQUEST['searchStr']));
foreach ($searchwords as $word) {
$searchArray[] = $word;
}
$noKeys = count($searchArray);
$like = '';
for ($i=0; $i<$noKeys; $i++) {
## Uppercase the search string
$ucSearchTerm = strtoupper($searchArray[$i]);
if (($ucSearchTerm !== 'AND') && ($ucSearchTerm !== 'OR')) {
$like .= "(name LIKE '%".$searchArray[$i]."%' OR description LIKE '%".$searchArray[$i]."%' OR productCode LIKE '%".$searchArray[$i]."%') OR ";
## See if search terrm is in database
$searchQuery = "SELECT id FROM ".$glob['dbprefix']."CubeCart_search WHERE searchstr='".$ucSearchTerm."'";
$searchLogs = $db->select($searchQuery);
$insertStr = array(
'searchstr' => $db->mySQLsafe($ucSearchTerm),
'hits' => 1,
);
$updateStr = array(
'hits' => 'hits+1',
);
if ($searchLogs) {
$db->update($glob['dbprefix'].'CubeCart_search', $updateStr, 'id='.$searchLogs[0]['id'], '');
} else if (!empty($_REQUEST['searchStr'])) {
$db->insert($glob['dbprefix'].'CubeCart_search', $insertStr);
}
} else {
$like = substr($like, 0, strlen($like)-3);
$like .= $ucSearchTerm;
}
}
$like = substr($like, 0, strlen($like)-3);
$productListQuery = "SELECT * FROM ".$glob['dbprefix']."CubeCart_inventory WHERE ".$like;
$productResults = $db->select($productListQuery, $config['productPages'], $page);
}
} else if ($_GET['catId'] == 'saleItems' && $config['saleMode']>0) {
$productListQuery = "SELECT ".$glob['dbprefix']."CubeCart_cats_idx.cat_id, ".$glob['dbprefix']."CubeCart_cats_idx.productId, productCode, quantity, description, image, price, name, popularity, sale_price, stock_level, useStockLevel FROM ".$glob['dbprefix']."CubeCart_cats_idx INNER JOIN ".$glob['dbprefix']."CubeCart_inventory ON ".$glob['dbprefix']."CubeCart_cats_idx.productId = ".$glob['dbprefix']."CubeCart_inventory.productId WHERE sale_price > 0 AND ".$glob['dbprefix']."CubeCart_cats_idx.cat_id > 0 GROUP BY ".$glob['dbprefix']."CubeCart_inventory.productId".$orderSort;
} else {
$productListQuery = "SELECT ".$glob['dbprefix']."CubeCart_cats_idx.cat_id, ".$glob['dbprefix']."CubeCart_cats_idx.productId, productCode, quantity, description, image, price, name, popularity, sale_price, stock_level, useStockLevel FROM ".$glob['dbprefix']."CubeCart_cats_idx INNER JOIN ".$glob['dbprefix']."CubeCart_inventory ON ".$glob['dbprefix']."CubeCart_cats_idx.productId = ".$glob['dbprefix']."CubeCart_inventory.productId WHERE ".$glob['dbprefix']."CubeCart_cats_idx.cat_id = ".$db->mySQLSafe($_GET['catId'])." GROUP BY ".$glob['dbprefix']."CubeCart_inventory.productId".$orderSort;
}
## Run query if we haven't already done a search
if (!$productResults) {
$productResults = $db->select($productListQuery, $config['productPages'], $page);
}
## Get different languages
if ($productResults && LANG_FOLDER !== $config['defaultLang']) {
for ($i=0;$i<count($productResults);$i++) {
if (($val = prodAltLang($productResults[$i]['productId'])) == true) {
$productResults[$i]['name'] = $val['name'];
$productResults[$i]['description'] = $val['description'];
}
}
}
$totalNoProducts = $db->numrows($productListQuery);
## Get current category info
if (isset($_GET['catId'])) {
if ($config['seftags']) {
if ($_GET['catId']>0) {
$currentCatQuery = "SELECT cat_metatitle, cat_metadesc, cat_metakeywords, cat_name, cat_father_id, cat_id, cat_image, cat_desc FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_id = ".$db->mySQLSafe($_GET['catId'])." ORDER BY priority,cat_name ASC";
$currentCat = $db->select($currentCatQuery);
$prevDirSymbol = $config['dirSymbol'];
$config['dirSymbol'] = ' - ';
$meta['siteTitle'] = getCatDir($currentCat[0]['cat_name'],$currentCat[0]['cat_father_id'], $currentCat[0]['cat_id'], FALSE, TRUE, $config['sefprodnamefirst'] ? FALSE : TRUE);
$config['dirSymbol'] = $prevDirSymbol;
$meta['metaDescription'] = strip_tags($config['metaDescription']);
$meta['sefSiteTitle'] = $currentCat[0]['cat_metatitle'];
$meta['sefSiteDesc'] = $currentCat[0]['cat_metadesc'];
$meta['sefSiteKeywords'] = $currentCat[0]['cat_metakeywords'];
} else if (strcmp($_GET['catId'], "saleItems") == 0) {
$meta['siteTitle'] = $lang['front']['boxes']['sale_items'];
$meta['metaDescription'] = strip_tags($config['metaDescription']);
}
} else if (is_numeric($_GET['catId'])) {
$currentCatQuery = "SELECT cat_name, cat_father_id, cat_id, cat_image, cat_desc FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_id = ".$db->mySQLSafe($_GET['catId'])." ORDER BY priority,cat_name ASC";
$currentCat = $db->select($currentCatQuery);
}
# Get translations
$resultForeign = $db->select("SELECT cat_master_id as cat_id, cat_name, cat_desc FROM ".$glob['dbprefix']."CubeCart_cats_lang WHERE cat_lang = '".LANG_FOLDER."' AND cat_master_id = ".$db->mySQLSafe($_GET['catId']));
if ($resultForeign == true) {
$currentCat[0]['cat_name'] = $resultForeign[0]['cat_name'];
$currentCat[0]['cat_desc'] = $resultForeign[0]['cat_desc'];
}
}
if (!empty($currentCat[0]['cat_image'])) {
$view_cat->assign("IMG_CURENT_CATEGORY",imgPath($currentCat[0]['cat_image'],$thumb=0,$path="rel"));
$view_cat->assign("TXT_CURENT_CATEGORY",validHTML($currentCat[0]['cat_name']));
$view_cat->parse("view_cat.cat_img");
}
if (isset($_REQUEST['searchStr'])) {
$view_cat->assign("TXT_CAT_TITLE", $lang['viewCat']['search_results']);
$view_cat->assign("CURRENT_LOC", $config['dirSymbol'].$lang['viewCat']['search_results']);
} else if ($_GET['catId']=="saleItems" && $config['saleMode']>0) {
$view_cat->assign("TXT_CAT_TITLE", $lang['viewCat']['sale_items']);
$view_cat->assign("CURRENT_LOC", $config['dirSymbol'].$lang['viewCat']['sale_items']);
} else {
$view_cat->assign("TXT_CAT_TITLE", validHTML($currentCat[0]['cat_name']));
$view_cat->assign("CURRENT_LOC", getCatDir($currentCat[0]['cat_name'], $currentCat[0]['cat_father_id'], $currentCat[0]['cat_id'], $link=true));
}
if (!empty($currentCat[0]['cat_desc'])) {
$view_cat->assign("TXT_CAT_DESC", $currentCat[0]['cat_desc']);
$view_cat->parse("view_cat.cat_desc");
}
$view_cat->assign("LANG_IMAGE", $lang['viewCat']['image']);
$view_cat->assign("LANG_DESC", $lang['viewCat']['description']);
$view_cat->assign("LANG_NAME", $lang['viewCat']['name']);
$view_cat->assign("LANG_PRICE", $lang['viewCat']['price']);
$pagination = paginate($totalNoProducts, $config['productPages'], $page, "page");
if (!empty($pagination)) {
$view_cat->assign("PAGINATION", $pagination);
$view_cat->parse("view_cat.pagination_top");
$view_cat->parse("view_cat.pagination_bot");
}
## create the links for product sorting - need improving later
$sort_order = ($_GET['sort_order'] == 'high') ? 'low' : 'high';
switch($_GET['sort_by']) {
case 'name':
$view_cat->assign('SORT_NAME_SELECTED', ' selected="selected"');
break;
case 'price':
$view_cat->assign('SORT_PRICE_SELECTED', ' selected="selected"');
break;
}
# $view_cat->assign('SORT_DIRECTION_TEXT', $orderText);
unset($_GET['sort_by'], $_GET['sort_order']);
$view_cat->assign('SORT_PROD_CODE', currentPage()."&sort_by=productCode&sort_order=".$sort_order);
$view_cat->assign('SORT_PRICE', currentPage()."&sort_by=price&sort_order=".$sort_order);
$view_cat->assign('SORT_DESC', currentPage()."&sort_by=description&sort_order=".$sort_order);
$view_cat->assign('SORT_NAME', currentPage()."&sort_by=name&sort_order=".$sort_order);
if (!empty($sortIcon) && file_exists('skins'.CC_DS.SKIN_FOLDER.CC_DS.'styleImages'.CC_DS.'icons'.CC_DS.$sortIcon)) {
$view_cat->assign('SORT_ICON', sprintf('<img src="%s", alt="" />', 'skins'.CC_DS.SKIN_FOLDER.CC_DS.'styleImages'.CC_DS.'icons'.CC_DS.$sortIcon));
}
## repeated region
if ($productResults) {
for ($i=0; $i<count($productResults); $i++) {
## alternate class
$view_cat->assign("CLASS",cellColor($i, $tdEven="tdEven", $tdOdd="tdOdd"));
$thumbRoot = imgPath($productResults[$i]['image'], $thumb=1, $path="root");
$thumbRootRel = imgPath($productResults[$i]['image'], $thumb=1, $path="rel");
if (file_exists($thumbRoot)) {
$view_cat->assign("SRC_PROD_THUMB", $thumbRootRel);
} else {
$view_cat->assign("SRC_PROD_THUMB", $GLOBALS['rootRel']."skins/". SKIN_FOLDER . "/styleImages/thumb_nophoto.gif");
}
$view_cat->assign("TXT_TITLE", validHTML($productResults[$i]['name']));
if (strlen($productResults[$i]['description']) > $config['productPrecis']) {
$view_cat->assign("TXT_DESC", substr(strip_tags($productResults[$i]['description']), 0, $config['productPrecis'])."…");
} else {
$view_cat->assign("TXT_DESC", $productResults[$i]['description']);
}
if (salePrice($productResults[$i]['price'], $productResults[$i]['sale_price']) == false) {
$view_cat->assign("TXT_PRICE", priceFormat($productResults[$i]['price'], true));
} else {
$view_cat->assign("TXT_PRICE","<span class='txtOldPrice'>".priceFormat($productResults[$i]['price'],true)."</span>");
}
$salePrice = salePrice($productResults[$i]['price'], $productResults[$i]['sale_price']);
$view_cat->assign("TXT_SALE_PRICE", priceFormat($salePrice,true));
if (isset($_GET['add']) && isset($_GET['quan'])) {
$view_cat->assign("CURRENT_URL", str_replace(array("&add=".$_GET['add'], "&quan=".$_GET['quan']), '', currentPage()));
} else {
$view_cat->assign("CURRENT_URL", currentPage());
}
if ($config['outofstockPurchase'] == true) {
$view_cat->assign("BTN_BUY", $lang['viewCat']['buy']);
$view_cat->assign("PRODUCT_ID", $productResults[$i]['productId']);
$view_cat->parse("view_cat.productTable.products.buy_btn");
} else if ($productResults[$i]['useStockLevel'] == true && $productResults[$i]['stock_level']>0) {
$view_cat->assign("BTN_BUY", $lang['viewCat']['buy']);
$view_cat->assign("PRODUCT_ID", $productResults[$i]['productId']);
$view_cat->parse("view_cat.productTable.products.buy_btn");
} else if ($productResults[$i]['useStockLevel'] == false) {
$view_cat->assign("BTN_BUY", $lang['viewCat']['buy']);
$view_cat->assign("PRODUCT_ID", $productResults[$i]['productId']);
$view_cat->parse("view_cat.productTable.products.buy_btn");
}
$view_cat->assign("BTN_MORE", $lang['viewCat']['more']);
$view_cat->assign("PRODUCT_ID", $productResults[$i]['productId']);
if ($productResults[$i]['stock_level']<1 && $productResults[$i]['useStockLevel'] == true && $productResults[$i]['digital'] == false) {
$view_cat->assign("TXT_OUTOFSTOCK", $lang['viewCat']['out_of_stock']);
} else {
$view_cat->assign("TXT_OUTOFSTOCK", '');
}
$view_cat->parse("view_cat.productTable.products");
}
$view_cat->assign("LANG_SORT", $lang['viewCat']['sort']);
$view_cat->parse("view_cat.productTable");
} else if (!$productResults && isset($_REQUEST['searchStr'])) {
$view_cat->assign("TXT_NO_PRODUCTS", sprintf($lang['viewCat']['no_products_match'], sanitizeVar($_REQUEST['searchStr'])));
$view_cat->parse("view_cat.noProducts");
} else {
$view_cat->assign("TXT_NO_PRODUCTS", $lang['viewCat']['no_prods_in_cat']);
$view_cat->parse("view_cat.noProducts");
}
$view_cat->parse("view_cat");
$page_content = $view_cat->text("view_cat");
?>
