Handle commercial lead prices
This commit is contained in:
@@ -27,15 +27,9 @@ export const fetchShopPackages = (cl, search) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopPackages());
|
||||
let searchParam = search ? '?search=' +search : ''
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products` + searchParam,
|
||||
// TODO: Add comercialLead parameter after the support for it is added on backend
|
||||
|
||||
// method: 'post',
|
||||
// data: {
|
||||
// idCommercialLead: (cl && cl.value) || 0,
|
||||
// search
|
||||
// }
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${cl.idCommercialLead}` + searchParam,
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
@@ -68,23 +62,29 @@ const generateClOptions = (commercialLeads) => {
|
||||
export const fetchShopCommercialLeads = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCommercialLeads());
|
||||
// TODO: FetchcomercialLead after the support for it is added on backend
|
||||
// return client.fetch({url: `${API_SERVER}/coMarket/api/getAllCommercialLeads`})
|
||||
// .then(response => {
|
||||
// if(response.data && response.data.commercialLeads){
|
||||
const clOptions = generateClOptions([{ "idCommercialLead": 14, "commercialLeadName": "Coor Service Management", "mail": "rikard@co-ideation.com" }]);
|
||||
dispatch(recieveShopCommercialLeads(clOptions));
|
||||
if (clOptions.length) {
|
||||
dispatch(selectCommercialLead(clOptions[0]));
|
||||
dispatch(fetchShopPackages(clOptions[0]));
|
||||
}
|
||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/commercial-leads` })
|
||||
.then(response => {
|
||||
|
||||
if(response.data){
|
||||
|
||||
const clOptions = generateClOptions(response.data.map(cl => ({
|
||||
idCommercialLead: cl.id,
|
||||
commercialLeadName: cl.name
|
||||
})));
|
||||
|
||||
dispatch(recieveShopCommercialLeads(clOptions));
|
||||
|
||||
if (clOptions.length) {
|
||||
dispatch(selectCommercialLead(clOptions[0]));
|
||||
dispatch(fetchShopPackages(clOptions[0]));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
// })
|
||||
// .catch(error => {
|
||||
// client.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
// }
|
||||
|
||||
export const selectCommercialLead = (cl) => ({
|
||||
type: SELECT_SHOP_COMMERCIAL_LEAD,
|
||||
|
||||
Reference in New Issue
Block a user