Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADCIO-2907) feat: pub-sub add-to-cart #38

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

hanchchch
Copy link
Contributor

✅ Jira Ticket Number

ADCIO-2907

♻️ Current situation

  • 장바구니를 감지하는 방법이 부자연스럽습니다.
    • 페이지 로드(이동) 시 마다 고객의 전체 장바구니를 불러옵니다.
    • 불러온 장바구니를 로컬스토리지에 저장된 장바구니와 비교합니다.
    • 새로 추가된 장바구니가 있다면 로그를 쏩니다.
    • 장바구니를 로컬스토리지에 저장합니다.
  • 이 방식은 문제가 있습니다.
    • 장바구니 추가 후 페이지 이동이 없으면 수집되지 않습니다.
    • stateful 하기 때문에, 코드 구조와 테스트가 복잡합니다.
    • cafe24 api로 불러오는 장바구니 데이터에는 카테고리 정보가 없습니다.

💡 Proposed solution

  • 장바구니를 추가하는 순간을 detect 합니다.
  • 장바구니 이벤트를 전반적으로 pub-sub 구조로 리팩토링합니다.
    • 자체 구축 스토어 개발자는, new AddToCartEvent(cart).dispatch() 같은 방법으로 간단하게 카트 이벤트를 pub합니다.
    • cafe24 클라이언트는 자동으로 장바구니가 감지됩니다.
      • 장바구니 추가 시 실행되는 action_basket 함수를 wrapping 했습니다.
      • 해당 함수가 콜될 때, AddToCartEvent를 dispatch 하도록 작업해두었습니다.

⚙️ Release Notes

➕ Additional Information

  • 문제
    • cafe24에서 action_basket 함수 관련 수정이 있을 경우, 장바구니 수집에 문제가 생길 수 있습니다.
  • 향후
    • impression / click / view / purchase 다른 이벤트도 이러한 구조로 리팩토링을 생각 중입니다.

🧪 Testing

🧑‍💻 Reviewer Nudging

✅ Checklist

📚 TODO

@hanchchch hanchchch added the feature request Request to add new functions label Mar 20, 2024
@hanchchch hanchchch self-assigned this Mar 20, 2024
NaGyeong-Park
NaGyeong-Park previously approved these changes Mar 25, 2024
Comment on lines +41 to +44
const data = decodeURI(arg)
.split("&")
.reduce((acc, cur) => {
const [key, value] = cur.split("=");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL 객체써서 요렇게 파싱하는건 어떠세요

const data = new URL(arg);
Object.fromEntries(data.searchParams)

@@ -102,6 +99,7 @@ export class Cafe24API implements ClientAPI {
id: order_id,
products: order_product.map((product) => ({
idOnStore: `${product.product_no}`,
// categoryIdOnStore: `${product.category_no_1}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 여기가 주석처리된 이유가 있을까요? 주석처리된 상태로 남겨둔다면, 간단히 이유를 남겨줘도 좋을 듯 해요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우리가 원하는 카테고리(구매 플로우에서 처음에 접근한 상품분류 페이지)가 맞는지 확실하지 않아서 주석처리했습니다.
테스트해보고 주석 유지 여부 결정할게요. 아무래도 구매다보니 테스트가 쉽지 않네요 ..ㅎㅎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request to add new functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants