nss-evening-cohort-11 / WildflowerCoffeeGifts

0 stars 2 forks source link

PURCH 1A - Customer can create a new order for their Shopping Cart #93

Closed ancasimon closed 3 years ago

ancasimon commented 3 years ago

User Story 1

Given the customer is on a product detail page When clicking on an add to cart button Then a new order gets created with a line item for that product.

User Story 2

Given the customer is on the Shopping Cart page When clicking on the Start Shopping button Then a new order gets created.

Logic:

  1. We are assuming there is no active pending (aka incomplete) order for the user logged it, so we create a new order when the user clicks Start Shopping on the Shopping Cart page OR when the user clicks Add to Cart on a single product view page.
  2. Shopping Cart page > When the user clicks Start Shopping, we create the order record for the cart and display the basic order data. To do that, we also need to a paymentType record - we can get the latest payment type added for the user OR - if none available - we will create a new payment type record with some default data as the PaymentOption and the DeliveryAddress, which are required fields.
  3. Since the user may start their cart NOT by clicking on the Cart page BUT by clicking Add to Cart on a single product view page > When the user clicks Add To Cart > we create the new order record - like in the scenario above, to do that, we also need to a paymentType record - so we can get the latest payment type added for the user OR - if none available - we will create a new payment type record - last, we will create a new ProductOrder record for the product the user clicks Add to Cart on!

Dev Notes:

SQL

  1. Orders table > PurchaseDate column > Update it so that it gets set automatically by the database when a new order gets created.
  2. PaymentTypes table > PaymentOption column > Update it to accept 50 characters instead of just 25 - to accommodate the default text we are adding.
  3. Write the query to get the latest active payment type record for a user (with the highest ID) to use in the API.
  4. Write insert statement to create a new payment type record.

API:

  1. Write a new CreateShoppingCart method in the OrderRepository file. This method: -1-gets the latest payment type record for a user (see SQL section above); -2-if one isn't found, it creates a new payment type record (see insert statement from SQL section above) - define the default data for all parameters except the userId - which uses the userId we are passing in to this method; -3- creates a new order record using the payment ID found or created above, the userId passed in and some additional default data
  2. Write the corresponding HttpGet method in the OrdersController - create a new URL for it to distinguish it from getting a single order by id, which already exists. We are starting this process with the userID so the url can use the userId that is getting passed in.

React app:

  1. In the ordersData.js file : write the createCart function, which takes in a userID, that uses the URL / data from the CreateShoppingCart method in the API.
  2. ShoppingCart.js file: Set the userId in state; Write the createCart function, which calls the function with the same name in the data file.
  3. In the SingleProductView.js file: -1-Declare the userId, cart, lineItems in state; -2-write the addToCart function, which calls the createCart function in the ordersData.js file; -3- in the then(), this function also creates a ProductOrder record - SHOULD I MOVE THIS TO THE BACKEND?? AND PASS THE PRODUCT ID AS A PARAMETER???; -4-send the user to the Cart page after adding this product by including this.props.history.push('/cart'); in thethen()of this last Promise; -5- in the Add to Cart button in this component, add theonClick` event handler which calls the new addToCart function we just wrote.
ancasimon commented 3 years ago

2 Prerequisites for this ticket - We all need to make these updates in our database:

  1. In our WCG database > Orders table > Design > PurchaseDate column > Column Properties section at the bottom > Default value row > Set it to be populated by default with the current date - as in the screenshot below.
  2. In our WCG database > PaymentTypes table > Design > PaymentOption column > Extend the length to 50. See screenshot below.

1 - WCG database > Orders table > Design > PurchaseDate column: orders_purchasedate_default

2 - WCG database > PaymentTypes table > Design > PaymentOption column: WCG_changePaymentTypeLength to 50

ancasimon commented 3 years ago

To create additional users:

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('felix.jordan@gmail.com', 'Felix', 'Jordan', 'felix.jordan@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('georgia.knox@gmail.com', 'Georgia', 'Knox', 'georgia.knox@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('maria.paxton@gmail.com', 'Maria', 'Paxton', 'maria.paxton@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('jonathan.mcknight@gmail.com', 'Jonathan', 'McKnight', 'jonathan.mcknight@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('tony.pizzicato@gmail.com', 'Tony', 'Pizzicato', 'tony.pizzicato@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('angela.andantino@gmail.com', 'Angela', 'Andantino', 'angela.andantino@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('theresa.fiorelli@gmail.com', 'Theresa', 'Fiorelli', 'theresa.fiorelli@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('fred.allegro@gmail.com', 'Fred', 'Allegro', 'fred.allegro@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('jeremy.ritardando@gmail.com', 'Jeremy', 'Ritardando', 'jeremy.ritardando@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('martin.nelson@gmail.com', 'Martin', 'Nelson', 'martin.nelson@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('arthur.coal@gmail.com', 'Arthur', 'Coal', 'arthur.coal@gmail.com', '2020', 'password123', 1)

** 11/14 UPDATE - more users:

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('sylvan.mcwheeler@gmail.com', 'Sylvan', 'McWheeler', 'sylvan.mcwheeler@gmail.com', '2020', 'password123', 1)

insert into Users(username, firstName, lastName,email,dateCreated,password,IsActive)
values('stephanie.plum@gmail.com', 'Stephanie', 'Plum', 'stephanie.plum@gmail.com', '2020', 'password123', 1)

Add payment options for them - replace the placeholder text <USERIDHERE!!!!> with the ID of the new users above - REPEAT this script at least 2 times, for 2 of the users created above - so you can use them in the second part in the PR testing steps!

insert into PaymentTypes(PaymentOption, UserId, AccountNo,ExpirationYear,ExpirationMonth,IsActive)
values('newcard',<USERIDHERE!!!>,'10101010101',2025,12,1)