now products have different options, like different parameters
This commit is contained in:
21
src/seed.rs
21
src/seed.rs
@@ -4,7 +4,7 @@ use loco_rs::prelude::*;
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
|
||||
|
||||
use crate::{
|
||||
models::_entities::{categories, products},
|
||||
models::_entities::{categories, product_variants, products},
|
||||
shared::slug::slugify,
|
||||
};
|
||||
|
||||
@@ -157,14 +157,11 @@ pub async fn seed_catalog(ctx: &AppContext) -> Result<()> {
|
||||
|
||||
let now = chrono::Utc::now();
|
||||
|
||||
products::ActiveModel {
|
||||
let product = products::ActiveModel {
|
||||
name: Set(item.name.to_string()),
|
||||
slug: Set(product_slug),
|
||||
description: Set(Some(item.description.to_string())),
|
||||
price_cents: Set(item.price_cents),
|
||||
currency: Set("EUR".to_string()),
|
||||
sku: Set(item.sku.map(|s| s.to_string())),
|
||||
stock: Set(item.stock),
|
||||
published: Set(true),
|
||||
published_at: Set(Some(now.into())),
|
||||
category_id: Set(category.map(|c| c.id)),
|
||||
@@ -172,6 +169,20 @@ pub async fn seed_catalog(ctx: &AppContext) -> Result<()> {
|
||||
}
|
||||
.insert(&ctx.db)
|
||||
.await?;
|
||||
|
||||
// Each seed product ships as a single default (unlabelled) variant
|
||||
// carrying its price/stock/sku.
|
||||
product_variants::ActiveModel {
|
||||
product_id: Set(product.id),
|
||||
label: Set(String::new()),
|
||||
position: Set(0),
|
||||
sku: Set(item.sku.map(|s| s.to_string())),
|
||||
stock: Set(item.stock),
|
||||
price_cents: Set(item.price_cents),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(&ctx.db)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user