Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Datart - coupon discounts #2544

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions actors/datart-daily/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,45 @@ function extractItems(document, rootUrl, country) {
const searchParams = new URLSearchParams(itemCartDataTarget);
result.itemId = searchParams.get("id");
}
result.currentPrice = parseFloat(
const currentPrice = parseFloat(
productBoxBuyInfoCart
.querySelector("div.item-price div.actual")
.innerText.trim()
.replace(/[^\d,]+/g, "")
.replace(",", ".")
);
const cutPrice = productBoxBuyInfoCart.querySelector("div.item-price span.cut-price del");
if (cutPrice) {
result.originalPrice = parseFloat(
cutPrice.innerText

let lowestPriceInLastMonth = currentPrice;
const lowestPriceInLastMonthEl = productBoxBuyInfoCart.querySelector("div.item-price span.cut-price del");
if (lowestPriceInLastMonthEl) {
lowestPriceInLastMonth = parseFloat(
lowestPriceInLastMonthEl.innerText
.trim()
.replace(/[^\d,]+/g, "")
.replace(",", ".")
);
}
let couponDiscount = 0;
const couponDiscountFlagEl = productEl.querySelector(".product-flags .flag-color-red");
if (couponDiscountFlagEl) {
const hasDiscountKeyword = country === Country.CZ && /extra sleva/i.test(couponDiscountFlagEl.textContent);
if (hasDiscountKeyword) {
couponDiscount = parseFloat(couponDiscountFlagEl.innerText.trim()
.replace(/[^\d,]+/g, "")
.replace(",", ".")
);
}
}

result.originalPrice = lowestPriceInLastMonth;
result.currentPrice = currentPrice;

if (couponDiscount > 0) {
result.currentPrice -= couponDiscount;
result.discounted = true;
} else {
result.originalPrice = null;
result.discounted = false;
result.currentPrice = currentPrice;
result.discounted = lowestPriceInLastMonth > currentPrice;
}

return result;
Expand Down