import type { NextPage } from "next"; import { getShippingMethods, getShippingZones, } from "../../../services/woocommerceApi/ShippingMethods"; import { LightBackground } from "../../../styles/BackgroundStyle"; import LayoutAdmin from "../../../Layout/LayoutAdmin"; import { Button } from "../../../styles/ProductDetail"; import useCart from "../../../hooks/useCart"; import Image from "next/image"; import CouponsCode from "../../../components/CouponsCode"; import useUser from "../../../hooks/useUser"; import { createOrder } from "../../../services/woocommerceApi/Orders"; import LoginForm from "../../../components/Login"; import { StyledCheckout } from "../../../styles/CheckoutStyle"; import Input from "../../../components/Input"; import { ChangeEvent, useCallback, useState } from "react"; interface userShippingInfos { address_1: string; address_2: string; city: string; company: string; country: string; first_name: string; last_name: string; phone: string; postcode: string; state: string; } interface userBillingInfo { address_1: string; address_2: string; city: string; company: string; country: string; email: string; first_name: string; last_name: string; phone: string; postcode: string; state: string; } const CheckoutMagasin: NextPage = () => { // getShippingMethods(); // getShippingZones(); const { login, logout, user } = useUser(); console.log("userdata", user); const { cart, removeCartItem } = useCart(); const [userBilling, setUserBilling] = useState( {} as userBillingInfo ); const [userShipping, setUserShipping] = useState( {} as userShippingInfos ); const [otherShippingAdress, setOtherShippingAdress] = useState(false); const authorizedCounty = [ "Suisse", "France", "Allemagne", "Italie", "Belgique", "Espagne", "Autriche", "Hollande", ]; const order = { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: userBilling, shipping: userShipping, line_items: [ { product_id: 8140, quantity: 2, }, ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "10.00", }, ], }; //enregistrer email dans billing // enregistrer billing data // enregistrer shipping data //si case otherShipping true //faire apparaitre le formulaire //vider le formulaire //enregistrer new values //BILLING DATA HANDLE CHANGE// // handleChange for Billing Inputs const handleChange = useCallback( (event: ChangeEvent) => { setUserBilling({ ...userBilling, [event.target.name]: event.target.value, }); }, [userBilling] ); //handle change for billing country selector const handleCountryChange = useCallback( (event: ChangeEvent) => { setUserBilling({ ...userBilling, [event.target.name]: event.target.value, }); }, [userBilling] ); //SHIPPING DATA HANDLE CHANGE// // handleChange for different shipping address const handleChangeShipping = useCallback( (event: ChangeEvent) => { setOtherShippingAdress(!otherShippingAdress); setUserShipping({}as userShippingInfos) }, [otherShippingAdress] ); // handleChange for Billing Inputs const handleShippingChange = useCallback( (event: ChangeEvent) => { setUserShipping({ ...userShipping, [event.target.name]: event.target.value, }); }, [userShipping] ); //handle change for shipping country selector const handleShippingCountryChange = useCallback( (event: ChangeEvent) => { setUserShipping({ ...userShipping, [event.target.name]: event.target.value, }); }, [userShipping] ); const sendOrder = () => { console.log("test",order); // createOrder(order); }; console.log("userbilling-->", userBilling); console.log("user different shipping-->", otherShippingAdress); console.log("usershipping-->", userShipping); return (

Vos coordonnées

{!user.token && ( <>
Vous avez un compte?
Créer un nouveau compte ?
)}

Addresse de livraison différente ?

{otherShippingAdress && ( <> )}
    {cart.totalProductsCount > 0 ? ( cart.products.map((product) => { return (
  • {product.name}

    {product.qty}x CHF {product.price}

    {product.name}
  • ); }) ) : (
  • aucun produit

  • )}
Sous total:{" "} CHF {cart.totalProductsPrice?.toFixed(2)}

ajouter code promo

ajouter expedition (seulement point de vente)

ajouter tva

ajouter prix total

); }; export default CheckoutMagasin;