|
@@ -1,8 +1,10 @@
|
|
|
package db
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"github.com/gshopify/service-wrapper/model"
|
|
|
"gshopper.com/gshopify/products/cache"
|
|
|
+ "gshopper.com/gshopify/products/graphql/generated"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -15,14 +17,26 @@ var (
|
|
|
time.Minute,
|
|
|
clause, args...)
|
|
|
}
|
|
|
- productSelection = func(ln model.LanguageCode) []string {
|
|
|
+ productSelection = func(ln model.LanguageCode, currency generated.CurrencyCode) []string {
|
|
|
return append([]string{
|
|
|
- "id", "handle", "type", "scope", "tags", "vendor",
|
|
|
- "collections", "images", "options",
|
|
|
- "created_at", "updated_at", "published_at", "deleted_at",
|
|
|
+ "t.id as id",
|
|
|
+ "any(handle) as handle", "any(type) as type", "any(scope) as scope", "any(tags) as tags", "any(vendor) as vendor",
|
|
|
+ "any(gift) as gift", "any(collections) as collections", "any(images) as images",
|
|
|
+ "any(product_variant.inventory_management) as inventory_management",
|
|
|
+ "any(product_variant.inventory_policy) as inventory_policy",
|
|
|
+ "any(product_variant.options) as options",
|
|
|
+ "any(inventory_item.requires_shipping) as requires_shipping",
|
|
|
+ "any(inventory_item.tracked) as tracked",
|
|
|
+ "any(inventory_level.available) as available",
|
|
|
+ "if(tracked, if(available > 0, true, if(inventory_policy == 'continue', true, false)), true) as for_sale",
|
|
|
+ fmt.Sprintf("min(product_variant.price['%s']) as price_min", currency),
|
|
|
+ fmt.Sprintf("max(product_variant.price['%s']) as price_max", currency),
|
|
|
+ fmt.Sprintf("min(product_variant.compare_at_price['%s']) as compare_at_price_min", currency),
|
|
|
+ fmt.Sprintf("max(product_variant.compare_at_price['%s']) as compare_at_price_max", currency),
|
|
|
+ "any(created_at) as created_at", "any(updated_at) as updated_at", "any(published_at) as published_at", "any(deleted_at) as deleted_at",
|
|
|
},
|
|
|
- ln.SqlFieldSelection("title", ""),
|
|
|
- ln.SqlFieldSelection("description", ""),
|
|
|
+ ln.SqlFieldSelection("title", "", "any"),
|
|
|
+ ln.SqlFieldSelection("description", "", "any"),
|
|
|
)
|
|
|
}
|
|
|
productCollectionSelection = func(ln model.LanguageCode) []string {
|
|
@@ -30,8 +44,8 @@ var (
|
|
|
"id", "handle", "scope", "sort_order", "image", "template_suffix",
|
|
|
"created_at", "updated_at", "published_at", "deleted_at",
|
|
|
},
|
|
|
- ln.SqlFieldSelection("title", ""),
|
|
|
- ln.SqlFieldSelection("description", ""),
|
|
|
+ ln.SqlFieldSelection("title", "", ""),
|
|
|
+ ln.SqlFieldSelection("description", "", ""),
|
|
|
)
|
|
|
}
|
|
|
productCollectionKey = func(clause string, args ...any) *cache.SqlKey {
|
|
@@ -44,7 +58,7 @@ var (
|
|
|
}
|
|
|
productOptionSelection = func(ln model.LanguageCode) []string {
|
|
|
return append([]string{"id", "position", "created_at", "updated_at", "published_at", "deleted_at"},
|
|
|
- ln.SqlFieldSelection("name", ""),
|
|
|
+ ln.SqlFieldSelection("name", "", ""),
|
|
|
ln.SqlArraySelection("values"),
|
|
|
)
|
|
|
}
|