diff --git a/app/services/vendor_product_service.py b/app/services/vendor_product_service.py index 772db8b6..4d5a88ef 100644 --- a/app/services/vendor_product_service.py +++ b/app/services/vendor_product_service.py @@ -198,6 +198,9 @@ class VendorProductService: "vendor_code": product.vendor.vendor_code if product.vendor else None, "marketplace_product_id": product.marketplace_product_id, "vendor_sku": product.vendor_sku, + # Product identifiers + "gtin": product.gtin, + "gtin_type": product.gtin_type or "ean13", # Product fields with source comparison info **source_comparison_info, # Vendor-specific fields @@ -275,29 +278,67 @@ class VendorProductService: Args: db: Database session product_id: Product ID to update - data: Fields to update + data: Fields to update (may include translations dict) Returns: Updated Product instance """ - product = db.query(Product).filter(Product.id == product_id).first() + from models.database.product_translation import ProductTranslation + + product = ( + db.query(Product) + .options(joinedload(Product.translations)) + .filter(Product.id == product_id) + .first() + ) if not product: raise ProductNotFoundException(product_id) - # Update allowed fields + # Handle translations separately + if "translations" in data and data["translations"]: + existing_translations = {t.language: t for t in product.translations} + + for lang, trans_data in data["translations"].items(): + if lang in existing_translations: + # Update existing translation + if "title" in trans_data: + existing_translations[lang].title = trans_data["title"] + if "description" in trans_data: + existing_translations[lang].description = trans_data["description"] + else: + # Create new translation + new_trans = ProductTranslation( + product_id=product_id, + language=lang, + title=trans_data.get("title"), + description=trans_data.get("description"), + ) + db.add(new_trans) + + # Handle price (convert to cents) + if "price" in data and data["price"] is not None: + product.price = data["price"] # Uses property setter to convert to cents + + if "sale_price" in data: + product.sale_price = data["sale_price"] # Uses property setter + + if "cost" in data: + product.cost = data["cost"] # Uses property setter + + # Update other allowed fields + # Note: is_digital is derived from marketplace_product, not directly updatable updatable_fields = [ "vendor_sku", "brand", "gtin", - "price_override", - "currency_override", - "availability", + "gtin_type", + "currency", + "tax_rate_percent", "is_active", "is_featured", - "is_digital", - "description", - "title", + "primary_image_url", + "supplier", ] for field in updatable_fields: diff --git a/app/templates/admin/vendor-product-edit.html b/app/templates/admin/vendor-product-edit.html index 213eee1a..577c5105 100644 --- a/app/templates/admin/vendor-product-edit.html +++ b/app/templates/admin/vendor-product-edit.html @@ -8,7 +8,7 @@ {% block alpine_data %}adminVendorProductEdit(){% endblock %} {% block content %} -{% call detail_page_header("'Edit: ' + (product?.title || 'Product')", '/admin/vendor-products', subtitle_show='product') %} +{% call detail_page_header("'Edit: ' + (product?.vendor_translations?.en?.title || 'Product')", '/admin/vendor-products', subtitle_show='product') %} {% endcall %} @@ -17,50 +17,127 @@ {{ error_state('Error loading product') }} -