Task:6631 | Правка исчезновения цены на странице магазина

dev_10_refactoring
parent d35f71c601
commit 732e44a8f9
  1. 10
      wp-content/themes/cosmopet/modules/footer/assets/js/footer.js
  2. 66
      wp-content/themes/cosmopet/modules/layout/assets/js/gp-main.js
  3. 2
      wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig
  4. 44
      wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js

@ -219,13 +219,13 @@
});
})
$('body').on('click', '.product-item-overlay__field .counter__button', function(){
var input = $(this).closest('.counter').find('.counter__input').val()
var price = $(this).closest('.product-item__form').find('.product-item-overlay__price')
// $('body').on('click', '.product-item-overlay__field .counter__button', function(){
// var input = $(this).closest('.counter').find('.counter__input').val()
// var price = $(this).closest('.product-item__form').find('.product-item-overlay__price')
$(price).html(Number(input) * $(price).data('basecost'))
})
// $(price).html(Number(input) * $(price).data('basecost'))
// })
$('body').on('click', '.modal-basket__item-before', function(){
var key = $(this).data('id')

@ -11,40 +11,40 @@ jQuery(document).ready(function ($) {
})
// END OVERLAY
$('.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();
product.find('.product-item-overlay__price').html(price * qty + ' ');
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 + '" data-quantity="' + qty +'" 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', '.counter__button', function(evt) {
evt.preventDefault();
let product = $(this).closest('.product__item');
let price = parseFloat(product.find('.select__state').data('product_price'));
// $('.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();
// product.find('.product-item-overlay__price').html(price * qty + ' ');
// 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 + '" data-quantity="' + qty +'" 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', '.counter__button', function(evt) {
// evt.preventDefault();
// let product = $(this).closest('.product__item');
// let price = parseFloat(product.find('.select__state').data('product_price'));
if (!price){
price = parseFloat(product.find('.product-item__price p').html());
}
let qty = product.find('.counter__input');
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);
}
}
product.find('.product-item-overlay__button a').attr('data-quantity', qty.val())
product.find('.product-item-overlay__price').html(price * qty.val() + ' ');
})
// if (!price){
// price = parseFloat(product.find('.product-item__price p').html());
// }
// let qty = product.find('.counter__input');
// 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);
// }
// }
// product.find('.product-item-overlay__button a').attr('data-quantity', qty.val())
// product.find('.product-item-overlay__price').html(price * qty.val() + ' ');
// })
$('.product__main').on('click', '.select__state', function(evt) {
evt.preventDefault();

@ -95,7 +95,7 @@
<button class="counter__button minus">
<img src="{{ theme.link }}/woocommerce/assets/img/svg/main/minus.svg" alt="">
</button>
<input type="text" class="counter__input" value="1">
<input type="text" class="counter__input" value="1">
<button class="counter__button plus">
<img src="{{ theme.link }}/woocommerce/assets/img/svg/main/plus.svg" alt="">
</button>

@ -25,27 +25,33 @@ jQuery(document).ready(function ($) {
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', '.counter__button', function(evt) {
evt.preventDefault();
let product = $(this).closest('.product__item');
let price = parseFloat(product.find('.select__state').data('product_price'));
if (!price || isNaN(price)) {
let priceText = product.find('.product-item__price p').text();
price = parseFloat(priceText.replace(/[^0-9\.,]/g, '').replace(',', '.'));
}
let qty = product.find('.counter__input');
$('.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);
}
}
// Обновляем количество
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);
}
product.find('.product-item-overlay__button a').attr('data-quantity', qty.val())
product.find('.product-item-overlay__price').html((price * qty.val()) + ' ');
})
// Обновляем атрибут 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', '.select__state', function(evt) {
evt.preventDefault();

Loading…
Cancel
Save