You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
cosmopet-architecture/wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js

138 lines
5.5 KiB

'use strict';
jQuery(document).ready(function ($) {
// OVERLAY
$('.product__main').on('click', '.open-overlay', function () {
let product = $(this).closest('.product__item'),
overlay = product.find('.product-item__overlay');
$('.product__item').find('.product-item__overlay').css('top', '100%');
overlay.css('top', 0);
})
// END OVERLAY
$('.product__main').on('click', '.counter__button', function(evt) {
evt.preventDefault();
let product = $(this).closest('.product__item');
let priceElement = product.find('.select__state');
let price = parseFloat(priceElement.data('product_price'));
let qty = product.find('.counter__input');
// Если цена не найдена, пытаемся взять её из .product-item__price
if (!price || isNaN(price)) {
let priceText = product.find('.product-item__price p').text();
price = parseFloat(priceText.replace(/[^0-9\.,]/g, '').replace(',', '.'));
}
// Обновляем количество
if ($(this).hasClass('minus') && parseInt(qty.val()) >= 2) {
qty.val(parseInt(qty.val()) - 1);
} else if ($(this).hasClass('plus')) {
qty.val(parseInt(qty.val()) + 1);
}
// Обновляем атрибут data-quantity для кнопки "Добавить в корзину"
product.find('.product-item-overlay__button a').attr('data-quantity', qty.val());
// Обновляем цену без символа валюты (он добавляется через ::after)
console.log(price * qty.val())
product.find('.product-item-overlay__price').html((price * qty.val()));
});
$('.product__main').on('click', '.state__button', function(evt) {
evt.preventDefault();
let product = $(this).closest('.product__item');
let price = $(this).data('product_price');
let id = $(this).data('product_id');
let qty = product.find('.counter__input').val();
console.log('qty', price * qty)
window.t = product.find('.product-item-overlay__price')
console.log(t)
var new_price = price * Number(qty)
product.find('.product-item-overlay__price').html(new_price + ' ');
product.find('.select__state').data('product_price', price).data('product_id', id).val($(this).text().trim());
product.find('.state__block').removeClass('expanded').css('height', '0');
product.find('.add_to_cart_button').detach();
product.find('.product-item-overlay__button').prepend('<a href="?add-to-cart=' + id + '" class="ajax_add_to_cart add_to_cart_button button button--gradient button--base button--100-perc" data-product_id="'+id+'">Добавить в корзину</a>');
})
$('.product__main').on('click', '.select__state', function(evt) {
evt.preventDefault();
let product = $(this).closest('.product__item'),
listing = product.find('.state__block');
if (listing.hasClass('expanded')) {
listing.removeClass('expanded').css('height', '0');
} else {
listing.addClass('expanded').css('height', 'auto');
}
product.find('.state__block').find('.state__button').removeClass('active');
product.find('.state__button').each(function () {
if (product.find('.select__state').data('product_id') === $(this).data('product_id')) {
$(this).addClass('active');
}
})
})
let page = 1;
jQuery('body').on('click', '#load-more-products', function(e) {
e.preventDefault();
page++;
let category = $(this).data('category_id');
let category_type = $(this).data('category_type');
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
dataType: 'html',
data: {
'action' : 'get_products',
'get_page' : page,
'get_category' : category,
'get_category_type' : category_type,
},
success: function(data) {
// if($('<div></div>').html(data).find('.archive__item.ended').size() > 0) $('#load-more-products').parents('.cta').remove();
// else $('#load-more-products').parents('.cta').show();
$('#load-more-products').detach();
$('.product__main').append(data);
$('#load-more-products').prependTo('.product__footer');
},
error: function(data) {
console.log(data);
}
});
});
$('.wpfMainWrapper').prepend('<div class="wpfFilters"></div>');
$('.wpfMainWrapper').find('.wpfFilterWrapper').appendTo($('.wpfFilters'));
$('.wpfFilterWrapper').each(function () {
if ($(this).data('filter-type') === 'wpfPrice') {
$(this).find('.wpfFilterContent').append('<div class="wpfExpandablePart"></div>');
$(this).find('.wpfPriceFilterRange').appendTo('.wpfExpandablePart');
$(this).find('.wpfPriceInputs').appendTo('.wpfExpandablePart');
$(this).find('.wpfCurrencySymbol').detach();
$(this).find('.wpfFilterDelimeter').detach();
}
});
$('.wfpDescription').on('click', function () {
$(this).closest('.wpfFilterWrapper').toggleClass('expanded').find('.wpfCheckboxHier').slideToggle();
$(this).parent().find('.wpfExpandablePart').slideToggle();
})
})