Jump to content

Problem with displaying 2 prices Solved


mkkorleone

Recommended Posts

Hello, we are required to display 2 prices in euros and leva.
For amounts over 1000 leva it shows me 1 leva.

Prestashop 1.6

At the end of global.js I have put this code.

const rate = 1.92583;

function convertBGNtoEUR(selector) {
$(selector).each(function () {
let text = $(this).text().trim();
let bgn = parseFloat(text.replace(',', '.'));
if (isNaN(bgn)) return;
if ($(this).html().includes('€')) return;

let eur = (bgn / rate).toFixed(2);
let bgnFormatted = bgn.toFixed(2).replace('.', ',');

$(this).html(bgnFormatted + ' лв / <span class="eur">€' + eur + '</span>');
});
}
$(document).ready(function () {

convertBGNtoEUR('.content_price .product-price, .content_price .old-price');
convertBGNtoEUR('#our_price_display, #unit_price_display');

const observer = new MutationObserver(function () {
convertBGNtoEUR('.content_price .product-price, .content_price .old-price');
convertBGNtoEUR('#our_price_display, #unit_price_display');
});

observer.observe(document.body, {
childList: true,
subtree: true
});
});

 

https://beautyandpower.eu/244-masazhni-stolove

 

Thanks in advance.

Edited by mkkorleone (see edit history)
Link to comment
Share on other sites

On 8/2/2025 at 11:06 AM, mkkorleone said:

Hello, we are required to display 2 prices in euros and leva.
For amounts over 1000 leva it shows me 1 leva.

Prestashop 1.6

At the end of global.js I have put this code.

const rate = 1.92583;

function convertBGNtoEUR(selector) {
$(selector).each(function () {
let text = $(this).text().trim();
let bgn = parseFloat(text.replace(',', '.'));
if (isNaN(bgn)) return;
if ($(this).html().includes('€')) return;

let eur = (bgn / rate).toFixed(2);
let bgnFormatted = bgn.toFixed(2).replace('.', ',');

$(this).html(bgnFormatted + ' лв / <span class="eur">€' + eur + '</span>');
});
}
$(document).ready(function () {

convertBGNtoEUR('.content_price .product-price, .content_price .old-price');
convertBGNtoEUR('#our_price_display, #unit_price_display');

const observer = new MutationObserver(function () {
convertBGNtoEUR('.content_price .product-price, .content_price .old-price');
convertBGNtoEUR('#our_price_display, #unit_price_display');
});

observer.observe(document.body, {
childList: true,
subtree: true
});
});

 

https://beautyandpower.eu/244-masazhni-stolove

 

Thanks in advance.

 

I found the correct code.

const rate = 1.95583;

function convertBGNtoEUR(selector) {

$(selector).each(function () {

let html = $(this).html();

if (!html.includes('лв')) return; // Само елементи със стойности в лева

if (html.includes('€')) return; // Вече конвертирано

let text = $(this).text().trim();

let bgn = parseFloat(text.replace(',', '.').replace(/[^\d.]/g, ''));

if (isNaN(bgn)) return;

let eur = (bgn / rate).toFixed(2);

let bgnFormatted = bgn.toFixed(2).replace('.', ',');

$(this).html(bgnFormatted + ' лв / <span class="eur">€' + eur + '</span>');

});

}

$(document).ready(function () {

const allSelectors = [

// Продуктови цени

'.content_price .product-price',

'#our_price_display',

'#unit_price_display',

'.price',

'.product-price-and-shipping',

'.product-miniature .price',

'.product-miniature .regular-price',

'.product-miniature .price-wrapper',

'.custom_price',

'.price-tag',

'.product-price',

'.current-price-value',

// Количка и checkout

'.cart_total .price',

'.cart_item .price',

'.checkout-summary .value',

'.product-line-info .price',

'.cart-summary .delivery-value',

'.cart-summary .total-value',

'.cart-summary .value',

'.delivery .value',

'.shipping .value',

'#cart_summary .price',

'#cart_total',

'#cart_total_price',

'#total_price',

'.subtotal.value',

'.value',

'td',

'.col-xs-4.text-sm-center.text-xs-right.bold',

// Доставка

'.delivery-option .carrier-price',

'#delivery_method .carrier-price',

'.delivery_option_price',

'.ajax_cart_shipping_cost',

// Pop-up слоеве и ajax количка

'.layer_cart_row .price',

'.layer_cart_product_price',

'#layer_cart_product_price',

'.ajax_cart_total',

'.ajax_cart_shipping',

'.ajax_cart_summary',

'.layer_cart_price',

'.ajax_block_products_total',

'.ajax_block_cart_total',

// Хедър количка

'.blockcart .price',

'#ajax_block_cart_total',

'#blockcart_total_price',

'#cart_total_ajax',

'.cart-summary-amount'

];

convertBGNtoEUR(allSelectors.join(', '));

const observer = new MutationObserver(function () {

convertBGNtoEUR(allSelectors.join(', '));

});

observer.observe(document.body, {

childList: true,

subtree: true

});

});

Link to comment
Share on other sites

  • mkkorleone changed the title to Problem with displaying 2 prices Solved

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...