Closed NullOperator404 closed 1 month ago
UPDATE 1 HOUR LATER:
The following functions have been refactored to utilize cartProds[]
as an object array:
addToCart()
trashItem()
openCheckout()
setRow()
openPreflight()
These were all the functions I could find that access cartProds[]
. From now on, the only time the program should have access the full database is when the user is adding a product or changing the current product. In such instances, the database must be accessed so that currentProd
and cartProds[]
can be updated with the corresponding data object (for use client-side).
The array
cartProds[]
currently only stores product numbers, but should be refactored to be an object array. Numerous functions must currently iterate through the product database looking for a match for a product number stored in the array. There is no need to do is; ifcartProds[]
contains the entire data object, then functions can just pull data directly from the cart instead of having to access the database every time data is needed.For example:
The above function is used to set whatever product is currently selected in the Quote panel. That is, when a user clicks to input/edit quantities, this function fires so it can assign
currentProd
the correct object data.As it's currently written, the function uses an event handler to get the ID of the clicked row ("a," for example). It then checks the
rowLabels[]
array to find out what the index of the retrieved label is. ("a" would be at index 0.) It assigns "0" toprodIdx
.After that, it uses the value of
prodIdx
to find out which product number incartProds[]
to assign touserProd
.It then iterates through the product database looking for a match to the value of
userProd
(G800, for example). When a match is found, it updatescurrentProd
with the new data object.REFACTOR PROPOSAL:
In this version,
cartProds[]
is an OBJECT ARRAY. In all instances where the user adds/edits a product in their shopping cart, this array will store the entire data object for that product instead of just it's product number. This way, any functions relating to shopping cart items need only read fromcartProds[]
, without needing to access the product database.A given row can always been determined using it's ID, just as
setRow()
does. Once it has the row ID, it should be able to locate the corresponding item incartProds[]
, since the cart array always updates based on what the user has selected.