From 732e44a8f9512d1c3b1ce1164e95d9f92e71cdce Mon Sep 17 00:00:00 2001 From: maksim Date: Tue, 10 Jun 2025 18:03:05 +0300 Subject: [PATCH] =?UTF-8?q?Task:6631=20|=20=D0=9F=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B8=D1=81=D1=87=D0=B5=D0=B7=D0=BD=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=86=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/footer/assets/js/footer.js | 10 +-- .../modules/layout/assets/js/gp-main.js | 66 +++++++++---------- .../archive-product-tease.twig | 2 +- .../cosmopet/woocommerce/assets/js/gp-main.js | 44 +++++++------ 4 files changed, 64 insertions(+), 58 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js b/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js index d362208..c2fa472 100644 --- a/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js +++ b/wp-content/themes/cosmopet/modules/footer/assets/js/footer.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') diff --git a/wp-content/themes/cosmopet/modules/layout/assets/js/gp-main.js b/wp-content/themes/cosmopet/modules/layout/assets/js/gp-main.js index 85f1651..a7eb44b 100644 --- a/wp-content/themes/cosmopet/modules/layout/assets/js/gp-main.js +++ b/wp-content/themes/cosmopet/modules/layout/assets/js/gp-main.js @@ -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('Добавить в корзину'); - }) - - $('.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('Добавить в корзину'); + // }) + + // $('.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(); diff --git a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig b/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig index 905bc45..8bb76ab 100644 --- a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig +++ b/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig @@ -95,7 +95,7 @@ - + diff --git a/wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js b/wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js index 438dc06..b176193 100644 --- a/wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js +++ b/wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js @@ -25,27 +25,33 @@ jQuery(document).ready(function ($) { product.find('.product-item-overlay__button').prepend('Добавить в корзину'); }) - $('.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();