verbb / events

Craft CMS Plugin for events management and ticketing.
Other
21 stars 12 forks source link

Possible to Query purchased tickets with User data on Craft 4? #119

Closed Gs-Joel closed 1 year ago

Gs-Joel commented 1 year ago

Question

I have a similar question to #71.

I'm in the middle of upgrading a site to Craft 4 and the site uses the Element API plugin to serve some data.

We were using

$customer = Plugin::getInstance()->getCustomers()->getCustomerByUserId($user->id);
$purchasedTickets = PurchasedTicket::find()->customer($customer);

but the function getCustomerByUserId() was removed in Craft Commerce 4 as Customers were made into Users. However when trying to pass User data I get the following error.

2023-02-09 10:04:30 [web.ERROR] [craft\elementapi\controllers\DefaultController::actionIndex] Error resolving Element API endpoint: verbb\events\elements\db\PurchasedTicketQuery::customer(): Argument #1 ($value) must be of type ?craft\commerce\models\Customer, craft\elements\User given, called in /Users/joel/Websites/parenting-place/config/element-api.php on line 36 {"memory":10949336} 

The FE templating documentation hasn't been updated between v1 and v2 so I wanted to check that this was even still possible in Craft 4.

thanks in advance

Additional context

No response

engram-design commented 1 year ago

Using customer() as an element query is still possible (although just fixed some minor typing), but instead of a Commerce customer, it's just a Craft user. I've updated the docs to reflect this.

You'll want to adjust that to:

$purchasedTickets = PurchasedTicket::find()->customer($user);

To get the fix early, change your verbb/events requirement in composer.json to:

"require": {
  "verbb/events": "dev-craft-4 as 2.0.0-beta.8",
  "...": "..."
}

Then run composer update.

Gs-Joel commented 1 year ago

Thanks so much for the update. That query is now working on my end with the User object.