Show “Starting from” price with campsite types that have options
In the old website, the prices where show with all the options, but in the new design only a single price is show, that in the case of campsites with options is the price per night of the “base” plus the minimum options selected.
This commit is contained in:
parent
2e10966ad7
commit
d1b43e5062
|
@ -10,7 +10,6 @@ import (
|
||||||
gotemplate "html/template"
|
gotemplate "html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v4"
|
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
|
||||||
"dev.tandem.ws/tandem/camper/pkg/auth"
|
"dev.tandem.ws/tandem/camper/pkg/auth"
|
||||||
|
@ -67,12 +66,7 @@ type typePrice struct {
|
||||||
SeasonColor string
|
SeasonColor string
|
||||||
MinNights int
|
MinNights int
|
||||||
PricePerNight string
|
PricePerNight string
|
||||||
Options []*optionPrice
|
HasOptions bool
|
||||||
}
|
|
||||||
|
|
||||||
type optionPrice struct {
|
|
||||||
OptionName string
|
|
||||||
PricePerNight string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type typeFeature struct {
|
type typeFeature struct {
|
||||||
|
@ -118,27 +112,24 @@ func collectPrices(ctx context.Context, conn *database.Conn, language language.T
|
||||||
select coalesce(i18n.name, season.name) as l10n_name
|
select coalesce(i18n.name, season.name) as l10n_name
|
||||||
, to_color(season.color)::text
|
, to_color(season.color)::text
|
||||||
, coalesce(cost.min_nights, 1)
|
, coalesce(cost.min_nights, 1)
|
||||||
, to_price(coalesce(cost.cost_per_night, 0))
|
, to_price(coalesce(cost.cost_per_night, 0) + coalesce(option.cost_per_night, 0))
|
||||||
, array_agg((coalesce(option_i18n.name, option.name), to_price(coalesce(option_cost.cost_per_night, 0)))) filter (where option.campsite_type_option_id is not null)
|
, option.cost_per_night is not null
|
||||||
from season
|
from season
|
||||||
left join season_i18n as i18n on season.season_id = i18n.season_id and i18n.lang_tag = $1
|
left join season_i18n as i18n on season.season_id = i18n.season_id and i18n.lang_tag = $1
|
||||||
left join (
|
left join (
|
||||||
campsite_type_cost as cost join campsite_type as type on cost.campsite_type_id = type.campsite_type_id and type.slug = $2
|
campsite_type_cost as cost join campsite_type as type on cost.campsite_type_id = type.campsite_type_id and type.slug = $2
|
||||||
) as cost on cost.season_id = season.season_id
|
) as cost on cost.season_id = season.season_id
|
||||||
left join (
|
left join (
|
||||||
select option.*
|
select season_id
|
||||||
from campsite_type_option as option
|
, sum(lower(range) * cost_per_night)::integer as cost_per_night
|
||||||
join campsite_type as type on option.campsite_type_id = type.campsite_type_id and type.slug = $2
|
from campsite_type_option
|
||||||
) as option on true
|
join campsite_type using(campsite_type_id)
|
||||||
left join campsite_type_option_i18n as option_i18n on option_i18n.campsite_type_option_id = option.campsite_type_option_id and option_i18n.lang_tag = $1
|
join campsite_type_option_cost using (campsite_type_option_id)
|
||||||
left join campsite_type_option_cost as option_cost on option_cost.campsite_type_option_id = option.campsite_type_option_id and option_cost.season_id = season.season_id
|
where slug = $2
|
||||||
|
group by season_id
|
||||||
|
) as option on option.season_id = season.season_id
|
||||||
where season.active
|
where season.active
|
||||||
group by i18n.name
|
`, language, slug)
|
||||||
, season.name
|
|
||||||
, season.color
|
|
||||||
, cost.min_nights
|
|
||||||
, cost.cost_per_night
|
|
||||||
`, pgx.QueryResultFormats{pgx.BinaryFormatCode}, language, slug)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -146,16 +137,9 @@ func collectPrices(ctx context.Context, conn *database.Conn, language language.T
|
||||||
var prices []*typePrice
|
var prices []*typePrice
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
price := &typePrice{}
|
price := &typePrice{}
|
||||||
var options database.RecordArray
|
if err := rows.Scan(&price.SeasonName, &price.SeasonColor, &price.MinNights, &price.PricePerNight, &price.HasOptions); err != nil {
|
||||||
if err := rows.Scan(&price.SeasonName, &price.SeasonColor, &price.MinNights, &price.PricePerNight, &options); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, el := range options.Elements {
|
|
||||||
price.Options = append(price.Options, &optionPrice{
|
|
||||||
OptionName: el.Fields[0].Get().(string),
|
|
||||||
PricePerNight: el.Fields[1].Get().(string),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
prices = append(prices, price)
|
prices = append(prices, price)
|
||||||
}
|
}
|
||||||
return prices, nil
|
return prices, nil
|
||||||
|
|
25
po/ca.po
25
po/ca.po
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: camper\n"
|
"Project-Id-Version: camper\n"
|
||||||
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
|
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
|
||||||
"POT-Creation-Date: 2023-10-13 20:28+0200\n"
|
"POT-Creation-Date: 2023-10-13 20:40+0200\n"
|
||||||
"PO-Revision-Date: 2023-07-22 23:45+0200\n"
|
"PO-Revision-Date: 2023-07-22 23:45+0200\n"
|
||||||
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
|
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
|
||||||
"Language-Team: Catalan <ca@dodds.net>\n"
|
"Language-Team: Catalan <ca@dodds.net>\n"
|
||||||
|
@ -84,34 +84,34 @@ msgctxt "title"
|
||||||
msgid "Prices"
|
msgid "Prices"
|
||||||
msgstr "Preus"
|
msgstr "Preus"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:48
|
#: web/templates/public/campsite/type.gohtml:49
|
||||||
|
msgid "Starting from %s €/night"
|
||||||
|
msgstr "A partir de %s €/nit"
|
||||||
|
|
||||||
|
#: web/templates/public/campsite/type.gohtml:51
|
||||||
msgid "%s €/night"
|
msgid "%s €/night"
|
||||||
msgstr "%s €/nit"
|
msgstr "%s €/nit"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:50
|
#: web/templates/public/campsite/type.gohtml:54
|
||||||
msgid "%s: %s €/night"
|
|
||||||
msgstr "%s: %s €/nit"
|
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:53
|
|
||||||
msgid "*Minimum %d nights per stay"
|
msgid "*Minimum %d nights per stay"
|
||||||
msgstr "*Mínim %d nits per estada"
|
msgstr "*Mínim %d nits per estada"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:62
|
#: web/templates/public/campsite/type.gohtml:63
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Features"
|
msgid "Features"
|
||||||
msgstr "Característiques"
|
msgstr "Característiques"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:73
|
#: web/templates/public/campsite/type.gohtml:74
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Info"
|
msgid "Info"
|
||||||
msgstr "Informació"
|
msgstr "Informació"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:77
|
#: web/templates/public/campsite/type.gohtml:78
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Facilities"
|
msgid "Facilities"
|
||||||
msgstr "Equipaments"
|
msgstr "Equipaments"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:81
|
#: web/templates/public/campsite/type.gohtml:82
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Description"
|
msgid "Description"
|
||||||
msgstr "Descripció"
|
msgstr "Descripció"
|
||||||
|
@ -1358,6 +1358,9 @@ msgstr "No podeu deixar el fitxer del mèdia en blanc."
|
||||||
msgid "Filename can not be empty."
|
msgid "Filename can not be empty."
|
||||||
msgstr "No podeu deixar el nom del fitxer en blanc."
|
msgstr "No podeu deixar el nom del fitxer en blanc."
|
||||||
|
|
||||||
|
#~ msgid "%s: %s €/night"
|
||||||
|
#~ msgstr "%s: %s €/nit"
|
||||||
|
|
||||||
#~ msgctxt "title"
|
#~ msgctxt "title"
|
||||||
#~ msgid "Pricing"
|
#~ msgid "Pricing"
|
||||||
#~ msgstr "Preus"
|
#~ msgstr "Preus"
|
||||||
|
|
25
po/es.po
25
po/es.po
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: camper\n"
|
"Project-Id-Version: camper\n"
|
||||||
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
|
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
|
||||||
"POT-Creation-Date: 2023-10-13 20:28+0200\n"
|
"POT-Creation-Date: 2023-10-13 20:40+0200\n"
|
||||||
"PO-Revision-Date: 2023-07-22 23:46+0200\n"
|
"PO-Revision-Date: 2023-07-22 23:46+0200\n"
|
||||||
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
|
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
|
||||||
"Language-Team: Spanish <es@tp.org.es>\n"
|
"Language-Team: Spanish <es@tp.org.es>\n"
|
||||||
|
@ -84,34 +84,34 @@ msgctxt "title"
|
||||||
msgid "Prices"
|
msgid "Prices"
|
||||||
msgstr "Precios"
|
msgstr "Precios"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:48
|
#: web/templates/public/campsite/type.gohtml:49
|
||||||
|
msgid "Starting from %s €/night"
|
||||||
|
msgstr "A partir de %s €/noche"
|
||||||
|
|
||||||
|
#: web/templates/public/campsite/type.gohtml:51
|
||||||
msgid "%s €/night"
|
msgid "%s €/night"
|
||||||
msgstr "%s €/noche"
|
msgstr "%s €/noche"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:50
|
#: web/templates/public/campsite/type.gohtml:54
|
||||||
msgid "%s: %s €/night"
|
|
||||||
msgstr "%s: %s €/noche"
|
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:53
|
|
||||||
msgid "*Minimum %d nights per stay"
|
msgid "*Minimum %d nights per stay"
|
||||||
msgstr "*Mínimo %d noches por estancia"
|
msgstr "*Mínimo %d noches por estancia"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:62
|
#: web/templates/public/campsite/type.gohtml:63
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Features"
|
msgid "Features"
|
||||||
msgstr "Características"
|
msgstr "Características"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:73
|
#: web/templates/public/campsite/type.gohtml:74
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Info"
|
msgid "Info"
|
||||||
msgstr "Información"
|
msgstr "Información"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:77
|
#: web/templates/public/campsite/type.gohtml:78
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Facilities"
|
msgid "Facilities"
|
||||||
msgstr "Equipamento"
|
msgstr "Equipamento"
|
||||||
|
|
||||||
#: web/templates/public/campsite/type.gohtml:81
|
#: web/templates/public/campsite/type.gohtml:82
|
||||||
msgctxt "title"
|
msgctxt "title"
|
||||||
msgid "Description"
|
msgid "Description"
|
||||||
msgstr "Descripción"
|
msgstr "Descripción"
|
||||||
|
@ -1358,6 +1358,9 @@ msgstr "No podéis dejar el archivo del medio en blanco."
|
||||||
msgid "Filename can not be empty."
|
msgid "Filename can not be empty."
|
||||||
msgstr "No podéis dejar el nombre del archivo en blanco."
|
msgstr "No podéis dejar el nombre del archivo en blanco."
|
||||||
|
|
||||||
|
#~ msgid "%s: %s €/night"
|
||||||
|
#~ msgstr "%s: %s €/noche"
|
||||||
|
|
||||||
#~ msgctxt "title"
|
#~ msgctxt "title"
|
||||||
#~ msgid "Pricing"
|
#~ msgid "Pricing"
|
||||||
#~ msgstr "Precios"
|
#~ msgstr "Precios"
|
||||||
|
|
|
@ -44,9 +44,10 @@
|
||||||
</svg>
|
</svg>
|
||||||
{{ .SeasonName }}
|
{{ .SeasonName }}
|
||||||
</dt>
|
</dt>
|
||||||
<dd>{{ printf (gettext "%s €/night") .PricePerNight }}</dd>
|
{{ if .HasOptions -}}
|
||||||
{{ range .Options }}
|
<dd>{{ printf (gettext "Starting from %s €/night") .PricePerNight }}</dd>
|
||||||
<dd>{{ printf (gettext "%s: %s €/night") .OptionName .PricePerNight }}</dd>
|
{{- else -}}
|
||||||
|
<dd>{{ printf (gettext "%s €/night") .PricePerNight }}</dd>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ if gt .MinNights 1 -}}
|
{{ if gt .MinNights 1 -}}
|
||||||
<dd>{{ printf (gettext "*Minimum %d nights per stay") .MinNights }}</dd>
|
<dd>{{ printf (gettext "*Minimum %d nights per stay") .MinNights }}</dd>
|
||||||
|
|
Loading…
Reference in New Issue