123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package relation
- import (
- "github.com/gshopify/service-wrapper/model"
- "github.com/gshopify/service-wrapper/scalar"
- "github.com/mailru/dbr"
- "github.com/microcosm-cc/bluemonday"
- "gshopper.com/gshopify/products/graphql/generated"
- "gshopper.com/gshopify/products/graphql/helper"
- "time"
- )
- type Product struct {
- Id string `db:"id"`
- Title string `db:"title"`
- Description dbr.NullString `db:"description"`
- Handle dbr.NullString `db:"handle"`
- CreatedAt time.Time `db:"created_at"`
- UpdatedAt time.Time `db:"updated_at"`
- PublishedAt *time.Time `db:"published_at"`
- DeletedAt *time.Time `db:"deleted_at"`
- Type dbr.NullString `db:"type"`
- Scope string `db:"scope"`
- Status string `db:"status"`
- Tags []string `db:"tags"`
- TemplateSuffix dbr.NullString `db:"template_suffix"`
- Vendor dbr.NullString `db:"vendor"`
- Gift bool `db:"gift"`
- Collections []string `db:"collections"`
- Images []string `db:"images"`
- Options []struct {
- Field0 string
- Field1 int32
- } `db:"options"`
- InventoryManagement string `db:"inventory_management"`
- InventoryPolicy string `db:"inventory_policy"`
- RequiresShipping bool `db:"requires_shipping"`
- QuantityAvailable int `db:"available"`
- ForSale bool `db:"for_sale"`
- PriceMin float64 `db:"price_min"`
- PriceMax float64 `db:"price_max"`
- CompareAtPriceMin float64 `db:"compare_at_price_min"`
- CompareAtPriceMax float64 `db:"compare_at_price_max"`
- }
- func (p *Product) As() *generated.Product {
- description := bluemonday.StrictPolicy().Sanitize(p.Description.String)
- product := generated.Product{
- AvailableForSale: p.ForSale,
- PriceRange: helper.NewPriceRange(p.PriceMin, p.PriceMax, generated.CurrencyCodeUsd),
- CompareAtPriceRange: helper.NewPriceRange(p.CompareAtPriceMin, p.CompareAtPriceMax, generated.CurrencyCodeUsd),
- RequiresSellingPlan: false,
- FeaturedImage: nil,
- Images: nil,
- Media: nil,
- OnlineStoreURL: nil,
- SellingPlanGroups: nil,
- ID: model.NewId(model.GidProduct, p.Id),
- Handle: p.Handle.String,
- Title: p.Title,
- Vendor: p.Vendor.String,
- Description: description,
- DescriptionHTML: scalar.Html(p.Description.String),
- ProductType: p.Type.String,
- IsGiftCard: p.Gift,
- Tags: p.Tags,
- Seo: &generated.Seo{
- Description: &description,
- Title: &p.Title,
- },
- TotalInventory: &p.QuantityAvailable,
- CreatedAt: scalar.NewDateTimeFrom(p.CreatedAt),
- UpdatedAt: scalar.NewDateTimeFrom(p.UpdatedAt),
- }
- if p.PublishedAt != nil {
- product.PublishedAt = scalar.NewDateTimeFrom(*p.PublishedAt)
- }
- return &product
- }
|