| Line 364... |
Line 364... |
| 364 |
OpenCartValidationResult result = cartValidationService.validateForOpen(cartId, fofoId);
|
364 |
OpenCartValidationResult result = cartValidationService.validateForOpen(cartId, fofoId);
|
| 365 |
if (result == null || result.getCart() == null || result.getCart().getLines() == null) {
|
365 |
if (result == null || result.getCart() == null || result.getCart().getLines() == null) {
|
| 366 |
return result;
|
366 |
return result;
|
| 367 |
}
|
367 |
}
|
| 368 |
HydratedCart cart = result.getCart();
|
368 |
HydratedCart cart = result.getCart();
|
| - |
|
369 |
|
| - |
|
370 |
// 1. Overwrite every line's price from TagListing.sellingPrice — this is
|
| - |
|
371 |
// the same source v1's CartServiceImpl.getCartValidation uses to set
|
| - |
|
372 |
// cart_line.actual_price, i.e. the price the order will actually be
|
| - |
|
373 |
// charged at. The v2 hydrator picks tagListing.mop instead, which
|
| - |
|
374 |
// diverges from sellingPrice on scheme-discounted models (e.g. Moto
|
| - |
|
375 |
// G67 showed ₹22,999 mop vs ₹19,907 sellingPrice). Sync client
|
| - |
|
376 |
// display to server-of-truth so the partner sees what they'll pay.
|
| - |
|
377 |
Set<Integer> lineItemIds = cart.getLines().stream()
|
| - |
|
378 |
.filter(l -> l.getProductId() != ProfitMandiConstants.ITEM_CARRY_BAG)
|
| - |
|
379 |
.map(HydratedLine::getProductId)
|
| - |
|
380 |
.collect(Collectors.toSet());
|
| - |
|
381 |
Map<Integer, Float> sellingByItemId = new java.util.HashMap<>();
|
| - |
|
382 |
if (!lineItemIds.isEmpty()) {
|
| - |
|
383 |
List<TagListing> tls = tagListingRepository.selectByItemIdsAndTagIds(
|
| - |
|
384 |
lineItemIds, new HashSet<>(Arrays.asList(MRP_TAG_ID)));
|
| - |
|
385 |
for (TagListing tl : tls) {
|
| - |
|
386 |
sellingByItemId.putIfAbsent(tl.getItemId(), tl.getSellingPrice());
|
| - |
|
387 |
}
|
| - |
|
388 |
}
|
| - |
|
389 |
boolean overridden = false;
|
| - |
|
390 |
for (HydratedLine line : cart.getLines()) {
|
| - |
|
391 |
if (line.getProductId() == ProfitMandiConstants.ITEM_CARRY_BAG) continue;
|
| - |
|
392 |
if (line.getPrice() == null) continue;
|
| - |
|
393 |
Float livePrice = sellingByItemId.get(line.getProductId());
|
| - |
|
394 |
if (livePrice == null) continue;
|
| - |
|
395 |
BigDecimal newPrice = BigDecimal.valueOf(livePrice)
|
| - |
|
396 |
.setScale(2, RoundingMode.HALF_UP);
|
| - |
|
397 |
if (line.getPrice().getSelling() == null
|
| - |
|
398 |
|| line.getPrice().getSelling().compareTo(newPrice) != 0) {
|
| - |
|
399 |
line.getPrice().setMrp(newPrice);
|
| - |
|
400 |
line.getPrice().setSelling(newPrice);
|
| - |
|
401 |
line.getPrice().setSchemeCashback(BigDecimal.ZERO);
|
| - |
|
402 |
overridden = true;
|
| - |
|
403 |
}
|
| - |
|
404 |
}
|
| - |
|
405 |
|
| - |
|
406 |
// 2. Carry-bag tier logic (₹1 for premium, MOP for Silver/Bronze).
|
| 369 |
BigDecimal tierPrice = BigDecimal.valueOf(resolveCarryBagPrice(fofoId))
|
407 |
BigDecimal tierPrice = BigDecimal.valueOf(resolveCarryBagPrice(fofoId))
|
| 370 |
.setScale(2, RoundingMode.HALF_UP);
|
408 |
.setScale(2, RoundingMode.HALF_UP);
|
| 371 |
boolean overridden = false;
|
- |
|
| 372 |
for (HydratedLine line : cart.getLines()) {
|
409 |
for (HydratedLine line : cart.getLines()) {
|
| 373 |
if (line.getProductId() != ProfitMandiConstants.ITEM_CARRY_BAG) continue;
|
410 |
if (line.getProductId() != ProfitMandiConstants.ITEM_CARRY_BAG) continue;
|
| 374 |
if (line.getPrice() == null) continue;
|
411 |
if (line.getPrice() == null) continue;
|
| 375 |
if (line.getPrice().getSelling() == null
|
412 |
if (line.getPrice().getSelling() == null
|
| 376 |
|| line.getPrice().getSelling().compareTo(tierPrice) != 0) {
|
413 |
|| line.getPrice().getSelling().compareTo(tierPrice) != 0) {
|
| Line 378... |
Line 415... |
| 378 |
line.getPrice().setSelling(tierPrice);
|
415 |
line.getPrice().setSelling(tierPrice);
|
| 379 |
line.getPrice().setSchemeCashback(BigDecimal.ZERO);
|
416 |
line.getPrice().setSchemeCashback(BigDecimal.ZERO);
|
| 380 |
overridden = true;
|
417 |
overridden = true;
|
| 381 |
}
|
418 |
}
|
| 382 |
}
|
419 |
}
|
| - |
|
420 |
|
| 383 |
if (overridden && cart.getPricing() != null) {
|
421 |
if (overridden && cart.getPricing() != null) {
|
| 384 |
// Mirrors CartHydrationServiceImpl.computePricing so grand total
|
422 |
// Mirrors CartHydrationServiceImpl.computePricing so the grand total
|
| 385 |
// reflects the overridden carry-bag price.
|
423 |
// reflects every overridden line price.
|
| 386 |
BigDecimal subtotal = BigDecimal.ZERO;
|
424 |
BigDecimal subtotal = BigDecimal.ZERO;
|
| 387 |
BigDecimal discounts = BigDecimal.ZERO;
|
425 |
BigDecimal discounts = BigDecimal.ZERO;
|
| 388 |
BigDecimal insuranceTotal = BigDecimal.ZERO;
|
426 |
BigDecimal insuranceTotal = BigDecimal.ZERO;
|
| 389 |
for (HydratedLine line : cart.getLines()) {
|
427 |
for (HydratedLine line : cart.getLines()) {
|
| 390 |
if (line.getStatus() != LineStatus.ACTIVE || line.getPrice() == null) continue;
|
428 |
if (line.getStatus() != LineStatus.ACTIVE || line.getPrice() == null) continue;
|