Add support for package payment methods and basic checkout proccess
This commit is contained in:
@@ -57,24 +57,21 @@ export const receiveCustomerDetails = (json) => ({
|
||||
export const fetchCartCount = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCartCount());
|
||||
//TODO : fetch cart count from woocommerce (requires plugin)
|
||||
dispatch(receiveShopCartCount(0));
|
||||
/*
|
||||
return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'cartItemsCount' in response.data) {
|
||||
dispatch(receiveShopCartCount(response.data.cartItemsCount));
|
||||
|
||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/cart/count`}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'count' in response.data) {
|
||||
dispatch(receiveShopCartCount(response.data.count));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchCartItems = (isForSteps = false) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCartItems());
|
||||
return client.fetch({url: `${API_SERVER}/cart/api/getCartItems`}).then(response => {
|
||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/cart/items`}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'cartItems' in response.data) {
|
||||
dispatch(receiveShopCartItems(response.data.cartItems));
|
||||
dispatch(fetchCartDocuments(response.data.cartItems.map((cartItem) => cartItem.idPackage), isForSteps));
|
||||
@@ -95,6 +92,7 @@ const updateCartItems = (newItem)=>(
|
||||
export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
||||
const params = {
|
||||
idPackage: cartItem.idPackage || 0,
|
||||
package_item_key: cartItem.key,
|
||||
idCustomerInstance: cartItem.idCustomerInstance || 0,
|
||||
idPrice: cartItem.idPrice || 0,
|
||||
quantity
|
||||
@@ -102,7 +100,7 @@ export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
||||
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/updateQuantity`,
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/update-quantity`,
|
||||
method: 'post',
|
||||
data: params
|
||||
}).then(response => {
|
||||
@@ -124,12 +122,14 @@ export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const removeCartItem = (idCart) => {
|
||||
export const removeCartItem = (cartItemKey) => {
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/removeFromCart`,
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/remove`,
|
||||
method: 'post',
|
||||
data: {idCart}
|
||||
data: {
|
||||
package_item_key: cartItemKey
|
||||
}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||
@@ -180,15 +180,46 @@ const resetSteps = () => ({type: RESET_STEPS});
|
||||
|
||||
export const getCustomerDetails = () => {
|
||||
return dispatch => {
|
||||
return client.fetch({url: `${API_SERVER}/cart/api/getCustomerDetails`})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && response.data.customerDetails) {
|
||||
const customerDetails = response.data.customerDetails;
|
||||
dispatch(receiveCustomerDetails(customerDetails));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
dispatch(receiveCustomerDetails({
|
||||
"companyName": "Coor Service Management AB",
|
||||
"vatCode": "556084-6783",
|
||||
"details": {
|
||||
"idBillingAddress": null,
|
||||
"idDeliveryAddress": null,
|
||||
"idProject": null,
|
||||
"reference": null,
|
||||
"tender": null
|
||||
},
|
||||
"billing": [
|
||||
{
|
||||
"id": 1,
|
||||
"city": "Göteborg",
|
||||
"countryName": "SE",
|
||||
"detailedAddress": "Lilla Bommen 2",
|
||||
"firstName": "Customer",
|
||||
"lastName": "User",
|
||||
"zipCode": "12323"
|
||||
}
|
||||
],
|
||||
"deliveryAddresses": [
|
||||
{
|
||||
"id": 1,
|
||||
"city": "Göteborg",
|
||||
"countryName": "Göteborg",
|
||||
"detailedAddress": "Lilla Bommen 2",
|
||||
"zipCode": "12323"
|
||||
}
|
||||
]
|
||||
}));
|
||||
// return client.fetch({url: `${API_SERVER}/wp-json/wiaas/cart/customer-details`})
|
||||
// .then(response => {
|
||||
// if (typeof response.data !== 'undefined' && response.data.customerDetails) {
|
||||
// const customerDetails = response.data.customerDetails;
|
||||
// dispatch(receiveCustomerDetails(customerDetails));
|
||||
// }
|
||||
// }).catch(error => {
|
||||
// client.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +270,8 @@ export const fetchCartDocuments = (packages, isForSteps = false) => {
|
||||
dispatch(requestCartDocuments());
|
||||
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/getCartDocuments`,
|
||||
method: 'post',
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||
method: 'get',
|
||||
data: {packages}
|
||||
}).then(response => {
|
||||
if (response.data) {
|
||||
@@ -262,18 +293,20 @@ export const selectCountryBilling = (country) => ({type: SELECT_COUNTRY_BILLING,
|
||||
export const saveOrderDetails = (orderDetails, cartItems) => {
|
||||
const orderInfo = {orderDetails, cartItems};
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/saveOrderDetails`,
|
||||
method: 'post',
|
||||
data: {orderDetails, cartItems}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(getCustomerDetails());
|
||||
dispatch(setOrderInfo(orderInfo));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
dispatch(getCustomerDetails());
|
||||
dispatch(setOrderInfo(orderInfo));
|
||||
// return client.fetch({
|
||||
// url: `${API_SERVER}/cart/api/saveOrderDetails`,
|
||||
// method: 'post',
|
||||
// data: {orderDetails, cartItems}
|
||||
// }).then(response => {
|
||||
// if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
// dispatch(getCustomerDetails());
|
||||
// dispatch(setOrderInfo(orderInfo));
|
||||
// }
|
||||
// }).catch(error => {
|
||||
// client.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,9 +319,9 @@ export const placeOrder = (orderInfo) => {
|
||||
const {orderDetails, cartItems} = orderInfo;
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/placeOrder`,
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/place-order`,
|
||||
method: 'post',
|
||||
data: {orderDetails, cartItems}
|
||||
data: orderDetails
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||
|
||||
Reference in New Issue
Block a user