|
@@ -0,0 +1,101 @@
|
|
|
|
+package relation
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "github.com/gshopify/service-wrapper/model"
|
|
|
|
+ "github.com/gshopify/service-wrapper/scalar"
|
|
|
|
+ "github.com/mailru/dbr"
|
|
|
|
+ "gshopper.com/gshopify/products/graphql/generated"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type ProductVariant struct {
|
|
|
|
+ Id string `db:"id"`
|
|
|
|
+ ProductId string `db:"product_id"`
|
|
|
|
+ Title string `db:"title"`
|
|
|
|
+ Options []struct {
|
|
|
|
+ Field0 string
|
|
|
|
+ Field1 int32
|
|
|
|
+ } `db:"options"`
|
|
|
|
+ Price float64 `db:"price"`
|
|
|
|
+ UnitPrice float64 `db:"unit_price"`
|
|
|
|
+ CompareAtPrice float64 `db:"compare_at_price"`
|
|
|
|
+ Barcode dbr.NullString `db:"barcode"`
|
|
|
|
+ Sku dbr.NullString `db:"sku"`
|
|
|
|
+ HarmonizedSystemCode dbr.NullString `db:"hs_code"`
|
|
|
|
+ AllowBackorder bool `db:"allow_backorder"`
|
|
|
|
+ ManageInventory bool `db:"manage_inventory"`
|
|
|
|
+ OriginCountry dbr.NullString `db:"origin_country"`
|
|
|
|
+ UnitPriceMeasurement struct {
|
|
|
|
+ Field0 string
|
|
|
|
+ Field1 string
|
|
|
|
+ Field2 float64
|
|
|
|
+ Field3 string
|
|
|
|
+ Field4 int32
|
|
|
|
+ } `db:"unit_price_measurement"`
|
|
|
|
+ Weight dbr.NullFloat64 `db:"weight"`
|
|
|
|
+ WeightUnit string `db:"wight_unit"`
|
|
|
|
+ CreatedAt time.Time `db:"created_at"`
|
|
|
|
+ UpdatedAt time.Time `db:"updated_at"`
|
|
|
|
+ DeletedAt *time.Time `db:"deleted_at"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (v *ProductVariant) As() *generated.ProductVariant {
|
|
|
|
+ variant := &generated.ProductVariant{
|
|
|
|
+ AvailableForSale: false,
|
|
|
|
+ CurrentlyNotInStock: false,
|
|
|
|
+ RequiresShipping: false,
|
|
|
|
+ QuantityAvailable: nil,
|
|
|
|
+
|
|
|
|
+ ID: model.NewId(model.GidVariant, v.Id),
|
|
|
|
+ Title: v.Title,
|
|
|
|
+
|
|
|
|
+ Price: &generated.MoneyV2{
|
|
|
|
+ Amount: scalar.NewDecimal(v.Price),
|
|
|
|
+ CurrencyCode: generated.CurrencyCodeUsd,
|
|
|
|
+ },
|
|
|
|
+ CompareAtPrice: &generated.MoneyV2{
|
|
|
|
+ Amount: scalar.NewDecimal(v.CompareAtPrice),
|
|
|
|
+ CurrencyCode: generated.CurrencyCodeUsd,
|
|
|
|
+ },
|
|
|
|
+ UnitPrice: &generated.MoneyV2{
|
|
|
|
+ Amount: scalar.NewDecimal(v.UnitPrice),
|
|
|
|
+ CurrencyCode: generated.CurrencyCodeUsd,
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ Product: &generated.Product{ID: model.NewId(model.GidProduct, v.ProductId)},
|
|
|
|
+ Image: nil,
|
|
|
|
+ SelectedOptions: nil,
|
|
|
|
+
|
|
|
|
+ UnitPriceMeasurement: &generated.UnitPriceMeasurement{
|
|
|
|
+ QuantityValue: v.UnitPriceMeasurement.Field2,
|
|
|
|
+ ReferenceValue: int(v.UnitPriceMeasurement.Field4),
|
|
|
|
+ },
|
|
|
|
+ WeightUnit: generated.WeightUnit(v.WeightUnit),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if enum := generated.UnitPriceMeasurementMeasuredType(v.UnitPriceMeasurement.Field0); enum.IsValid() {
|
|
|
|
+ variant.UnitPriceMeasurement.MeasuredType = &enum
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if enum := generated.UnitPriceMeasurementMeasuredUnit(v.UnitPriceMeasurement.Field1); enum.IsValid() {
|
|
|
|
+ variant.UnitPriceMeasurement.QuantityUnit = &enum
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if enum := generated.UnitPriceMeasurementMeasuredUnit(v.UnitPriceMeasurement.Field3); enum.IsValid() {
|
|
|
|
+ variant.UnitPriceMeasurement.ReferenceUnit = &enum
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if v.Weight.Valid {
|
|
|
|
+ variant.Weight = &v.Weight.Float64
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if v.Sku.Valid {
|
|
|
|
+ variant.Sku = &v.Sku.String
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if v.Barcode.Valid {
|
|
|
|
+ variant.Barcode = &v.Barcode.String
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return variant
|
|
|
|
+}
|