Feature: Implement context-aware pricing for product types
Updates pricing logic to use correct price based on product type:
- Updated getEffectivePrice to accept priceType parameter ('base', 'plain', 'personalised')
- Updated toProductDTO to accept and use priceType when computing effective price
- Updated made-to-order pages to use 'personalised' price type
- Updated products catalog pages to use 'plain' price type
- Updated checkout logic to determine price type based on design
Pricing behavior:
- Personalised orders (with design): use personalisedPrice if set, else basePrice
- Plain/blank orders (no design): use plainPrice if set, else basePrice
- Ready-made orders (no design, no plainPrice): use basePrice
All prices now correctly reflect the product variant being purchased.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
e5fb22aab1
commit
5bd6f3de39
@@ -110,9 +110,19 @@ export async function POST(req: Request) {
|
||||
const pricedItems = items.map((i) => {
|
||||
const design = typeof i.designJson === 'string' ? JSON.parse(i.designJson) : i.designJson;
|
||||
const isPersonalised = (design.front?.length ?? 0) > 0 || (design.back?.length ?? 0) > 0;
|
||||
const product = productsById.get(i.productId)!;
|
||||
|
||||
// Determine which price to use
|
||||
let priceType: 'base' | 'plain' | 'personalised' = 'base';
|
||||
if (isPersonalised) {
|
||||
priceType = 'personalised';
|
||||
} else if (product.plainPrice != null) {
|
||||
priceType = 'plain';
|
||||
}
|
||||
|
||||
return {
|
||||
...i,
|
||||
unitPrice: getEffectivePrice(productsById.get(i.productId)!, activePromotions, new Date(), isPersonalised).price,
|
||||
unitPrice: getEffectivePrice(product, activePromotions, new Date(), priceType).price,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user