public static function WishlistPurchase::fromArray in Commerce Wishlist 8.3
Creates a new purchase from the given array.
Parameters
array $purchase: The purchase array, with the "order_id", "quantity" and "purchased" keys.
Return value
static
2 calls to WishlistPurchase::fromArray()
- WishlistPurchaseTest::testCreateFromInvalidArray in tests/
src/ Unit/ WishlistPurchaseTest.php - Tests creating a purchase from an invalid array.
- WishlistPurchaseTest::testCreateFromValidArray in tests/
src/ Unit/ WishlistPurchaseTest.php - Tests creating a purchase from a valid array.
File
- src/
WishlistPurchase.php, line 55
Class
- WishlistPurchase
- Provides a value object for wishlist purchases.
Namespace
Drupal\commerce_wishlistCode
public static function fromArray(array $purchase) {
if (!isset($purchase['order_id'], $purchase['quantity'], $purchase['purchased'])) {
throw new \InvalidArgumentException('WishlistPurchase::fromArray() called with a malformed array.');
}
return new static($purchase['order_id'], $purchase['quantity'], $purchase['purchased']);
}