Fetch product data from market service in cart's add_to_cart route
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m54s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m54s
The global add_to_cart route was calling find_or_create_cart_item without
denormalized product data, leaving NULL columns. Now fetches product info
via fetch_data("market", "products-by-ids") before creating the cart item.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -37,13 +37,28 @@ def register(url_prefix: str) -> Blueprint:
|
|||||||
|
|
||||||
@bp.post("/add/<int:product_id>/")
|
@bp.post("/add/<int:product_id>/")
|
||||||
async def add_to_cart(product_id: int):
|
async def add_to_cart(product_id: int):
|
||||||
|
from shared.infrastructure.data_client import fetch_data
|
||||||
|
|
||||||
ident = current_cart_identity()
|
ident = current_cart_identity()
|
||||||
|
|
||||||
|
# Fetch product data from market service (cart DB doesn't have products)
|
||||||
|
products_raw = await fetch_data(
|
||||||
|
"market", "products-by-ids",
|
||||||
|
params={"ids": str(product_id)},
|
||||||
|
required=False,
|
||||||
|
) or []
|
||||||
|
product_data = products_raw[0] if products_raw else None
|
||||||
|
|
||||||
cart_item = await find_or_create_cart_item(
|
cart_item = await find_or_create_cart_item(
|
||||||
g.s,
|
g.s,
|
||||||
product_id,
|
product_id,
|
||||||
ident["user_id"],
|
ident["user_id"],
|
||||||
ident["session_id"],
|
ident["session_id"],
|
||||||
|
product_title=product_data["title"] if product_data else None,
|
||||||
|
product_slug=product_data["slug"] if product_data else None,
|
||||||
|
product_image=product_data["image"] if product_data else None,
|
||||||
|
product_regular_price=product_data["regular_price"] if product_data else None,
|
||||||
|
product_special_price=product_data["special_price"] if product_data else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not cart_item:
|
if not cart_item:
|
||||||
|
|||||||
Reference in New Issue
Block a user