Open KBCodes2021 opened 2 years ago
I am stuck at the countries section, where I am getting an empty array. did you the list countries ?
For anyone new who got stuck, It looks like the error is coming from the commerce js company/webiste themselves as localeListShippingCountries is not working at all but it could be replaced with localeListCountries to display the countries but this function will list all of the countries that's in their website, not the one that you selected, not shipping countries that you want and getShippingOptions is not working at all
In Address form i am getting error "methods" is not defined please help me someone
i have installed same all pkg
I've completed 2/3rds of the project. I can log the token generated in Checkout.jsx and log it in the AddressForm.jsx. But when adding shippingSubdivision and setShippingOption I get HTTP 500 errors.
Any help would be appreciated! I've commented out components that were very unstable.
This is the Address Form: and Checkout is below:
import React, { useState, useEffect } from 'react'; import { InputLabel, Select, MenuItem, Button, Grid, Typography } from '@material-ui/core'; import { useForm, FormProvider } from 'react-hook-form'; import { Link } from 'react-router-dom';
import { commerce } from '../../lib/commerce'; import FormInput from './CustomTextField';
const AddressForm = ({ checkoutToken }) => { const [shippingCountries, setShippingCountries] = useState([]); const [shippingCountry, setShippingCountry] = useState(''); const [shippingSubdivisions, setShippingSubdivisions] = useState([]); const [shippingSubdivision, setShippingSubdivision] = useState(''); const [shippingOptions, setShippingOptions] = useState([]); const [shippingOption, setShippingOption] = useState(''); const methods = useForm();
const fetchShippingCountries = async (checkoutTokenId) => { const { countries } = await commerce.services.localeListShippingCountries(checkoutTokenId);
};
const fetchSubdivisions = async (countryCode) => { const { subdivisions } = await commerce.services.localeListSubdivisions(countryCode);
};
// const fetchShippingOptions = async (checkoutTokenId, country, stateProvince = null) => { // const options = await commerce.checkout.getShippingOptions(checkoutTokenId, { country, region: stateProvince });
// setShippingOptions(options); // setShippingOption(options[0].id); // };
}, []);
useEffect(() => { if (shippingCountry) fetchSubdivisions(shippingCountry); }, [shippingCountry]);
// useEffect(() => { // if (shippingSubdivision) fetchShippingOptions(checkoutToken.id, shippingCountry, shippingSubdivision); // }, [shippingSubdivision]);
); };
export default AddressForm;
Checkout
import React, { useState, useEffect } from 'react' import { Paper, Stepper, Step, StepLabel, Typography, CircularProgress, Divider, Button } from '@material-ui/core';
import { commerce } from '../../../lib/commerce'; import useStyles from './styles'; import AddressForm from '../AddressForm'; import PaymentForm from '../PaymentForm';
const steps = ['Shipping address', 'Payment details'];
const Checkout = ({ cart }) => { const [activeStep, setActiveStep] = useState(0); const [checkoutToken, setCheckoutToken] = useState(null); const classes = useStyles();
}
export default Checkout