feat: скидки на товары и редактирование промокодов в админке
Цена со скидкой и срок акции на товаре; отображение в каталоге и корзине. Улучшенный UI промокодов с редактированием. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user