Notice: Undefined offset: 1 in /home/plusensd/steelhammer.com.ua/route.php on line 89
$(function() {
if (window.products_initialized) return; window.products_initialized = true;
$(".products .sort select").change(function() {
var sort = ($(this).val() + " ").split(" ");
location.replace(setUrlParams({ sort: sort[0], sort_dir: sort[1] }));
});
$(".products .page-size select").change(function() {
location.replace(setUrlParams({ count: $(this).val() }));
});
$(".products .manufacturer select").change(function() {
location.replace(setUrlParams({ manufacturer: $(this).val() }));
});
$("#market_discount_subcategory").blur(function(){
post({ market_discount_subcategory: $(this).val(), subcut_id: $("#subcategory_id").val()}, function() {
location.reload();
});
});
$("#crossed_percent").blur(function(){
post("_common", "master-page", { crossed_percent_price: $(this).val() }, function() {
location.reload();
});
});
$("#manufacturer_discount").blur(function(){
post("product", { manufacturer_discount: $(this).val(), manufacturer_id: $("#manufacturer_id").val()}, function() {
location.reload();
});
});
$("#manufacturer_crossed_percent").blur(function(){
post("product", { manufacturer_crossed_percent: $(this).val(), manufacturer_id: $("#manufacturer_id").val()}, function() {
location.reload();
});
});
$("#manufacturer_discount_date_end").blur(function(){
post("product", { manufacturer_discount_date_end: $(this).val(), manufacturer_id: $("#manufacturer_id").val()}, function() {
location.reload();
});
});
var updateChangePrices = function() {
$(".products .new-price").each(function() {
var oldPrice = $(this).parents("[productid]").attr("price");
var newPrice = oldPrice / parseFloat($("[name='change-price-from']").val()) * parseFloat($("[name='change-price-to']").val());
$(this).text(formatPrice(newPrice));
});
}
$(".param.change-price h3").click(function() {
$(this).parent().toggleClass("open");
var isOpen = $(this).parent().hasClass("open");
if (isOpen) {
$(".products .free-delivery").hide();
$(".products .old-price").each(function() {
$(this).text(formatPrice($(this).parents("[productid]").attr("price")));
}).show();
updateChangePrices();
} else {
$(".products .free-delivery").show();
$(".products .old-price").hide();
$(".products .new-price").each(function() {
$(this).text(formatPrice($(this).parents("[productid]").attr("price")));
});
}
});
$("[name='change-price-from'], [name='change-price-to']").each(function() {
this.oldValue = this.value;
}).keydown(function() {
var that = this;
setTimeout(function() {
if (that.value != that.oldValue) {
that.oldValue = that.value;
updateChangePrices();
}
});
});
$(".change-price .button").click(function() {
var productCount = $("[name='product-count']").val();
var from = parseFloat($("[name='change-price-from']").val());
var to = parseFloat($("[name='change-price-to']").val());
if (isNaN(from) || isNaN(to) || from <= 0 || to <= 0) {
alert("Некорректные параметры изменения цены.");
return;
}
if (confirm("Вы хотите обновить цену для " + productCount + " товар" + (productCount % 10 == 1 && productCount != 11 ? "а" : "ов") + "?")) {
location.href = setUrlParams({ changepricefrom: from, changepriceto: to });
}
});
$(".add-product").click(function() {
post({ add: true, subcategory_id: $(this).attr("subcategoryid") }, function(response) {
var productId = Number(response);
if (productId) {
location.href = "/products/product/" + productId;
}
});
});
$(".header").on("dropbox", function() {
var $this = $(this);
var imageData = $this.data("dropbox")[0];
var backgroundImage = $this.css("background-image");
$this.css("background-image", "url('" + imageData + "')");
setTimeout(function() {
if (confirm("Сохранить новый логотип?")) {
post("products", "category", { category_id: $this.attr("categoryid"), bg: imageData });
} else {
$this.css("background-image", backgroundImage);
}
}, 100);
}).dblclick(function() {
if (confirm("Удалить картинку для категории " + $("h1").text() + "?")) {
post("products", "category", { remove_bg_id: $(".header").attr("categoryid") }, function() {
location.reload();
});
}
});
$(".products").on("sortstop", function(e, ui) {
post({ reorder_product_id: ui.item.attr("productid"), after_product_id: ui.item.prev().attr("productid") });
});
});