1

From this question, I tried:

$user->setAttributes(['products' => $userProductsIds]);

return Craft::$app->getElements()->saveElement($user);

Where $user is an instance of craft\elements\User; and $userProductsIds an array. It's not giving me any errors, but the user is not updated. Any idea on what am I missing?

1

By checking vendor/craftcms/cms/src/controllers/UsersController.php and vendor/craftcms/cms/src/base/Element.php, I did it like

$user->setFieldValue('products', $userProductsIds);
return Craft::$app->getElements()->saveElement($user, false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.