Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
пациентКаким образом? Какая библиотека используется? Причем здесь вообще верстка?
<?php
require_once('api/Simpla.php');
$simpla = new Simpla();
header('Content-Type: text/html; charset=windows-1251');
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
header('Content-transfer-encoding: binary');
header('Content-Disposition: attachment; filename=price.xls');
header('Content-Type: application/x-unknown');
print "
<!DOCTYPE HTML>
<html>
<head>
<base href='".$simpla->config->root_url."'/>
<title>Прайс-лист :: ".$simpla->settings->site_name." :: ".$simpla->settings->company_name."</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<meta http-equiv='Cache-Control' content='public'>
<!--[if gte mso 9]>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Прайс</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
<x:PaperSizeIndex>9</x:PaperSizeIndex>
<x:Scale>60</x:Scale>
<x:HorizontalResolution>600</x:HorizontalResolution>
<x:VerticalResolution>0</x:VerticalResolution>
</x:Print>
<x:ShowPageBreakZoom/>
<x:Selected/>
<x:TopRowVisible>36</x:TopRowVisible>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveRow>5</x:ActiveRow>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>10005</x:WindowHeight>
<x:WindowWidth>10005</x:WindowWidth>
<x:WindowTopX>120</x:WindowTopX>
<x:WindowTopY>135</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml>
<![endif]-->
</head>
<body>
";
$categories = $simpla->categories->get_categories_tree();
$treefunc=tree($categories);
print "</body></html>";
function tree($c) {
$simpla = new simpla();
// Валюты
$currencies = $simpla->money->get_currencies(array('enabled'=>1));
$currency_code = reset($currencies)->sign;
foreach($c as $cat){
if($cat->visible==1){
// Товары
$simpla->db->query("SET SQL_BIG_SELECTS=1");
$simpla->db->query("SELECT p.id FROM __products p LEFT JOIN __products_categories pc ON p.id = pc.product_id LEFT JOIN __categories pcat ON pc.category_id = pcat.id
WHERE p.visible AND pcat.visible AND pc.category_id=$cat->id ORDER BY p.id");
$print_tbl = 0;
$catw = 1200; // Ширина колонки с названием товара
$catm = 0;
if($simpla->db->result()){
$path_name = "";
$print_tbl = 1;
foreach($cat->path as $path){
if ($path->parent_id>0){
$catw-=20; // Величина отступа для подразделов
$catm+=20;
$path_name .= " » ";
}
$path_name .= esc($path->name);
}
print "
<table border=0 cellpadding=0 cellspacing=0 width=425 style='border-collapse:
collapse;table-layout:fixed;width:319pt'>
<col width=425 style='mso-width-source:userset;mso-width-alt:15542;width:319pt'>
<tr height=20 style='height:15.0pt'>
<td height=20 width=425 style='height:15.0pt;width:319pt'><strong>Наименование</strong></td>
<td><strong>Цена, ".$currency_code."</strong></td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=425 style='width:319pt'><strong>Наименование</strong></td>
<td><strong>Цена, ".$currency_code."</strong></td>
</tr>
<![endif]>";
}
$simpla->db->query("SELECT v.price, v.sku, v.id as variant_id, p.name as product_name, v.name as variant_name, v.position as variant_position, p.id as product_id, p.url, pc.category_id
FROM __variants v LEFT JOIN __products p ON v.product_id=p.id
LEFT JOIN __products_categories pc ON p.id = pc.product_id AND pc.position=(SELECT MIN(position) FROM __products_categories WHERE product_id=p.id LIMIT 1)
LEFT JOIN __categories pcat ON pc.category_id = pcat.id
WHERE p.visible AND pcat.visible AND pc.category_id=$cat->id AND (v.stock >0 OR v.stock is NULL) GROUP BY v.id ORDER BY p.id, v.position");
// В цикле мы используем не results(), a result(), то есть выбираем из базы товары по одному,
// так они нам одновременно не нужны - мы всё равно сразу же отправляем товар на вывод.
// Таким образом используется памяти только под один товар
$prev_product_id = null;
while($p = $simpla->db->result())
{
$sku = '';
if ($p->sku)
$sku = ' :: артикул: '.$p->sku;
$variant_url = '';
if ($prev_product_id === $p->product_id)
$variant_url = '?variant='.$p->variant_id;
$prev_product_id = $p->product_id;
$price = $simpla->money->convert($p->price, $main_currency->id, true);
// Если не хотим отделять разряды
//$price = round($simpla->money->convert($p->price, $main_currency->id, false),2);
print
"<tr>
<td height=40 width=425 style='height:15.0pt;width:319pt'><a href='".$simpla->config->root_url.'/products/'.$p->url.$variant_url."' target='_blank'>".esc($p->product_name).($p->variant_name?' ('.esc($p->variant_name.')'):'').esc($sku)."</a>
</td>";
print "<td>$price</td>
</tr>
";
}
if($print_tbl == 1)
print "</tbody></table><br/>";
if ($cat->subcategories)
$treefunc=tree($cat->subcategories);
}
}
}
function esc($s)
{
return(htmlspecialchars($s, ENT_QUOTES, 'UTF-8'));
}