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:
jordi fita mas 2023-10-13 20:44:24 +02:00
parent 2e10966ad7
commit d1b43e5062
4 changed files with 45 additions and 54 deletions

View File

@ -10,7 +10,6 @@ import (
gotemplate "html/template"
"net/http"
"github.com/jackc/pgx/v4"
"golang.org/x/text/language"
"dev.tandem.ws/tandem/camper/pkg/auth"
@ -67,12 +66,7 @@ type typePrice struct {
SeasonColor string
MinNights int
PricePerNight string
Options []*optionPrice
}
type optionPrice struct {
OptionName string
PricePerNight string
HasOptions bool
}
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
, to_color(season.color)::text
, coalesce(cost.min_nights, 1)
, to_price(coalesce(cost.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)
, to_price(coalesce(cost.cost_per_night, 0) + coalesce(option.cost_per_night, 0))
, option.cost_per_night is not null
from season
left join season_i18n as i18n on season.season_id = i18n.season_id and i18n.lang_tag = $1
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
) as cost on cost.season_id = season.season_id
left join (
select option.*
from campsite_type_option as option
join campsite_type as type on option.campsite_type_id = type.campsite_type_id and type.slug = $2
) as option on true
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
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
select season_id
, sum(lower(range) * cost_per_night)::integer as cost_per_night
from campsite_type_option
join campsite_type using(campsite_type_id)
join campsite_type_option_cost using (campsite_type_option_id)
where slug = $2
group by season_id
) as option on option.season_id = season.season_id
where season.active
group by i18n.name
, season.name
, season.color
, cost.min_nights
, cost.cost_per_night
`, pgx.QueryResultFormats{pgx.BinaryFormatCode}, language, slug)
`, language, slug)
if err != nil {
return nil, err
}
@ -146,16 +137,9 @@ func collectPrices(ctx context.Context, conn *database.Conn, language language.T
var prices []*typePrice
for rows.Next() {
price := &typePrice{}
var options database.RecordArray
if err := rows.Scan(&price.SeasonName, &price.SeasonColor, &price.MinNights, &price.PricePerNight, &options); err != nil {
if err := rows.Scan(&price.SeasonName, &price.SeasonColor, &price.MinNights, &price.PricePerNight, &price.HasOptions); err != nil {
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)
}
return prices, nil

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\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"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Catalan <ca@dodds.net>\n"
@ -84,34 +84,34 @@ msgctxt "title"
msgid "Prices"
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"
msgstr "%s €/nit"
#: web/templates/public/campsite/type.gohtml:50
msgid "%s: %s €/night"
msgstr "%s: %s €/nit"
#: web/templates/public/campsite/type.gohtml:53
#: web/templates/public/campsite/type.gohtml:54
msgid "*Minimum %d nights per stay"
msgstr "*Mínim %d nits per estada"
#: web/templates/public/campsite/type.gohtml:62
#: web/templates/public/campsite/type.gohtml:63
msgctxt "title"
msgid "Features"
msgstr "Característiques"
#: web/templates/public/campsite/type.gohtml:73
#: web/templates/public/campsite/type.gohtml:74
msgctxt "title"
msgid "Info"
msgstr "Informació"
#: web/templates/public/campsite/type.gohtml:77
#: web/templates/public/campsite/type.gohtml:78
msgctxt "title"
msgid "Facilities"
msgstr "Equipaments"
#: web/templates/public/campsite/type.gohtml:81
#: web/templates/public/campsite/type.gohtml:82
msgctxt "title"
msgid "Description"
msgstr "Descripció"
@ -1358,6 +1358,9 @@ msgstr "No podeu deixar el fitxer del mèdia en blanc."
msgid "Filename can not be empty."
msgstr "No podeu deixar el nom del fitxer en blanc."
#~ msgid "%s: %s €/night"
#~ msgstr "%s: %s €/nit"
#~ msgctxt "title"
#~ msgid "Pricing"
#~ msgstr "Preus"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\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"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Spanish <es@tp.org.es>\n"
@ -84,34 +84,34 @@ msgctxt "title"
msgid "Prices"
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"
msgstr "%s €/noche"
#: web/templates/public/campsite/type.gohtml:50
msgid "%s: %s €/night"
msgstr "%s: %s €/noche"
#: web/templates/public/campsite/type.gohtml:53
#: web/templates/public/campsite/type.gohtml:54
msgid "*Minimum %d nights per stay"
msgstr "*Mínimo %d noches por estancia"
#: web/templates/public/campsite/type.gohtml:62
#: web/templates/public/campsite/type.gohtml:63
msgctxt "title"
msgid "Features"
msgstr "Características"
#: web/templates/public/campsite/type.gohtml:73
#: web/templates/public/campsite/type.gohtml:74
msgctxt "title"
msgid "Info"
msgstr "Información"
#: web/templates/public/campsite/type.gohtml:77
#: web/templates/public/campsite/type.gohtml:78
msgctxt "title"
msgid "Facilities"
msgstr "Equipamento"
#: web/templates/public/campsite/type.gohtml:81
#: web/templates/public/campsite/type.gohtml:82
msgctxt "title"
msgid "Description"
msgstr "Descripción"
@ -1358,6 +1358,9 @@ msgstr "No podéis dejar el archivo del medio en blanco."
msgid "Filename can not be empty."
msgstr "No podéis dejar el nombre del archivo en blanco."
#~ msgid "%s: %s €/night"
#~ msgstr "%s: %s €/noche"
#~ msgctxt "title"
#~ msgid "Pricing"
#~ msgstr "Precios"

View File

@ -44,9 +44,10 @@
</svg>
{{ .SeasonName }}
</dt>
{{ if .HasOptions -}}
<dd>{{ printf (gettext "Starting from %s €/night") .PricePerNight }}</dd>
{{- else -}}
<dd>{{ printf (gettext "%s €/night") .PricePerNight }}</dd>
{{ range .Options }}
<dd>{{ printf (gettext "%s: %s €/night") .OptionName .PricePerNight }}</dd>
{{- end }}
{{ if gt .MinNights 1 -}}
<dd>{{ printf (gettext "*Minimum %d nights per stay") .MinNights }}</dd>