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

Add Timestamp to Cart Instance #320

Open
dayhaysoos opened this issue Apr 23, 2023 · 0 comments
Open

Add Timestamp to Cart Instance #320

dayhaysoos opened this issue Apr 23, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@dayhaysoos
Copy link
Owner

Disclaimer

This issue was written by ChatGPT lol

Feature Proposal: Add Time Stamps to Cart Entries

Overview

Currently, there's no way to make changes or updates to the cart based on time. This proposal suggests adding time stamps to cart entries, enabling updates based on time. Time stamps should be created for every cart and turned on by default.

Implementation

The time stamp should be created in the Entry.js file located in the core folder. The createEntry function is the ideal location for creating the time stamp.

Here's what the createEntry function currently looks like:

export function createEntry({
  state,
  id,
  product,
  count,
  price_metadata,
  product_metadata
}) {
  const entry = Entry({
    id,
    product,
    quantity: count,
    price_metadata,
    product_metadata
  })

  state.cartDetails[id] = entry
  updateFormattedValue(state, id)
  updateFormattedPrice(state, id)

  state.totalPrice += entry.value
  state.cartCount += count
  updateFormattedTotalPrice(state)
}

To add the time stamp, we can simply modify the createEntry function to include the current time:

import { formatISO } from 'date-fns'

export function createEntry({
  state,
  id,
  product,
  count,
  price_metadata,
  product_metadata
}) {
  const entry = Entry({
    id,
    product,
    quantity: count,
    price_metadata,
    product_metadata,
    timeStamp: formatISO(new Date()) // Add the time stamp here
  })

  state.cartDetails[id] = entry
  updateFormattedValue(state, id)
  updateFormattedPrice(state, id)

  state.totalPrice += entry.value
  state.cartCount += count
  updateFormattedTotalPrice(state)
}

Future Expansion

This proposal focuses on adding time stamps to cart entries as an initial step. We can expand on time-oriented features in the future based on the requirements and use cases.

Feel free to modify the content as needed, but this structure should give you a clear and concise proposal for adding time stamps to the cart entries in the use-shopping-cart library. Good luck!

@dayhaysoos dayhaysoos added the enhancement New feature or request label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant