pages/checkout/index.js
/**
   * Generate a checkout token. This is called when the checkout first loads.
   */
Generate a checkout token. This is called when the checkout first loads.
Generate a checkout token . This is called when the checkout first loads .
generateToken() {
    const { cart, dispatchGenerateCheckout, dispatchGetShippingOptions } = this.props;
    const { 'shipping[country]': country, 'shipping[region]': region } = this.state;
    if (typeof cart.id === 'undefined') {
      return;
    }
    return dispatchGenerateCheckout(cart.id)
      .then((checkout) => {
        getAllCountries(checkout).then(countries => this.setState({ countries }));
        return dispatchGetShippingOptions(checkout.id, country, region)
          .then(shippingOptions => {
            if (shippingOptions.length) {
              this.setState({
                'fulfillment[shipping_method]': shippingOptions[0].id,
              });
            }
          });
      })
      .catch(error => {
        console.log('error caught in checkout/index.js in generateToken', error);
      })
  }
generateToken ( ) { const { cart , dispatchGenerateCheckout , dispatchGetShippingOptions } = this . props ; const { 'shipping[country]' : country , 'shipping[region]' : region } = this . state ; if ( typeof cart . id === 'undefined' ) { return ; } return dispatchGenerateCheckout ( cart . id ) . then ( ( checkout ) => { getAllCountries ( checkout ) . then ( countries => this . setState ( { countries } ) ) ; return dispatchGetShippingOptions ( checkout . id , country , region ) . then ( shippingOptions => { if ( shippingOptions . length ) { this . setState ( { 'fulfillment[shipping_method]' : shippingOptions [ 0 ] . id , } ) ; } } ) ; } ) . catch ( error => { console . log ( 'error caught in checkout/index.js in generateToken' , error ) ; } ) }
Generate a checkout token.
Generate a checkout token .
// Wait for a future update when a cart ID exists // continue and dispatch getShippingOptionsForCheckout to get shipping options based on checkout.id