Muneesh commited on
Commit
e5c56ea
·
1 Parent(s): ac148ce

fix(bigbasket): more defensive pricing parsing

Browse files
Files changed (1) hide show
  1. providers/bigbasket.py +13 -7
providers/bigbasket.py CHANGED
@@ -67,15 +67,21 @@ class BigBasketProvider(BaseProvider):
67
  continue
68
 
69
  # Pricing: pricing.discount.mrp (string), pricing.discount.prim_price.sp (string)
70
- pricing = item.get("pricing", {})
71
- discount_info = pricing.get("discount", {})
72
- mrp_str = str(discount_info.get("mrp", "0"))
73
- prim_price = discount_info.get("prim_price", {})
74
- sp_str = str(prim_price.get("sp", mrp_str))
 
 
 
 
 
 
75
 
76
  try:
77
- price = float(sp_str.replace(",", ""))
78
- mrp = float(mrp_str.replace(",", ""))
79
  except (ValueError, TypeError):
80
  continue
81
  if price <= 0:
 
67
  continue
68
 
69
  # Pricing: pricing.discount.mrp (string), pricing.discount.prim_price.sp (string)
70
+ pricing = item.get("pricing") or {}
71
+ discount_info = pricing.get("discount") or {}
72
+ mrp_raw = discount_info.get("mrp", "0")
73
+ prim_price = discount_info.get("prim_price") or {}
74
+ sp_raw = prim_price.get("sp") or mrp_raw
75
+
76
+ # Also try top-level pricing keys as fallback
77
+ if not sp_raw or str(sp_raw) == "0":
78
+ sp_raw = pricing.get("sp") or pricing.get("price") or pricing.get("selling_price") or "0"
79
+ if not mrp_raw or str(mrp_raw) == "0":
80
+ mrp_raw = pricing.get("mrp") or pricing.get("mrp_price") or sp_raw
81
 
82
  try:
83
+ price = float(str(sp_raw).replace(",", "").strip())
84
+ mrp = float(str(mrp_raw).replace(",", "").strip())
85
  except (ValueError, TypeError):
86
  continue
87
  if price <= 0: