protected function MoveToCart::isValid in Commerce Wishlist 8.3
Checks, if the given wishlist item is still valid.
The underlying purchasable entity could have been deleted or disabled in the meantime. In this case, we won't show the move/copy to cart action at all.
Parameters
\Drupal\commerce_wishlist\Entity\WishlistItemInterface $wishlist_item: The wishlist item.
Return value
bool TRUE, if the given wishlist item is valid, FALSE otherwise.
1 call to MoveToCart::isValid()
- MoveToCart::viewsForm in src/
Plugin/ views/ field/ MoveToCart.php - Form constructor for the views form.
File
- src/
Plugin/ views/ field/ MoveToCart.php, line 255
Class
- MoveToCart
- Defines a form element for moving or copying the wishlist item to the cart.
Namespace
Drupal\commerce_wishlist\Plugin\views\fieldCode
protected function isValid(WishlistItemInterface $wishlist_item) {
$purchasable_entity = $wishlist_item
->getPurchasableEntity();
$valid = FALSE;
// Check the deprecated ::isActive method.
if ($purchasable_entity instanceof ProductVariationInterface) {
$valid = $purchasable_entity
->isActive();
}
elseif ($purchasable_entity instanceof EntityPublishedInterface) {
$valid = $purchasable_entity
->isPublished();
}
if ($valid) {
try {
$this
->selectStore($wishlist_item
->getPurchasableEntity());
} catch (\Exception $e) {
$valid = FALSE;
}
}
return $valid;
}