This commit introduces a comprehensive variant management system and enhances the existing ProductVariant model with per-variant weight overrides and stock tracking, integrated across Admin Panel and TeleBot. Features Added: - Variant Collections: Reusable variant templates (e.g., "Standard Sizes") - Admin UI for managing variant collections (CRUD operations) - Dynamic variant editor with JavaScript-based UI - Per-variant weight and weight unit overrides - Per-variant stock level tracking - SalesLedger model for financial tracking ProductVariant Enhancements: - Added Weight (decimal, nullable) field for variant-specific weights - Added WeightUnit (enum, nullable) field for variant-specific units - Maintains backward compatibility with product-level weights TeleBot Integration: - Enhanced variant selection UI to display stock levels - Shows weight information with proper unit conversion (µg, g, oz, lb, ml, L) - Compact button format: "Medium (15 in stock, 350g)" - Real-time stock availability display Database Migrations: - 20250928014850_AddVariantCollectionsAndSalesLedger - 20250928155814_AddWeightToProductVariants Technical Changes: - Updated Product model to support VariantCollectionId and VariantsJson - Extended ProductService with variant collection operations - Enhanced OrderService to handle variant-specific pricing and weights - Updated LittleShop.Client DTOs to match server models - Added JavaScript dynamic variant form builder Files Modified: 15 Files Added: 17 Lines Changed: ~2000 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using LittleShop.Services;
|
|
using LittleShop.DTOs;
|
|
|
|
namespace LittleShop.Areas.Admin.Controllers;
|
|
|
|
[Area("Admin")]
|
|
[Authorize(Policy = "AdminOnly")]
|
|
public class VariantCollectionsController : Controller
|
|
{
|
|
private readonly IVariantCollectionService _variantCollectionService;
|
|
|
|
public VariantCollectionsController(IVariantCollectionService variantCollectionService)
|
|
{
|
|
_variantCollectionService = variantCollectionService;
|
|
}
|
|
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var collections = await _variantCollectionService.GetAllVariantCollectionsAsync();
|
|
return View(collections);
|
|
}
|
|
|
|
public IActionResult Create()
|
|
{
|
|
return View(new CreateVariantCollectionDto());
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Create(CreateVariantCollectionDto model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(model);
|
|
}
|
|
|
|
await _variantCollectionService.CreateVariantCollectionAsync(model);
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
public async Task<IActionResult> Edit(Guid id)
|
|
{
|
|
var collection = await _variantCollectionService.GetVariantCollectionByIdAsync(id);
|
|
if (collection == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var model = new UpdateVariantCollectionDto
|
|
{
|
|
Name = collection.Name,
|
|
PropertiesJson = collection.PropertiesJson,
|
|
IsActive = collection.IsActive
|
|
};
|
|
|
|
ViewData["CollectionId"] = id;
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Edit(Guid id, UpdateVariantCollectionDto model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
ViewData["CollectionId"] = id;
|
|
return View(model);
|
|
}
|
|
|
|
var success = await _variantCollectionService.UpdateVariantCollectionAsync(id, model);
|
|
if (!success)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Delete(Guid id)
|
|
{
|
|
await _variantCollectionService.DeleteVariantCollectionAsync(id);
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
} |