You are here

protected function WishlistManager::matchWishlistItem in Commerce Wishlist 8.3

Finds a matching wishlist item for the given one.

Parameters

\Drupal\commerce_wishlist\Entity\WishlistItemInterface $wishlist_item: The wishlist item.

\Drupal\commerce_wishlist\Entity\WishlistItemInterface[] $wishlist_items: The wishlist items to match against.

Return value

\Drupal\commerce_wishlist\Entity\WishlistItemInterface|null A matching wishlist item, or NULL if none was found.

1 call to WishlistManager::matchWishlistItem()
WishlistManager::addEntity in src/WishlistManager.php
Adds the given purchasable entity to the given wishlist entity.

File

src/WishlistManager.php, line 140

Class

WishlistManager
Default implementation of the wishlist manager.

Namespace

Drupal\commerce_wishlist

Code

protected function matchWishlistItem(WishlistItemInterface $wishlist_item, array $wishlist_items) {
  $matching_wishlist_item = NULL;
  foreach ($wishlist_items as $existing_wishlist_item) {
    if ($existing_wishlist_item
      ->bundle() != $wishlist_item
      ->bundle()) {
      continue;
    }
    if ($existing_wishlist_item
      ->getPurchasableEntityId() != $wishlist_item
      ->getPurchasableEntityId()) {
      continue;
    }
    $matching_wishlist_item = $existing_wishlist_item;
    break;
  }
  return $matching_wishlist_item;
}