reseller to customer
This commit is contained in:
@@ -42,7 +42,7 @@ export const fetchPackageDetails = (params) => {
|
||||
return dispatch => {
|
||||
dispatch(requestPackageDetails());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}`,
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}?cl_id=${params.shopId}`,
|
||||
method: 'get'
|
||||
})
|
||||
.then(response => {
|
||||
@@ -127,7 +127,8 @@ export const addToCart = (addParams) => {
|
||||
'package_id': addParams.selectedPackage.id,
|
||||
'price_id': addParams.selectedAgreement.idPrice,
|
||||
'addons_ids': result.additionalPackages,
|
||||
'options_ids': result.optionPackages
|
||||
'options_ids': result.optionPackages,
|
||||
'cl_id': addParams.shopId,
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
|
||||
@@ -5,9 +5,9 @@ import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_SHOP_PACKAGES,
|
||||
RECIEVE_SHOP_PACKAGES,
|
||||
REQUEST_SHOP_COMMERCIAL_LEADS,
|
||||
RECIEVE_SHOP_COMMERCIAL_LEADS,
|
||||
SELECT_SHOP_COMMERCIAL_LEAD
|
||||
REQUEST_SHOPS,
|
||||
RECEIVE_SHOPS,
|
||||
SELECT_SHOP
|
||||
} from '../../constants/coMarketConstants';
|
||||
import { fromWCPackage } from '../../helpers/PackageHelper';
|
||||
|
||||
@@ -23,13 +23,13 @@ const recieveShopPackages = (json) => ({
|
||||
shopPackages: json
|
||||
});
|
||||
|
||||
export const fetchShopPackages = (cl, search) => {
|
||||
export const fetchShopPackages = (shop, search) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopPackages());
|
||||
let searchParam = search ? '?search=' +search : ''
|
||||
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${cl.idCommercialLead}` + searchParam,
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${shop.id}` + searchParam,
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
@@ -42,41 +42,38 @@ export const fetchShopPackages = (cl, search) => {
|
||||
}
|
||||
}
|
||||
|
||||
const requestShopCommercialLeads = () => ({
|
||||
type: REQUEST_SHOP_COMMERCIAL_LEADS
|
||||
const requestShops = () => ({
|
||||
type: REQUEST_SHOPS
|
||||
});
|
||||
const recieveShopCommercialLeads = (json) => ({
|
||||
type: RECIEVE_SHOP_COMMERCIAL_LEADS,
|
||||
commercialLeads: json
|
||||
const receiveShops = (json) => ({
|
||||
type: RECEIVE_SHOPS,
|
||||
shops: json
|
||||
});
|
||||
|
||||
const generateClOptions = (commercialLeads) => {
|
||||
commercialLeads.forEach((cl) => {
|
||||
cl.value = cl.idCommercialLead;
|
||||
cl.label = cl.commercialLeadName;
|
||||
const generateShopOptions = (shops) => {
|
||||
shops.forEach((shop) => {
|
||||
shop.value = shop.id;
|
||||
shop.label = shop.name;
|
||||
});
|
||||
|
||||
return commercialLeads;
|
||||
return shops;
|
||||
}
|
||||
|
||||
export const fetchShopCommercialLeads = () => {
|
||||
export const fetchShops = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCommercialLeads());
|
||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/commercial-leads` })
|
||||
dispatch(requestShops());
|
||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/customer/0/shops` })
|
||||
.then(response => {
|
||||
|
||||
if(response.data){
|
||||
|
||||
const clOptions = generateClOptions(response.data.map(cl => ({
|
||||
idCommercialLead: cl.id,
|
||||
commercialLeadName: cl.name
|
||||
})));
|
||||
const shopOptions = generateShopOptions(response.data);
|
||||
|
||||
dispatch(recieveShopCommercialLeads(clOptions));
|
||||
dispatch(receiveShops(shopOptions));
|
||||
|
||||
if (clOptions.length) {
|
||||
dispatch(selectCommercialLead(clOptions[0]));
|
||||
dispatch(fetchShopPackages(clOptions[0]));
|
||||
if (shopOptions.length) {
|
||||
dispatch(selectShop(shopOptions[0]));
|
||||
dispatch(fetchShopPackages(shopOptions[0]));
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -86,7 +83,7 @@ export const fetchShopCommercialLeads = () => {
|
||||
}
|
||||
}
|
||||
|
||||
export const selectCommercialLead = (cl) => ({
|
||||
type: SELECT_SHOP_COMMERCIAL_LEAD,
|
||||
selectedCommercialLead: cl
|
||||
export const selectShop = (shopInfo) => ({
|
||||
type: SELECT_SHOP,
|
||||
selectedShop: shopInfo
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user