Need help with a price display on a store repeater

I’m editing my online store with repeaters connected with my products dataset. I have 2 texts elements, one for the original price and other for the discounted Price. I want to only show the original price when the product have a discount

i’ve tried using this code, but it didn’t work.
Note: dataset6 is the product dataset that i am using for a especific type of products and the destquesRepeater is the repeater that i’ve applied the dataset to

$w(“#dataset6”).onReady(() => {
const currentItem = $w(“#dataset6”).getCurrentItem()
const { price, discountedPrice } = currentItem
$w(“#destaquesRepeater”).forEachItem(() => {
if(discountedPrice < price)
$w(“#originalPrice”).show() : $w(“#originalPrice”).hide()
}

})

})

Problem solved!!

here’s the code:

$w.onReady(function () {
 $w('#dataset6').onReady(() => {
        $w('#Repeater').onItemReady(($item, itemData) => {
            let sTitle = itemData.formattedDiscountedPrice;
            if (sTitle === itemData.formattedPrice) {
                $item("#originalPrice").collapse();
            } else {
                $item("#originalPrice").expand();
            }
        })
    })

});

notes:

  • the #dataset is the dataset connected to your repeater
  • In order for this to work, you will have to have 2 texts element, one connected to the formattedDiscountedPrice field and other connected to the formattedPrice field
  • The one that you will have always on display is the text element connected with the formattedDiscountedPrice, and you will want to only display the original price if it is not equal
  • change the id of the text element connected to the formattedPrice to originalPrice and replace the #dataset and #repeater to the id’s of the dataset that you are using and the repeater that you are working on
1 Like