function formatPrice(price) {
const zeroPad = (num, places) => String(num).padStart(places, '0')
if (price > 1000)
return Math.floor(price / 1000) + " " + zeroPad(price % 1000, 3);
else
return price;
}
function BuildOneBlockProduct(element)
{
var img = element.product_image;
if (typeof img == "undefined") img = "";
if (img != "") img = img + "_m.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
var result = "
';
return result;
}
function BuildOneBlockModel(element)
{
var img = element.model_img;
if (typeof img == "undefined") img = "";
if (img != "") img = img + ".jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
var result;
result = "';
return result;
}
function BuildBlocks(list)
{
var data = "";
//var x = 0;
for (i in list)
{
if ((list[i].product_id > 0) && (list[i].product_enabled == '1'))
data = data + BuildOneBlockProduct(list[i]);
if (list[i].model_id > 0)
data = data + BuildOneBlockModel(list[i]);
}
return data;
}
function BuildListLineProduct(element)
{
var img = element.product_image;
if (typeof img == "undefined") img = "";
if (img != "") img = img + "_s.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
var result = "";
result += "
" + element.product_name + "
";
if (element.product_desc != "")
result += element.product_desc + "
";
result += 'Артикул:
' + element.product_id + '';
for (var i = 0; i < element.stars; i++)
result += '

';
result += "
";
result += "
";
/*result = result + "
";*/
result += "";
result += "
";
var norm_price = element.product_normprice;
if (norm_price > 0)
result += '' + norm_price + ' руб
';
var min_price = element.product_minprice;
if ((min_price > 0) && (min_price < norm_price))
result += '' + min_price + ' руб';
var self_price = element.product_selfprice;
if (self_price > 0)
result += '
(' + self_price + 'руб)';
result += "
";
result += element.avail;
result += "
";
result += "";
result += "";
return result;
}
function LinkCommentClick(id) {};
function BuildListLineProduct3(element)
{
var img = element.product_image;
if (typeof img == "undefined") img = "";
if (img != "") img = img + "_s.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
if (typeof element.link_source == "undefined")
element.link_source = "";
if (typeof element.link_active == "undefined")
element.link_active = "1";
var result = "";
if (element.availcount > 0)
result += "

";
else
result += "

";
result += "
";
if (parseInt(Number(element.product_desc)) > 0) {
element.product_name += " - " + element.product_desc;
element.product_desc = "";
}
result += "
" + element.product_name + " ";
if (element.product_desc != "")
result += element.product_desc + " ";
result += 'Артикул: ' + element.product_id + '';
for (var i = 0; i < element.stars; i++)
result += '  ';
if (typeof element.link_comment != "undefined")
result += ' ";
result += " |
";
result += "
";
result += "
";
result += "
";
var norm_price = element.product_normprice;
if (norm_price > 0)
result += '' + formatPrice(norm_price) + ' руб ';
var min_price = element.product_minprice;
if ((min_price > 0) && (min_price < norm_price))
result += '' + formatPrice(min_price) + ' руб';
var self_price = element.product_selfprice;
if (self_price > 0)
result += ' ' + formatPrice(self_price) + ' руб';
result += " |
";
result += "
";
result += "
";
result += "
";
result += "";
return result;
}
function BuildListLineProduct2(element)
{
var img = element.product_image;
if (typeof img == "undefined") img = "";
if (img != "") img = img + "_s.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
var result = "";
result += "
";
if (element.availcount > 0)
result += " ";
else
result += " ";
result += " | ";
result += element.product_name + " ";
if (element.product_desc != "")
result += element.product_desc + " ";
result += 'Артикул: ' + element.product_id + '';
result += " | ";
var norm_price = element.product_normprice;
if (norm_price > 0)
result += '' + norm_price + ' руб ';
var min_price = element.product_minprice;
if ((min_price > 0) && (min_price < norm_price))
result += '' + min_price + ' руб';
var self_price = element.product_selfprice;
if (self_price > 0)
result += ' (' + self_price + 'руб)';
result += " | ";
result += " ";
result += " | ";
result += " |
";
result += "
";
return result;
}
function BuildListLineModel(element)
{
return '=';
}
function BuildList(list)
{
var data = '';
for (i in list)
{
if (list[i].product_id > 0)
data = data + BuildListLineProduct3(list[i]);
if (list[i].model_id > 0)
data = data + BuildListLineModel(list[i]);
}
data = data + "
";
return data;
}
function BuildModelProducts(list) {
const cats = [
["28,29,30", "Фильтры", false],
["91", "Свечи", false],
["44", "Тормозные колодки", true],
["64,65,15", "Сальники и пыльники", true],
["38,39", "Цепи, звезды", true],
["82,83", "Подшипники", false],
["85", "Аккумуляторы", true],
["26", "Сцепление", false],
["84,86,87,89,90,92", "Резина", true],
["73", "Масло, смазки", true]
];
var data = '';
for (i = 0; i < cats.length; i++) {
nums = cats[i][0].split(',');
title = cats[i][1];
var prods = [];
for (x in list) {
if ((nums.includes(list[x].product_category)) && (list[x].link_active != "0")) {
if ((list[x].availcount > 0) || (!cats[i][2]))
prods.push(list[x]);
}
}
if (prods.length > 0) {
data += "
" + title + "
";
for (x in prods) {
if (prods[x].product_id > 0)
data += BuildListLineProduct3(prods[x]);
index = list.indexOf(prods[x]);
list.splice(index, 1);
}
data += "
";
}
}
var dis_cnt = 0;
if (list.length > 0) {
data += "
Прочее
";
for (x in list) {
if (list[x].link_active == "0") dis_cnt++;
else
if ((list[x].product_id > 0) && (list[x].availcount > 0))
data += BuildListLineProduct3(list[x]);
}
data += "
";
}
if (dis_cnt > 0) {
data += "
Отключенное
";
for (x in list) {
if ((list[x].link_active == "0") && (list[x].product_id > 0))
data += BuildListLineProduct3(list[x]);
}
data += "
";
}
data = data + "
";
return data;
}
function BuildTableLineProduct(element)
{
var result;
if (element.product_enabled == '1')
result = "" + element.product_id;
else
result = " |
" + element.product_id;
for (var i = 0; i < element.stars; i++)
result = result + ' ';
var img = element.product_image;
if (typeof img == "undefined") img = "";
if (img != "") img = img + "_s.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
result = result + ' ' + ' ';
result = result + ' | ';
result = result + '' + element.product_name + ' | ' + element.product_desc + ' | ' + element.product_weight + ' | ';
if (element.product_selfprice > 0)
result = result + '' + element.product_selfprice + ' | ';
if (element.product_minprice > 0)
result = result + '' + element.product_minprice + ' | ';
result = result + '' + element.product_normprice + ' | ';
result = result + '' + element.avail + ' | ';
result = result + '
';
return result;
}
function BuildTableLineModel(element)
{
return '=';
}
function BuildTable(list)
{
var data = 'Артикул | Название | Описание | Вес | ';
var selfprice = 0;
var minprice = 0;
for (i in list)
{
minprice = list[i].product_minprice;
selfprice = list[i].product_selfprice;
break;
}
if (selfprice > 0) data = data + 'Закупка | ';
if ((minprice > 0) && (list[i].product_minprice < list[i].product_normprice)) data = data + 'Цена поставщика | ';
data = data + 'Цена | Доступно |
';
for (i in list)
{
if (list[i].product_id > 0)
data = data + BuildTableLineProduct(list[i]);
if (list[i].model_id > 0)
data = data + BuildTableLineModel(list[i]);
}
data = data + '
';
return data;
}
function UpdateMulti()
{
RedrawMulti();
var addr = "https://motoshtuki.ru/data/products.php?action=load_new";
var news = ajaxsmart(addr);
addr = "https://motoshtuki.ru/data/products.php?action=load_popular";
var popular = ajaxsmart(addr);
//multi = news;
var result;
var img;
if (typeof news !== "undefined") {
img = news.product_image;
if (typeof img === "undefined")
img = "";
if (img != "") img = img + "_s.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
result = "";
result = result + "
Новое";
result = result + "

";
result = result + "
" + news.product_name + "
";
if (news.product_normprice > 0)
result = result + '' + news.product_normprice + ' руб.';
result = result + "
";
result = result + "
";
}
if (typeof popular !== "undefined") {
img = popular.product_image;
if (typeof img == "undefined") img = "";
if (img != "") img = img + "_s.jpg";
if (img == "") img = "https://motoshtuki.ru/img/notfound.png";
result = result + "";
result = result + "
Популярное";
result = result + "

";
result = result + "
" + popular.product_name + "
"
if (popular.product_normprice > 0)
result = result + '' + popular.product_normprice + ' руб.';
result = result + "
";
result = result + "
";
}
multi = result;
}
function RedrawMulti()
{
var height = $('.central').height();
//alert(height);
if (height > 900) {
$('.multi_panel').html(multi);
} else {
$('.multi_panel').html("");
}
}