How to also return the `slug` field from the Paid Plans dataset using `getCurrentMemberOrders`

Hi community,

Maybe someone has a creative solution, but otherwise this is more of a feature request for the good people of Wix: the getCurrentMemberOrders functions returns about all the fields in the paid plans dataset, except for, unfortunately, the slug field. Many situations including mine need this information if you want to list and link all the relevant of the user’s paid for plans in a sort-off ‘my plans’ overview, as I’ve built here using a repeater:

$w.onReady(function () {
    $w("#userPlansRepeater").onItemReady(($item, itemData) => {
        $item("#planTitleText").text = itemData.planName;
        $item("#planTaglineText").text = itemData.planDescription;
        // The part that's not working now because there is no `itemData.slug`:
        // $item("#planButton").link = "/" + itemData.slug;
    });

    wixPaidPlans.getCurrentMemberOrders().then(userOrders => {
        $w("#userPlansRepeater").data = userOrders.map(order => { return { ...order, _id: order.planId } });
    });
});

Two ways around this: 1) building the repeater using the paidplans dataset directly, but then I’d have to filter out (in the front-end) plans the user didn’t buy yet, or 2) adding an onClick event to the planButton which fetches the slug from the paidplans dataset using its ID, 3) get all the slugs beforehand from the paid plans dataset (I guess I’ll end up doing that for now). However, it’d be ideal (and expected) if wixPaidPlans.getCurrentMemberOrders() would also just return the slug, we’d only need one look-up in that case. Maybe someone knows another, better solution, or maybe someone from Wix could add this feature or explain why the slug is left out.

Kind regards,

Henk

1 Like

Hey Henk,
You can use wixData to query or get the items from the ‘plans’ collection,
You also get the ‘slug’ of the item in the results.

This is one of the solutions:

$w.onReady(function () {
    $w("#userPlansRepeater").onItemReady(($item, itemData) => {
        $item("#planTitleText").text = itemData.planName;
        $item("#planTaglineText").text = itemData.planDescription;

wixData.get('PaidPlans/Plans', itemData._id).then(item =>{ let slug = item.slug  
})

      
    });

    wixPaidPlans.getCurrentMemberOrders().then(userOrders => {
        $w("#userPlansRepeater").data = userOrders.map(order => { return { ...order, _id: order.planId } });
    });
});

Best

Binyamin

Hi Binyamin,

Thanks for your message! This is indeed a solution, but the downside is that then for each plan you’d have to do a database look-up. So if the user signed up for a 100 plans, you’d have a 100 extra requests going from the client to the server. I’d sooner go for my solution number 3, which would be just one extra request.

@hbierlee
In this case, it’s better to work with wixData.query instead of data binding with the dataset.

So, I ended up solving it with basically solution 3:

import wixData from 'wix-data';
import wixPaidPlans from 'wix-paid-plans';

$w.onReady(function () {
    // Get a list of the current member's plans
    wixPaidPlans.getCurrentMemberOrders().then(async userOrders => {
        // Using this list, again get all plans (but with slug this time)
        const plans = await wixData.query("PaidPlans/Plans")
            .hasSome("id", userOrders.map(order => order.planId)) // only get plans of which the id is one of the user's plans!
            .find();

        // Connect the data property of the repeater to the returned plans
        $w("#userPlansRepeater").data = plans._items;
        $w("#userPlansRepeater").show("fade");
    });

    // Configure what to do with the data
    $w("#userPlansRepeater").onItemReady(($item, itemData) => {
        // This part gets executed only after the data property is set (so after we get the plans above)
        // `itemData` holds the information we put in, namely `plans._items`, for each item of the repeater
        $item("#planTitleText").text = itemData.name; // set the text of the text element equal to the na
        $item("#planTaglineText").text = itemData.tagline;

        // slug is the link to the plan's page
        $item("#planModulesButton").link = "/account/" + itemData.slug;
    });
});

This is fine, but like I said, takes one extra request. It would be nice if the slug property would be returned along with the rest of the plan’s data via getCurrentMemberOrder().