如何将添加到Firestore购物车的商品数量限制为一个?

问题描述

我正在建立一个房地产网站。由于不可能一次购买多次房产,因此我需要限制用户可以将房产添加到购物车的次数。如图所示,我一直在尝试在Firestore中定位propertyID。

此外,在“操作”或“简化程序”中,执行此操作的逻辑应该在哪里?我在动作中尝试过Firestore.where(),还尝试将逻辑放入化简器中。

Picture of Firestore tree

   const propertyReducer = (state = initState,action,{ cart }) => {
  switch (action.type) {
    case "ADD_TO_CART": //ListingDetail
      console.log("property cart added",action.payload);
      console.log(state);

  const index = cart.findindex((item) => item.propertyID === action.id);
  
  if (index >= 0) {
    state.error = "This property is alread in your cart";
  }

  return {
    ...state,};

case "ADD_TO_CART_ERROR":
  console.log("CART_ADDED_ERROR",action.err);
  let error = state.error;

  return {
    ...state,error,};

case "REMOVE_FROM_CART": //ListingCheckout
  console.log("REMOVE_FROM_CART",action.payload);

  return {
    ...state,};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)