-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
187 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { createActions } from 'redux-actions'; | |
import { RestApi } from '@magento/peregrine'; | ||
|
||
import { closeDrawer } from 'src/actions/app'; | ||
import { clearGuestCartId, getGuestCartId } from 'src/actions/cart'; | ||
import { clearGuestCartId, getCartDetails } from 'src/actions/cart'; | ||
|
||
const prefix = 'CHECKOUT'; | ||
const actionTypes = ['EDIT', 'RESET']; | ||
|
@@ -52,25 +52,27 @@ export const submitCart = () => | |
}; | ||
|
||
export const submitInput = () => | ||
async function thunk(dispatch) { | ||
dispatch(actions.input.submit()); | ||
async function thunk(dispatch, getState) { | ||
const { cart } = getState(); | ||
const { guestCartId } = cart; | ||
|
||
try { | ||
const guestCartId = await getGuestCartId(...arguments); | ||
if (!guestCartId) { | ||
throw new Error('Missing required information: guestCartId'); | ||
} | ||
|
||
if (!guestCartId) { | ||
throw new Error('Missing required information: guestCartId'); | ||
} | ||
dispatch(actions.input.submit()); | ||
|
||
try { | ||
const address = formatAddress(); | ||
const response = await request( | ||
`/rest/V1/guest-carts/${guestCartId}/shipping-information`, | ||
{ | ||
method: 'POST', | ||
// TODO: replace with real data from cart state | ||
body: JSON.stringify({ | ||
addressInformation: { | ||
billing_address: getAddress(), | ||
shipping_address: getAddress(), | ||
billing_address: address, | ||
shipping_address: address, | ||
shipping_method_code: 'flatrate', | ||
shipping_carrier_code: 'flatrate' | ||
} | ||
|
@@ -79,22 +81,24 @@ export const submitInput = () => | |
); | ||
|
||
dispatch(actions.input.accept(response)); | ||
dispatch(getCartDetails({ forceRefresh: true })); | ||
} catch (error) { | ||
dispatch(actions.input.reject(error)); | ||
} | ||
}; | ||
|
||
export const submitOrder = () => | ||
async function thunk(dispatch) { | ||
dispatch(actions.order.submit()); | ||
async function thunk(dispatch, getState) { | ||
const { cart } = getState(); | ||
const { guestCartId } = cart; | ||
|
||
try { | ||
const guestCartId = await getGuestCartId(...arguments); | ||
if (!guestCartId) { | ||
throw new Error('Missing required information: guestCartId'); | ||
} | ||
|
||
if (!guestCartId) { | ||
throw new Error('Missing required information: guestCartId'); | ||
} | ||
dispatch(actions.order.submit()); | ||
|
||
try { | ||
const response = await request( | ||
`/rest/V1/guest-carts/${guestCartId}/order`, | ||
{ | ||
|
@@ -117,7 +121,6 @@ export const submitOrder = () => | |
|
||
/* helpers */ | ||
|
||
// TODO: replace with real address data | ||
const mockAddress = { | ||
country_id: 'US', | ||
firstname: 'Veronica', | ||
|
@@ -132,7 +135,6 @@ const mockAddress = { | |
email: '[email protected]' | ||
}; | ||
|
||
// TODO: replace with real address data | ||
function getAddress() { | ||
return mockAddress; | ||
function formatAddress(address = mockAddress) { | ||
return address; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.