fix: envoie correctement les adresses du client lors d'une commande
- une mise à jour WooCommerce a changé les clés attendues des adresses dans le corps de la requête pour la création d'une comande.
This commit is contained in:
parent
96983c5218
commit
f8c83a6331
8 changed files with 37 additions and 3110 deletions
|
|
@ -33,7 +33,7 @@ export default defineConfig(async ({ mode }) => {
|
|||
emptyOutDir: true,
|
||||
/* Génère un fichier manifeste dans outDir */
|
||||
manifest: true,
|
||||
minify: env.VITE_MODE === "development",
|
||||
minify: env.VITE_MODE === "production",
|
||||
outDir: resolve("./web/app/themes/haiku-atelier-2024/assets/js"),
|
||||
reportCompressedSize: true,
|
||||
rollupOptions: {
|
||||
|
|
@ -51,7 +51,7 @@ export default defineConfig(async ({ mode }) => {
|
|||
target: "es2020",
|
||||
write: true,
|
||||
},
|
||||
mode: env.VITE_MODE ?? "development",
|
||||
mode: env.VITE_MODE ?? "production",
|
||||
plugins: [
|
||||
// Permet de valider les variables d'environnements définies à partir d'un schéma Valibot
|
||||
valibot(SCHEMA_ENVIRONNEMENT),
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -21,20 +21,20 @@ export const WCAddressErrorSchema = v.object({
|
|||
code: v.literal("rest_invalid_param"),
|
||||
data: v.object({
|
||||
details: v.object({
|
||||
billing_address: v.optional(v.object({
|
||||
billing: v.optional(v.object({
|
||||
code: v.string(),
|
||||
data: v.union([v.null(), v.string()]),
|
||||
message: v.string(),
|
||||
})),
|
||||
shipping_address: v.optional(v.object({
|
||||
shipping: v.optional(v.object({
|
||||
code: v.string(),
|
||||
data: v.union([v.null(), v.string()]),
|
||||
message: v.string(),
|
||||
})),
|
||||
}),
|
||||
params: v.object({
|
||||
billing_address: v.optional(v.string()),
|
||||
shipping_address: v.optional(v.string()),
|
||||
billing: v.optional(v.string()),
|
||||
shipping: v.optional(v.string()),
|
||||
}),
|
||||
status: v.literal(400),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -127,9 +127,10 @@ export const initShippingCalculationButton = (): void => {
|
|||
.liftEither(safeSchemaParse(formArgs, WCStoreCartUpdateCustomerArgsSchema))
|
||||
// Désactive le Bouton pour empêcher des requêtes concurrentes
|
||||
.ifRight((): void => setButtonLoadingState(E.BOUTON_ACTIONS_FORMULAIRE, true))
|
||||
.chain((args: WCStoreCartUpdateCustomerArgs) =>
|
||||
safeFetch(postBackend(ROUTE_API_MAJ_CLIENT, JSON.stringify(args), false))
|
||||
)
|
||||
.chain((args: WCStoreCartUpdateCustomerArgs) => {
|
||||
logger.debug("ADRESSES", "args", args);
|
||||
return safeFetch(postBackend(ROUTE_API_MAJ_CLIENT, JSON.stringify(args), false));
|
||||
})
|
||||
.chain((rs: Response) => {
|
||||
logger.debug("ADRESSES", "initShippingCalculationButton", "rs", rs);
|
||||
return EitherAsync<ErreurAdresseInvalide | HttpCodeErrors, unknown>(async ({ throwE }): Promise<unknown> =>
|
||||
|
|
@ -288,12 +289,14 @@ export const initOrderCreationButton = (): void => {
|
|||
}));
|
||||
logger.debug("ADRESSES", "initOrderCreationButton", "cartProducts", cartProducts);
|
||||
|
||||
const addresses = getAddressesFromForm(formFields, E.BOUTON_SEPARATION_ADRESSES.checked);
|
||||
/** Les données du Formulaire transformées pour la requête vers le Backend. */
|
||||
const formArgs: WCV3OrdersArgs = {
|
||||
...getAddressesFromForm(formFields, E.BOUTON_SEPARATION_ADRESSES.checked),
|
||||
billing: addresses.billing_address,
|
||||
currency: selectedRateLS.currency_code,
|
||||
customer_note: E.INSTRUCTIONS_CLIENT.value,
|
||||
line_items: cartProducts,
|
||||
shipping: addresses.shipping_address,
|
||||
shipping_lines: [
|
||||
{
|
||||
method_id: selectedRateLS.method_id,
|
||||
|
|
@ -309,9 +312,10 @@ export const initOrderCreationButton = (): void => {
|
|||
.liftEither(safeSchemaParse(formArgs, WCV3OrdersArgsSchema))
|
||||
// Désactive le Bouton pour empêcher des requêtes concurrentes
|
||||
.ifRight((): void => setButtonLoadingState(E.BOUTON_ACTIONS_FORMULAIRE, true))
|
||||
.chain((args: WCV3OrdersArgs) =>
|
||||
safeFetch(postBackend(ROUTE_API_NOUVELLE_COMMANDES, JSON.stringify(args), true))
|
||||
)
|
||||
.chain((args: WCV3OrdersArgs) => {
|
||||
logger.debug("ADRESSES", "args commande", args);
|
||||
return safeFetch(postBackend(ROUTE_API_NOUVELLE_COMMANDES, JSON.stringify(args), true));
|
||||
})
|
||||
.chain((rs: Response) =>
|
||||
EitherAsync<HttpCodeErrors, unknown>(async ({ throwE }): Promise<unknown> =>
|
||||
match(await newPartialResponse(rs))
|
||||
|
|
@ -325,6 +329,8 @@ export const initOrderCreationButton = (): void => {
|
|||
E.BOUTON_ACTIONS_FORMULAIRE.textContent = "OK!";
|
||||
E.MESSAGE_ADRESSES.textContent = " ";
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Redirige vers Stripe
|
||||
Maybe
|
||||
.fromNullable(new URL(`https://${window.location.host}/checkout`))
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import type { Maybe } from "purify-ts";
|
||||
import { reporteEtJournaliseErreur } from "../lib/erreurs";
|
||||
import { getSessionStorageByKey, setSessionStorageByKey } from "../lib/session-storage";
|
||||
import { WCStoreShippingRateShippingRatesSchema } from "../lib/schemas/api/couts-livraison";
|
||||
|
||||
import type { WCStoreShippingRateShippingRates } from "../lib/types/api/couts-livraison";
|
||||
|
||||
import { reporteEtJournaliseErreur } from "../lib/erreurs";
|
||||
import { WCStoreShippingRateShippingRatesSchema } from "../lib/schemas/api/couts-livraison";
|
||||
import { getSessionStorageByKey, setSessionStorageByKey } from "../lib/session-storage";
|
||||
|
||||
/* LS = SessionStorage */
|
||||
|
||||
export const getShippingRatesLS = (): Maybe<WCStoreShippingRateShippingRates> =>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
import { forEach as arrayForEach, map as arrayMap } from "@mobily/ts-belt/Array";
|
||||
import { html, render, type TemplateResult } from "lit-html";
|
||||
|
||||
import type { WCStoreCartTotals, WCStoreShippingRateShippingRate } from "../lib/types/api/cart";
|
||||
import type { WCStoreShippingRateShippingRates } from "../lib/types/api/couts-livraison";
|
||||
|
||||
import { ATTRIBUT_HIDDEN } from "../constantes/dom";
|
||||
import { forEach, map } from "../lib/arrays";
|
||||
import { getDOMElementsWithSelector } from "../lib/dom";
|
||||
import { reporteEtJournaliseErreur } from "../lib/erreurs";
|
||||
import { createUpdatedShippingRatesEvent, createUpdatedTotalsEvent } from "../lib/evenements/panier";
|
||||
import { getSessionStorageByKey } from "../lib/session-storage";
|
||||
import { formateEnEuros } from "../lib/nombres";
|
||||
import { find } from "../lib/safe-arrays";
|
||||
import { WCStoreCartTotalsSchema } from "../lib/schemas/api/cart";
|
||||
import type { WCStoreCartTotals, WCStoreShippingRateShippingRate } from "../lib/types/api/cart";
|
||||
import type { WCStoreShippingRateShippingRates } from "../lib/types/api/couts-livraison";
|
||||
import { getSessionStorageByKey } from "../lib/session-storage";
|
||||
import { logger } from "../logging";
|
||||
import { E } from "./scripts-page-panier-elements";
|
||||
import { getShippingRatesLS } from "./scripts-page-panier-local-storage";
|
||||
|
|
|
|||
|
|
@ -5,6 +5,13 @@ import { forEach as arrayForEach, map as arrayMap } from "@mobily/ts-belt/Array"
|
|||
import { EitherAsync, Maybe } from "purify-ts";
|
||||
import { match, P } from "ts-pattern";
|
||||
import { type AnySchema, ValiError } from "valibot";
|
||||
|
||||
import type { WCStoreCart } from "../lib/types/api/cart";
|
||||
import type { WCStoreCartRemoveItemArgs } from "../lib/types/api/cart-remove-item";
|
||||
import type { WCStoreCartUpdateItemArgs } from "../lib/types/api/cart-update-item";
|
||||
import type { GenericPageState } from "../lib/types/pages";
|
||||
import type { FetchErrors, HttpCodeErrors } from "../lib/types/reseau";
|
||||
|
||||
import { ROUTE_API_MAJ_ARTICLE_PANIER, ROUTE_API_RETIRE_ARTICLE_PANIER } from "../constantes/api";
|
||||
import {
|
||||
ATTRIBUT_CLE_PANIER,
|
||||
|
|
@ -27,11 +34,6 @@ import { newPartialResponse, postBackend, safeFetch, traiteErreursBackendWooComm
|
|||
import { WCStoreCartSchema } from "../lib/schemas/api/cart";
|
||||
import { WCStoreCartRemoveItemArgsSchema } from "../lib/schemas/api/cart-remove-item";
|
||||
import { WCStoreCartUpdateItemArgsSchema } from "../lib/schemas/api/cart-update-item";
|
||||
import type { WCStoreCart } from "../lib/types/api/cart";
|
||||
import type { WCStoreCartRemoveItemArgs } from "../lib/types/api/cart-remove-item";
|
||||
import type { WCStoreCartUpdateItemArgs } from "../lib/types/api/cart-update-item";
|
||||
import type { GenericPageState } from "../lib/types/pages";
|
||||
import type { FetchErrors, HttpCodeErrors } from "../lib/types/reseau";
|
||||
import { safeSchemaParse } from "../lib/validation";
|
||||
import { E } from "./scripts-page-panier-elements";
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import {
|
|||
import { lanceAnimationCycleLoading } from "./lib/animations.ts";
|
||||
import { html, mustGetEleInDocument } from "./lib/dom.ts";
|
||||
import { BadRequestError, reporteErreur, ServerError } from "./lib/erreurs.ts";
|
||||
import { newPartialResponse, getBackendAvecParametresUrl } from "./lib/reseau.ts";
|
||||
import { getBackendAvecParametresUrl, newPartialResponse } from "./lib/reseau.ts";
|
||||
import { WCV3ProductsArgsSchema, WCV3ProductsSchema } from "./lib/schemas/api/v3/products.ts";
|
||||
import { safeSchemaParse } from "./lib/validation.ts";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue