Beispiel #1
0
 return (dispatch, getState) => {
   return api.customers.deleteAddress(customerId, addressId)
   .then(customerResponse => {
       dispatch(fetchCustomer(customerId));
   })
   .catch(error => {});
 }
Beispiel #2
0
 return (dispatch, getState) => {
   return api.customers.setDefaultShippingAddress(customerId, addressId)
   .then(customerResponse => {
       dispatch(fetchCustomer(customerId));
   })
   .catch(error => {});
 }
Beispiel #3
0
 return (dispatch, getState) => {
   return api.customers.update(data.id, data)
   .then(customerResponse => {
       dispatch(receiveCustomer(customerResponse.json));
   })
   .catch(error => {});
 }
Beispiel #4
0
const fetchOrderAdditionalData = (order) => {
  const hasCustomer = order.customer_id && order.customer_id.length > 0;
  const hasShippingMethod = order.shipping_method_id && order.shipping_method_id.length > 0;
  const productIds = order && order.items && order.items.length > 0
    ? order.items.filter(item => item.product_id).map(item => item.product_id)
    : [];
  const productFilter = { ids: productIds, fields: 'images,enabled,stock_quantity,variants,options' };
  
  return Promise.all([
    productIds.length > 0 ? api.products.list(productFilter) : null,
    hasCustomer ? api.customers.retrieve(order.customer_id) : null,
    hasShippingMethod ? api.shippingMethods.retrieve(order.shipping_method_id): null
  ]).then(([
    productsResponse,
    customerResponse,
    methodResponse
  ]) => {
    if(productsResponse){
      const products = productsResponse.json.data;
      const newItems = order.items.map(item => {
        item.product = products.find(p => p.id === item.product_id);
        return item;
      })
      order.items = newItems;
    }
    order.customer = customerResponse ? customerResponse.json : null;
    order.shipping_method_details = methodResponse ? methodResponse.json : null;

    return order;
  }).catch(err => err);
}
Beispiel #5
0
  return (dispatch, getState) => {
    dispatch(requestCustomer());

    return api.customers.retrieve(customerId)
    .then(customerResponse => {
      dispatch(receiveCustomer(customerResponse.json))
    })
    .catch(error => {});
  }
Beispiel #6
0
  return (dispatch, getState) => {
    const state = getState();
    let customer = state.customers.editCustomer;

    if(customer && customer.id) {
      return api.customers.delete(customer.id)
      .catch(err => { console.log(err) });
    }
  }
Beispiel #7
0
  return (dispatch, getState) => {
    const state = getState();
    if (!state.customers.loadingItems) {
      dispatch(requestMoreCustomers());

      let filter = getFilter(state, state.customers.items.length);

      return api.customers.list(filter)
        .then(({status, json}) => {
          dispatch(receiveCustomersMore(json))
        })
        .catch(error => {
            dispatch(receiveCustomersError(error));
        });
    }
  }
Beispiel #8
0
 let promises = state.customers.selected.map(customerId => api.customers.update(customerId, { group_id: group_id }));
Beispiel #9
0
 let promises = state.customers.selected.map(customerId => api.customers.delete(customerId));