Repeater from a member's Order Collection

My site is for eLearning modules, so I’d like members to be able to purchase courses from the store, then have these orders appear in a repeater on a member’s dynamic page. I know the “My Orders” page allows this, but I want the data to appear in a repeater that can be more customised than the “My Orders” page (ie. links to course once purchased). The “Stores/Orders” collection permissions are admin only so I’m trying to query the orders by buyerInfo then insert the buyer ID and purchased course into another collection called “Courses”. Here’s my code below, but the data from the “Stores/Orders” collection isn’t appearing in the “Courses” collection.

import wixData from 'wix-data';
import wixStores from 'wix-stores';
import wixUsers from 'wix-users';

let user = wixUsers.currentUser;
let userId = user.id;

$w.onReady(function () {
  wixData.query("Stores/Orders")
  .eq("user",userId)
  .find()
  .then( (results) => {
 let usersCourseName = results.lineItems.name
 let toInsert = {
 "baristaBasics": usersCourseName
    }
    wixData.insert("Courses", toInsert)
  })
});
1 Like

Hey,
So there is no “user” field in the Stores/Orders database collection. To get the user’s ID, you can use the “buyerInfo.id” field.

.eq("buyerInfo.id",userId)

The results of the query are an array of items because each user can have multiple orders. And “lineItems” is an array of objects because you can have more than 1 line item in an order. If you want to get the name of the first line item in the first order by the current user, you can use the following code:

 let usersCourseName = results.items[0].lineItems[0].name;

HTH,
Tova

Hi @jamesogilvie , I’m trying to implement something nearly identical with my site. Did you get a working solution?