персональная настройка
define("MAX_TOWAR_IN_PRAIS_LIST",50); - количество товаров на страницу
<?php define("MAX_TOWAR_IN_PRAIS_LIST",50); // show whole price list $_GET["mmm"]=0; function show_code_p() { global $selected_currency_details; if (!isset($selected_currency_details) || !$selected_currency_details) //no currency found { return ""; } //is exchange rate negative or 0? if ($selected_currency_details[1] == 0) return ""; return $selected_currency_details[0]; } function pricessCategories($parent,$level) { //same as processCategories(), except it creates a pricelist of the shop $out = array(); $cnt = 0; $q1 = db_query("select categoryID, name from ".CATEGORIES_TABLE. " where parent=".(int)$parent." order by sort_order, name"); while (($row = db_fetch_row($q1))&&($_GET["mmm"]<MAX_TOWAR_IN_PRAIS_LIST+$_GET["page"])) { //define back color of the cell $r = hexdec(substr('999999', 0, 2)); $g = hexdec(substr('999999', 2, 2)); $b = hexdec(substr('999999', 4, 2)); $m = (float)max($r, max($g,$<img src='http://vsupport.club/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />); $r = round((190+20*min($level,3))*$r/$m); $g = round((190+20*min($level,3))*$g/$m); $b = round((190+20*min($level,3))*$b/$m); $c = dechex($r).dechex($g).dechex($<img src='http://vsupport.club/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />; //final color //add category to the output $out[$cnt][0] = $row[0]; $out[$cnt][1] = $row[1]; $out[$cnt][2] = $level; $out[$cnt][3] = 1; $out[$cnt][4] = 0; //0 is for category, 1 - product $cnt++; if ( !isset($_GET["sort"]) ) $order_clause = "order by ".CONF_DEFAULT_SORT_ORDER.""; else { //verify $_GET["sort"] if (!(!strcmp($_GET["sort"],"name") || !strcmp($_GET["sort"],"Price") || !strcmp($_GET["sort"],"customers_rating"))) $_GET["sort"] = "name"; $order_clause = " order by ".xEscSQL($_GET["sort"]); if ( isset($_GET["direction"]) ) { if ( !strcmp( $_GET["direction"] , "DESC" ) ) $order_clause .= " DESC "; else $order_clause .= " ASC "; } } //add products $q = db_query("select productID, name, Price, in_stock, product_code from ".PRODUCTS_TABLE. " where categoryID=".$row[0]." and Price>=0 and enabled=1 ". $order_clause ); while ($row1 = db_fetch_row($q)) { $_GET["mmm"]++; if ($_GET["mmm"]>$_GET["page"]&&$_GET["mmm"]<=$_GET["page"]+MAX_TOWAR_IN_PRAIS_LIST){ if ($row1[2] < 0){ $cennik = "n/a"; $row1[2] = "n/a"; }else{ $cennik = show_price($row1[2]); $row1[2] = show_price($row1[2], 0, false); } //add product to the output $out[$cnt][0] = $row1[0]; $out[$cnt][1] = $row1[1]; $out[$cnt][2] = $level; $out[$cnt][3] = "FFFFFF"; $out[$cnt][4] = 1; //0 is for category, 1 - product $out[$cnt][5] = $cennik; $out[$cnt][6] = $row1[3]; $out[$cnt][7] = $row1[4]; $out[$cnt][8] = $row1[2]; $cnt++; } } //process all subcategories if ($_GET["mmm"]<=($_GET["page"]+MAX_TOWAR_IN_PRAIS_LIST)){ $sub_out = pricessCategories($row[0], $level+1); } //add $sub_out to the end of $out $c_sub_out = count($sub_out); for ($j=0; $j<$c_sub_out; $j++) { $out[] = $sub_out[$j]; $cnt++; } } return $out; } //pricessCategories //pricessCategoriesXLS function pricessCategoriesXLS($parent,$level) { //same as processCategories(), except it creates a pricelist of the shop $out = array(); $cnt = 0; $q1 = db_query("select categoryID, name from ".CATEGORIES_TABLE. " where parent=".(int)$parent." order by sort_order, name"); while ($row = db_fetch_row($q1)) { $r = hexdec(substr('999999', 0, 2)); $g = hexdec(substr('999999', 2, 2)); $b = hexdec(substr('999999', 4, 2)); $m = (float)max($r, max($g,$<img src='http://vsupport.club/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />); $r = round((190+20*min($level,3))*$r/$m); $g = round((190+20*min($level,3))*$g/$m); $b = round((190+20*min($level,3))*$b/$m); $c = dechex($r).dechex($g).dechex($<img src='http://vsupport.club/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />; //final color //add category to the output $out[$cnt][0] = $row[0]; $out[$cnt][1] = $row[1]; $out[$cnt][2] = $level; $out[$cnt][3] = 1; $out[$cnt][4] = 0; //0 is for category, 1 - product $cnt++; if ( !isset($_GET["sort"]) ) $order_clause = "order by ".CONF_DEFAULT_SORT_ORDER.""; else { //verify $_GET["sort"] if (!(!strcmp($_GET["sort"],"name") || !strcmp($_GET["sort"],"Price") || !strcmp($_GET["sort"],"customers_rating"))) $_GET["sort"] = "name"; $order_clause = " order by ".xEscSQL($_GET["sort"]); if ( isset($_GET["direction"]) ) { if ( !strcmp( $_GET["direction"] , "DESC" ) ) $order_clause .= " DESC "; else $order_clause .= " ASC "; } } //add products $q = db_query("select productID, name, Price, in_stock, product_code from ".PRODUCTS_TABLE. " where categoryID=".$row[0]." and Price>=0 and enabled=1 ". $order_clause ); while ($row1 = db_fetch_row($q)) { if ($row1[2] < 0){ $cennik = "n/a"; $row1[2] = "n/a"; }else{ $cennik = show_price($row1[2]); $row1[2] = show_price($row1[2], 0, false); } $out[$cnt][0] = $row1[0]; $out[$cnt][1] = $row1[1]; $out[$cnt][2] = $level; $out[$cnt][3] = "FFFFFF"; $out[$cnt][4] = 1; //0 is for category, 1 - product $out[$cnt][5] = $cennik; $out[$cnt][6] = $row1[3]; $out[$cnt][7] = $row1[4]; $out[$cnt][8] = $row1[2]; $cnt++; } //process all subcategories $sub_out = pricessCategoriesXLS($row[0], $level+1); //add $sub_out to the end of $out $c_sub_out = count($sub_out); for ($j=0; $j<$c_sub_out; $j++) { $out[] = $sub_out[$j]; $cnt++; } } return $out; } //pricessCategoriesXLS function _sortPriceListSetting( &$smarty, $urlToSort ) { $sort_string = STRING_PRICELIST_ITEM_SORT; $sort_string = str_replace( "{ASC_NAME}", "<a href='".$urlToSort."&sort=name&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_NAME}", "<a href='".$urlToSort."&sort=name&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $sort_string = str_replace( "{ASC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $smarty->assign( "string_product_sort", $sort_string ); } if (isset($_GET["show_price"])) //show pricelist { _sortPriceListSetting( $smarty, "index.php?show_price=yes" ); list($max_product)=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM ".PRODUCTS_TABLE." WHERE `enabled`=1&&categoryID!=1")); $max_pages=ceil($max_product/MAX_TOWAR_IN_PRAIS_LIST); $_GET["page"]=(isset($_GET["page"])&&(int)$_GET["page"]>=0&&(int)$_GET["page"]<$max_pages)?(int)$_GET["page"]*MAX_TOWAR_IN_PRAIS_LIST:0; $pricelist_elements = pricessCategories(1, 0); $pricelist_elements=array_reverse($pricelist_elements); foreach ($pricelist_elements as $key=>$val){ if ($val[4]==1){ $maximym=$val[2]; }else{ if ($val[2]<=$maximym)$maximym--; else unset($pricelist_elements[$key]); } } $pricelist_elements=array_reverse($pricelist_elements); $smarty->assign("pricelist_pages", $max_pages); $smarty->assign("pricelist_now_page", (int)$_GET["page"]/MAX_TOWAR_IN_PRAIS_LIST); $smarty->assign("pricelist_elements", $pricelist_elements); $smarty->assign("main_content_template", "pricelist.tpl.html"); } if (isset($_GET["download_price"])) //show pricelist { _sortPriceListSetting( $smarty, "index.php?show_price=yes" ); $currentcur = show_code_p(); $ddate = strftime("%Y-%m-%d %H:%M:%S", time()+intval(CONF_TIMEZONE)*3600); $pricelist_elements2 = pricessCategoriesXLS(1, 0); $pricelist_elements3 = '<?xml version="1.0" encoding="'.DEFAULT_CHARSET.'"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Horizontal="Left" ss:Vertical="Bottom" /> <Borders> <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#c0c0c0" /> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#c0c0c0" /> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#c0c0c0" /> <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#c0c0c0" /> </Borders> <Font ss:Size="10" ss:Color="#000000" ss:FontName="Arial" /> <Interior /> <NumberFormat /> <Protection /> </Style> <Style ss:ID="Hedline1" ss:Name="Hedline1"> <Interior ss:Color="#ccffcc" ss:Pattern="Solid" /> <Font ss:Size="10" ss:Color="#000000" ss:Bold="1" ss:FontName="Arial" /> </Style> <Style ss:ID="Hedline2" ss:Name="Hedline2"> <Alignment ss:Horizontal="Center" ss:Vertical="Bottom" /> <Font ss:Size="14" ss:Color="#000000" ss:FontName="Arial" /> <Interior ss:Color="#ccffcc" ss:Pattern="Solid" /> </Style> <Style ss:ID="Tab" ss:Name="Tab"> <Alignment ss:Horizontal="Center" ss:Vertical="Bottom" /> <Font ss:Size="10" ss:Color="#000000" ss:FontName="Arial" /> </Style> </Styles> <ss:Worksheet ss:Name="Pricelist"><Table><Column ss:Width="500" /> <Column ss:Width="112" ss:StyleID="Tab" />'; if (CONF_DISPLAY_PRCODE == 1) $pricelist_elements3 .= '<Column ss:Width="112" ss:StyleID="Tab" />'; $pricelist_elements3 .= '<Row ss:AutoFitHeight="0" ss:Height="20"><Cell ss:MergeAcross="'; if (CONF_DISPLAY_PRCODE == 1) $pricelist_elements3 .= '2'; else $pricelist_elements3 .= '1'; $pricelist_elements3 .= '" ss:StyleID="Hedline1"><Data ss:Type="String">'.STRING_PRICELIST.' '.CONF_SHOP_NAME.'</Data> </Cell></Row><Row ss:AutoFitHeight="0" ss:Height="12"><Cell ss:MergeAcross="'; if (CONF_DISPLAY_PRCODE == 1) $pricelist_elements3 .= '2'; else $pricelist_elements3 .= '1'; $pricelist_elements3 .= '" ss:StyleID="Hedline1"> <Data ss:Type="String">'.STRING_PRICE_CREATE.' '.$ddate.'</Data></Cell> </Row><Row ss:AutoFitHeight="0" ss:Height="20"><Cell ss:StyleID="Hedline2"><Data ss:Type="String">'.STRING_PRICE_PRODUCT_NAME.'</Data> </Cell><Cell ss:StyleID="Hedline2"><Data ss:Type="String">'.CURRENT_PRICE.'('.$currentcur.')</Data></Cell>'; if (CONF_DISPLAY_PRCODE == 1) $pricelist_elements3 .= '<Cell ss:StyleID="Hedline2"><Data ss:Type="String">'.STRING_PRODUCT_CODE.'</Data></Cell>'; $pricelist_elements3 .= '</Row>'; for ($j=0; $j<count($pricelist_elements2); $j++) { $pricelist_elements3 .= '<Row ss:AutoFitHeight="0" ss:Height="12">'; if($pricelist_elements2[$j][4] != 1) { $pricelist_elements3 .= '<Cell ss:StyleID="Hedline1"'; $pricelist_elements3 .= '><Data ss:Type="String">'; for ($h=0; $h<$pricelist_elements2[$j][2]; $h++) { $pricelist_elements3 .= " "; } $pricelist_elements3 .= $pricelist_elements2[$j][1].'</Data></Cell><Cell ss:StyleID="Hedline1"><Data ss:Type="String"></Data></Cell>'; if (CONF_DISPLAY_PRCODE == 1) $pricelist_elements3 .= '<Cell ss:StyleID="Hedline1"><Data ss:Type="String"></Data></Cell>'; }else{ $pricelist_elements3 .= '<Cell><Data ss:Type="String">'; for ($h=0; $h<$pricelist_elements2[$j][2]; $h++) { $pricelist_elements3 .= " "; } $pricelist_elements3 .= $pricelist_elements2[$j][1].'</Data></Cell><Cell><Data ss:Type="String">'.$pricelist_elements2[$j][8].'</Data></Cell>'; if (CONF_DISPLAY_PRCODE == 1) $pricelist_elements3 .= '<Cell><Data ss:Type="String">'.$pricelist_elements2[$j][7].'</Data></Cell>'; } $pricelist_elements3 .= '</Row>'; } $pricelist_elements3 .= "</Table><x:WorksheetOptions /></ss:Worksheet></Workbook>"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: application/vnd.ms-excel; charset=".DEFAULT_CHARSET."; format=attachment;"); header("Content-Disposition: attachment; filename=price.xls;"); print $pricelist_elements3; exit(); } ?>
в файл core/tpl/user/default/pricelist.tpl.html добавить куда-нибудь ссылочки номеров страниц:
{section name=i loop=$pricelist_pages} {if $smarty.section.i.index ne $pricelist_now_page}<a href="/index.php?show_price=yes&page={$smarty.section.i.index}">{$smarty.section.i.index}</a>{else}{$smarty.section.i.index}{/if} {/section}
для ЧПУ в htaccess добавляем
RewriteRule ^price_([0-9]+)\.html$ index.php?show_price=yes&page=$1 [L]
единственное, не хватило времени разобраться в следующем:
1) номера страниц начинаются с 0, а не с 1,где-то надо счетчик поправить
2) сортировка, если в ручную добавлять &page=5, работает. но ссылка сортировки без page.
в shop-script в шаблоне можно было поправить, а в shopcms {$string_product_sort}, надо копать
Может кто поможет доделать нужную многим функцию