mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
32 lines
567 B
Go
32 lines
567 B
Go
package lineitem
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/hanzoai/commerce/models/product"
|
|
"github.com/hanzoai/commerce/models/variant"
|
|
)
|
|
|
|
func Fake(item interface{}) LineItem {
|
|
var li LineItem
|
|
|
|
switch v := item.(type) {
|
|
case *product.Product:
|
|
li.ProductId = v.Id()
|
|
li.ProductName = v.Name
|
|
li.ProductSlug = v.Slug
|
|
li.Price = v.Price
|
|
case *variant.Variant:
|
|
li.VariantId = v.Id()
|
|
li.VariantName = v.Name
|
|
li.VariantSKU = v.SKU
|
|
li.Price = v.Price
|
|
default:
|
|
panic("Unsupported item")
|
|
}
|
|
|
|
li.Quantity = rand.Intn(5) + 1
|
|
li.Taxable = false
|
|
return li
|
|
}
|