public function WishlistAssignment::assign in Commerce Wishlist 8.3
Assigns the anonymous wishlist to the given user account.
Parameters
\Drupal\commerce_wishlist\Entity\WishlistInterface $wishlist: The wishlist wishlist.
\Drupal\user\UserInterface $account: The user account.
Overrides WishlistAssignmentInterface::assign
1 call to WishlistAssignment::assign()
- WishlistAssignment::assignMultiple in src/
WishlistAssignment.php - Assigns multiple anonymous wishlists to the given user account.
File
- src/
WishlistAssignment.php, line 68
Class
- WishlistAssignment
- Default wishlist assignment implementation.
Namespace
Drupal\commerce_wishlistCode
public function assign(WishlistInterface $wishlist, UserInterface $account) {
if (!empty($wishlist
->getOwnerId())) {
// Skip wishlists which already have an owner.
return;
}
$wishlist
->setOwner($account);
// Update the referenced shipping profile.
$shipping_profile = $wishlist
->getShippingProfile();
if ($shipping_profile && empty($shipping_profile
->getOwnerId())) {
$shipping_profile
->setOwner($account);
$shipping_profile
->save();
}
// Notify other modules.
$event = new WishlistAssignEvent($wishlist, $account);
$this->eventDispatcher
->dispatch(WishlistEvents::WISHLIST_ASSIGN, $event);
$wishlist
->save();
}