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));
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from '../../constants/coMarketConstants';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
import {fetchCartCount} from '../cart/cartActions';
|
||||
import { fromWCPackage } from '../../helpers/PackageHelper';
|
||||
|
||||
const client = new HtmlClient();
|
||||
const priceHelper = new PriceHelper();
|
||||
@@ -41,28 +42,27 @@ export const fetchPackageDetails = (params) => {
|
||||
return dispatch => {
|
||||
dispatch(requestPackageDetails());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/coMarket/api/getShopPackageDetails`,
|
||||
method: 'post',
|
||||
data: params
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}`,
|
||||
method: 'get'
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data){
|
||||
const jsonData = response.data;
|
||||
const packageData = fromWCPackage(response.data);
|
||||
dispatch(clearSelections());
|
||||
if(jsonData.prices && jsonData.prices.length){
|
||||
dispatch(selectAgreement(jsonData.prices[0]));
|
||||
if(packageData.prices && packageData.prices.length){
|
||||
dispatch(selectAgreement(packageData.prices[0]));
|
||||
}
|
||||
|
||||
if(jsonData.groups){
|
||||
Object.keys(jsonData.groups).forEach((idGroup) => {
|
||||
const defaultOption = jsonData.groups[idGroup].options.find((option) => {return parseInt(option.isDefault, 10) === 1});
|
||||
if(packageData.groups){
|
||||
Object.keys(packageData.groups).forEach((idGroup) => {
|
||||
const defaultOption = packageData.groups[idGroup].options.find((option) => {return parseInt(option.isDefault, 10) === 1});
|
||||
if(defaultOption){
|
||||
dispatch(selectOption(idGroup, defaultOption));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dispatch(recievePackageDetails(jsonData));
|
||||
dispatch(recievePackageDetails(packageData));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -104,25 +104,25 @@ const requestAddToCart = () => ({
|
||||
});
|
||||
|
||||
export const addToCart = (addParams) => {
|
||||
const options = generateOptions(addParams.selectedOptions, addParams.selectedAdditionals, addParams.selectedAgreement);
|
||||
// const options = generateOptions(addParams.selectedOptions, addParams.selectedAdditionals, addParams.selectedAgreement);
|
||||
|
||||
const params = {
|
||||
idPackage: addParams.selectedPackage.packageInfo.idPackage,
|
||||
idPrice: addParams.selectedAgreement.idPrice,
|
||||
options: options.extraPackages
|
||||
'package_id': addParams.selectedPackage.id,
|
||||
'price_id': addParams.selectedAgreement.idPrice,
|
||||
//options: options.extraPackages
|
||||
};
|
||||
|
||||
if(options.unavailablePackages.length){
|
||||
const unavailable = options.unavailablePackages.map((unavailable) =>{return unavailable.optionName || unavailable.packageName;});
|
||||
const message = coMarketMessages.UNAVAILABLE_PACKAGES + ' ' + unavailable.join();
|
||||
|
||||
return dispatch => {dispatch(updateMessages([{code: 'warning', message}], coMarketMessages))};
|
||||
}
|
||||
// if(options.unavailablePackages.length){
|
||||
// const unavailable = options.unavailablePackages.map((unavailable) =>{return unavailable.optionName || unavailable.packageName;});
|
||||
// const message = coMarketMessages.UNAVAILABLE_PACKAGES + ' ' + unavailable.join();
|
||||
//
|
||||
// return dispatch => {dispatch(updateMessages([{code: 'warning', message}], coMarketMessages))};
|
||||
// }
|
||||
|
||||
return dispatch => {
|
||||
dispatch(requestAddToCart());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/coMarket/api/addToCart`,
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/add`,
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
|
||||
@@ -49,8 +49,36 @@ export const validateAccessToken = (token) => {
|
||||
// const serverTime = response.data.serverTime || 1;
|
||||
|
||||
dispatch(loggedIn({
|
||||
accessToken: token
|
||||
// userInfo: response.data.userInfo
|
||||
accessToken: token,
|
||||
userInfo: {
|
||||
"id": 2,
|
||||
"name": "Customer User",
|
||||
"mail": "customer@mail.com",
|
||||
"phone": "",
|
||||
"userType": "customer",
|
||||
"vatCode": "556084-6783",
|
||||
"companyName": "Coor Service Management AB",
|
||||
"billingAddresses": [
|
||||
{
|
||||
"id": 1,
|
||||
"city": "fsdfcsdfcs",
|
||||
"countryName": "SE",
|
||||
"detailedAddress": "sdfcsvfsdf, fdfvds, fdfvds",
|
||||
"firstName": "Customer",
|
||||
"lastName": "User",
|
||||
"zipCode": "323232"
|
||||
}
|
||||
],
|
||||
"profileAddresses": [
|
||||
{
|
||||
"id": 1,
|
||||
"city": "fsdfcsdfcs",
|
||||
"countryName": "fsdfcsdfcs",
|
||||
"detailedAddress": "sdfcsvfsdf, fdfvds, fdfvds",
|
||||
"zipCode": "323232"
|
||||
}
|
||||
]
|
||||
}
|
||||
}));
|
||||
// refreshToken = response.data.refreshToken;
|
||||
// startRefreshTimer(dispatch, serverTime);
|
||||
|
||||
@@ -33,18 +33,41 @@ const generateOptions = (orderProjects) => {
|
||||
export const getOrderProjects = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestOrderProjects());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orderProjects/api/getOrderProjects`
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
const orderProjects = generateOptions(response.data);
|
||||
dispatch(recieveOrderProjects(orderProjects));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
|
||||
dispatch(recieveOrderProjects(generateOptions([
|
||||
{
|
||||
"idProject": 1,
|
||||
"projectName": "Innovation Center",
|
||||
"isAvailable": 1
|
||||
},
|
||||
{
|
||||
"idProject": 2,
|
||||
"projectName": "Demo01",
|
||||
"isAvailable": 1
|
||||
},
|
||||
{
|
||||
"idProject": 3,
|
||||
"projectName": "Kontorsrådet",
|
||||
"isAvailable": 1
|
||||
},
|
||||
{
|
||||
"idProject": 4,
|
||||
"projectName": "PerProj01",
|
||||
"isAvailable": 1
|
||||
}
|
||||
])));
|
||||
// return htmlClient.fetch({
|
||||
// url: `${API_SERVER}/orderProjects/api/getOrderProjects`
|
||||
// })
|
||||
// .then(response => {
|
||||
// if (response.data) {
|
||||
// const orderProjects = generateOptions(response.data);
|
||||
// dispatch(recieveOrderProjects(orderProjects));
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// htmlClient.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,19 +29,49 @@ export const recieveProfileInfo = (json) => ({
|
||||
export const fetchProfileInfo = (idUser) => {
|
||||
return dispatch => {
|
||||
dispatch(requestProfileInfo());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/getProfileInfo`,
|
||||
method: 'post',
|
||||
data: {idUser}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data){
|
||||
dispatch(recieveProfileInfo(response.data));
|
||||
|
||||
dispatch(recieveProfileInfo({
|
||||
"id": 2,
|
||||
"name": "Customer User",
|
||||
"mail": "customer@mail.com",
|
||||
"phone": "",
|
||||
"userType": "customer",
|
||||
"vatCode": "556084-6783",
|
||||
"companyName": "Coor Service Management AB",
|
||||
"billingAddresses": [
|
||||
{
|
||||
"id": 1,
|
||||
"city": "Göteborg",
|
||||
"countryName": "SE",
|
||||
"detailedAddress": "Lilla Bommen 2",
|
||||
"firstName": "Customer",
|
||||
"lastName": "User",
|
||||
"zipCode": "12323"
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
],
|
||||
"profileAddresses": [
|
||||
{
|
||||
"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-info`,
|
||||
// method: 'get',
|
||||
// data: {idUser}
|
||||
// })
|
||||
// .then(response => {
|
||||
// if(response.data){
|
||||
// dispatch(recieveProfileInfo(response.data));
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// client.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -107,17 +137,32 @@ const recieveCountries = (json) => ({
|
||||
export const fetchCountries = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestCountries());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/getCoutnries`,
|
||||
method: 'get'
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data){
|
||||
dispatch(recieveCountries(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
|
||||
dispatch(recieveCountries([
|
||||
{
|
||||
"idCountry": 3,
|
||||
"countryName": "Denmark"
|
||||
},
|
||||
{
|
||||
"idCountry": 4,
|
||||
"countryName": "Finland"
|
||||
},
|
||||
{
|
||||
"idCountry": 2,
|
||||
"countryName": "Sweden"
|
||||
}
|
||||
]));
|
||||
// return client.fetch({
|
||||
// url: `${API_SERVER}/profileSettings/api/getCoutnries`,
|
||||
// method: 'get'
|
||||
// })
|
||||
// .then(response => {
|
||||
// if(response.data){
|
||||
// dispatch(recieveCountries(response.data));
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// client.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user