From d1b43e50621d220ad32bd365839a4e8a975b048e Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Fri, 13 Oct 2023 20:44:24 +0200 Subject: [PATCH] =?UTF-8?q?Show=20=E2=80=9CStarting=20from=E2=80=9D=20pric?= =?UTF-8?q?e=20with=20campsite=20types=20that=20have=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pkg/campsite/types/public.go | 42 +++++++---------------- po/ca.po | 25 ++++++++------ po/es.po | 25 ++++++++------ web/templates/public/campsite/type.gohtml | 7 ++-- 4 files changed, 45 insertions(+), 54 deletions(-) diff --git a/pkg/campsite/types/public.go b/pkg/campsite/types/public.go index a16cb33..8ec21c0 100644 --- a/pkg/campsite/types/public.go +++ b/pkg/campsite/types/public.go @@ -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 diff --git a/po/ca.po b/po/ca.po index 11af1cf..336de78 100644 --- a/po/ca.po +++ b/po/ca.po @@ -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 \n" "Language-Team: Catalan \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" diff --git a/po/es.po b/po/es.po index 25e0646..46d2a40 100644 --- a/po/es.po +++ b/po/es.po @@ -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 \n" "Language-Team: Spanish \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" diff --git a/web/templates/public/campsite/type.gohtml b/web/templates/public/campsite/type.gohtml index 0a243f4..c7b71c7 100644 --- a/web/templates/public/campsite/type.gohtml +++ b/web/templates/public/campsite/type.gohtml @@ -44,9 +44,10 @@ {{ .SeasonName }} -
{{ printf (gettext "%s €/night") .PricePerNight }}
- {{ range .Options }} -
{{ printf (gettext "%s: %s €/night") .OptionName .PricePerNight }}
+ {{ if .HasOptions -}} +
{{ printf (gettext "Starting from %s €/night") .PricePerNight }}
+ {{- else -}} +
{{ printf (gettext "%s €/night") .PricePerNight }}
{{- end }} {{ if gt .MinNights 1 -}}
{{ printf (gettext "*Minimum %d nights per stay") .MinNights }}