Copy collection A to collection B, on user submit button

Hi,

Thank for taking the time to read the following below. Your patience is greatly appreciated. I will do my best to explain the situation as best I can. I am open to any and all feedback to how best execute set task.

Essentially I am trying to understand how I can copy content from collection A to collection B when submit button is clicked by user (creating a shopping page for school store). Collection A will have add and deletes of records similar to adding and removing item to a shopping cart. When user wants to check out(make final purchase), then ALL the records from collection A will copy(and append) to collection B and collection A will remove all current records.

Based on other posts, I’ve concluded that I will need to build the following:

  1. Create onClick event for submit button (check out process)
  2. Event function will query ‘Collection A’ and insert query to ‘Collection B’ (not sure how to append). Collection B will Save, Collection A will refresh (or remove records) to blank.

Question #1: Is there any other building steps that I should consider when making this function?
Question #2: Will I need to make sure column names in Collection B are same as Collection A since data is copying from on collection to another? Not a problem if yes, but not sure how to create the variable placeholders (IE. CollectionA.Price = CollectionB.Price)
Question #3: How can I ensure records are appending to collectionB and not replacing (will I need to use record ID as the main field)?

(PS. I was able to use a lightbox to create a preview table of collectionA, and users can select by row and remove (delete) record from Column A if item is not wanted. This was actually easier than I thought it would be). However since there is more transactions than one per day, I want to only group them by create-date in Column B and use Column A as a ‘shopping cart’ function. Transactions will only be handled once at a time, never more than one instance at a time.

Thanks again,
Esco.

import wixData from 'wix-data';

$w.onReady(function () {});

export function finalsalebutton_click(event) {  
 function getData(){
 let query = wixData.query("Collection A");
        wixData.bulkInsert("Collection B", query)
    }   
}