9b688b2af4
Цена со скидкой и срок акции на товаре; отображение в каталоге и корзине. Улучшенный UI промокодов с редактированием. Co-authored-by: Cursor <cursoragent@cursor.com>
20 lines
671 B
JavaScript
20 lines
671 B
JavaScript
function isSaleActive(product) {
|
|
if (product.sale_price_cents == null) return false;
|
|
if (product.sale_price_cents >= product.price_cents) return false;
|
|
if (product.sale_ends_at && new Date(product.sale_ends_at) <= new Date()) return false;
|
|
return true;
|
|
}
|
|
|
|
function getEffectivePriceCents(product) {
|
|
return isSaleActive(product) ? product.sale_price_cents : product.price_cents;
|
|
}
|
|
|
|
function salePercent(product) {
|
|
if (!isSaleActive(product) || !product.price_cents) return 0;
|
|
return Math.round(
|
|
((product.price_cents - product.sale_price_cents) / product.price_cents) * 100
|
|
);
|
|
}
|
|
|
|
module.exports = { isSaleActive, getEffectivePriceCents, salePercent };
|