Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.7 kB
1
Indexable
Never
  let cartAttributes = "";
  const aiResultList = $(".list-product").data("aiResult");
  const aiResultCookie = getCookie("aiVid").split(",");
  const didCookie = getCookie("aiDid");
  cartData.items.forEach(item => {
    if (item.properties && Object.keys(item.properties).length !== 0) {
      for (const [key, value] of Object.entries(item.properties)) {
        if (key.includes('セット商品')) {
          defineProductAI.forEach(productAi => {
            if (value.includes(productAi.title)) {
              if (aiResultList.length) {
                aiResultList.forEach(aiResult => {
                  if (aiResult.vid.includes(productAi.id)) {
                    if (cartAttributes !== '') {
                      if (!cartAttributes.includes(aiResult.did)) {
                        cartAttributes += `,${aiResult.did}`;
                      }
                    } else {
                      cartAttributes = `${aiResult.did}`;
                    }
                  }
                })
              }
              if (aiResultCookie.length) {
                aiResultCookie.forEach(cookieAI => {
                  if (+cookieAI === productAi.id) {
                    if (cartAttributes !== '') {
                      if (!cartAttributes.includes(didCookie)) {
                        cartAttributes += `,${didCookie}`;
                      }
                    } else {
                      cartAttributes = `${didCookie}`;
                    }
                  }
                })
              }
            }
          })
        }
      }
    } else {
      defineProductAI.forEach(productAi => {
        if (item.title.includes(productAi.title)) {
          if (aiResultList.length) {
            aiResultList.forEach(aiResult => {
              if (aiResult.vid.includes(productAi.id)) {
                if (cartAttributes !== '') {
                  if (!cartAttributes.includes(aiResult.did)) {
                    cartAttributes += `,${aiResult.did}`;
                  }
                } else {
                  cartAttributes = `${aiResult.did}`;
                }
              }
            })
          }
          if (aiResultCookie.length) {
            aiResultCookie.forEach(cookieAI => {
              if (+cookieAI === productAi.id) {
                if (cartAttributes !== '') {
                  if (!cartAttributes.includes(didCookie)) {
                    cartAttributes += `,${didCookie}`;
                  }
                } else {
                  cartAttributes = `${didCookie}`;
                }
              }
            })
          }
        }
      })
    }
  });