verbb / wishlist

A Craft CMS plugin for wishlists for your users to save things to
Other
11 stars 12 forks source link

Display Wishlist based on custom Dropdown in item #110

Closed DynamiteGoesBoom closed 1 year ago

DynamiteGoesBoom commented 1 year ago

Question

Love the plugin gang! But I'm having trouble doing something that seems sort of easy to do, at least in theory.

I have a Wishlist with Items. Each item is being used as an Application. Each application has a Progress field and a Application Status field.

I know that I can grab all of the Items in the Wishlist by doing this:

{% set allGrants = craft.wishlist.lists().one() %}

But what I can't figure out is how I can query against the values of my applicationStatus field. I tried using relatedTo in my query:

{% set allGrants = craft.wishlist.lists().one() %}

{% set inProgressGrants = allGrants.relatedTo({ 
        sourceElement: craft.wishlist.items().applicationStatus('inProgress')
    }).collect() 
%}

When doing that I get:

Calling unknown method: verbb\wishlist\elements\ListElement::relatedTo()

I'm probably over thinking this and would appreciate your insight :)

I don't think this is a bug per say so filing it under Question and hoping that's correct :)

Thanks gang!

Additional context

No response

DynamiteGoesBoom commented 1 year ago

@engram-design Do you have any ideas on how this could be accomplished?

Many thanks!

engram-design commented 1 year ago

So first thing, what sort of fields are Progress field and Application Status field? I assume these are on your List Type layout, not your entries layout (the thing that you add to your Wishlist). There's sometimes a little confusion on that front, so thought to check.

And just to also confirm, the following doesn't grab all the wishlist items, it grabs a single wishlist list.

{% set allGrants = craft.wishlist.lists().one() %}

To get all the items in that you do:

{# FYI, you probably need to get the current users' list, not just the first list #}
{% set list = craft.wishlist.lists().one() %}

{# Find all items where `applicationStatus` custom field == `inProgress` #}
{% set inProgressGrants = list.items.applicationStatus('inProgress').all() %}

The above should return all the items in that list where the custom field applicationStatus equals inProgress. Again, I don't know the type of field this is, but you should only require relatedTo if that field is an element field.

Hope that helps?

DynamiteGoesBoom commented 1 year ago

Hey@engram-design thanks for chiming in. Those two fields are just dropdown select fields. Yes I am only trying to get the active users wish list. We're attempting to use WishList as a way to organize the status of a Saved Grant. Each Grant can have an Application Status of: In progress, lost, won, or archived. So I was hoping to use that dropdown to help organize those.

If I do {% set allGrants = craft.wishlist.lists(true).one() %} {% set inProgressGrants = allGrants.items.applicationStatus('inProgress').all() %} then I don't get any items to appear with the inProgressGrants query although there is one with that option in the Dashbboard:

Screen Shot 2022-10-10 at 10 36 14 AM

is there anything else I can try?

DynamiteGoesBoom commented 1 year ago

@engram-design never mind it looks like I got it sorted out after all!

Thanks again!