shop product refactoring
This commit is contained in:
@@ -187,15 +187,15 @@ class CSVProcessor:
|
||||
return processed_data
|
||||
|
||||
async def process_marketplace_csv_from_url(
|
||||
self, url: str, marketplace: str, shop_name: str, batch_size: int, db: Session
|
||||
self, url: str, marketplace: str, vendor_name: str, batch_size: int, db: Session
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Process CSV from URL with marketplace and shop information.
|
||||
Process CSV from URL with marketplace and vendor information.
|
||||
|
||||
Args:
|
||||
url: URL to the CSV file
|
||||
marketplace: Name of the marketplace (e.g., 'Letzshop', 'Amazon')
|
||||
shop_name: Name of the shop
|
||||
vendor_name: Name of the vendor
|
||||
batch_size: Number of rows to process in each batch
|
||||
db: Database session
|
||||
|
||||
@@ -203,7 +203,7 @@ class CSVProcessor:
|
||||
Dictionary with processing results
|
||||
"""
|
||||
logger.info(
|
||||
f"Starting marketplace CSV import from {url} for {marketplace} -> {shop_name}"
|
||||
f"Starting marketplace CSV import from {url} for {marketplace} -> {vendor_name}"
|
||||
)
|
||||
# Download and parse CSV
|
||||
csv_content = self.download_csv(url)
|
||||
@@ -220,7 +220,7 @@ class CSVProcessor:
|
||||
for i in range(0, len(df), batch_size):
|
||||
batch_df = df.iloc[i : i + batch_size]
|
||||
batch_result = await self._process_marketplace_batch(
|
||||
batch_df, marketplace, shop_name, db, i // batch_size + 1
|
||||
batch_df, marketplace, vendor_name, db, i // batch_size + 1
|
||||
)
|
||||
|
||||
imported += batch_result["imported"]
|
||||
@@ -235,14 +235,14 @@ class CSVProcessor:
|
||||
"updated": updated,
|
||||
"errors": errors,
|
||||
"marketplace": marketplace,
|
||||
"shop_name": shop_name,
|
||||
"vendor_name": vendor_name,
|
||||
}
|
||||
|
||||
async def _process_marketplace_batch(
|
||||
self,
|
||||
batch_df: pd.DataFrame,
|
||||
marketplace: str,
|
||||
shop_name: str,
|
||||
vendor_name: str,
|
||||
db: Session,
|
||||
batch_num: int,
|
||||
) -> Dict[str, int]:
|
||||
@@ -253,7 +253,7 @@ class CSVProcessor:
|
||||
|
||||
logger.info(
|
||||
f"Processing batch {batch_num} with {len(batch_df)} rows for "
|
||||
f"{marketplace} -> {shop_name}"
|
||||
f"{marketplace} -> {vendor_name}"
|
||||
)
|
||||
|
||||
for index, row in batch_df.iterrows():
|
||||
@@ -261,9 +261,9 @@ class CSVProcessor:
|
||||
# Convert row to dictionary and clean up
|
||||
product_data = self._clean_row_data(row.to_dict())
|
||||
|
||||
# Add marketplace and shop information
|
||||
# Add marketplace and vendor information
|
||||
product_data["marketplace"] = marketplace
|
||||
product_data["shop_name"] = shop_name
|
||||
product_data["vendor_name"] = vendor_name
|
||||
|
||||
# Validate required fields
|
||||
if not product_data.get("marketplace_product_id"):
|
||||
@@ -294,7 +294,7 @@ class CSVProcessor:
|
||||
updated += 1
|
||||
logger.debug(
|
||||
f"Updated product {product_data['marketplace_product_id']} for "
|
||||
f"{marketplace} and shop {shop_name}"
|
||||
f"{marketplace} and vendor {vendor_name}"
|
||||
)
|
||||
else:
|
||||
# Create new product
|
||||
@@ -309,7 +309,7 @@ class CSVProcessor:
|
||||
imported += 1
|
||||
logger.debug(
|
||||
f"Imported new product {product_data['marketplace_product_id']} "
|
||||
f"for {marketplace} and shop {shop_name}"
|
||||
f"for {marketplace} and vendor {vendor_name}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user