final class WishlistPurchase in Commerce Wishlist 8.3
Provides a value object for wishlist purchases.
Hierarchy
- class \Drupal\commerce_wishlist\WishlistPurchase
Expanded class hierarchy of WishlistPurchase
7 files declare their use of WishlistPurchase
- WishlistItem.php in src/
Entity/ WishlistItem.php - WishlistItemInterface.php in src/
Entity/ WishlistItemInterface.php - WishlistItemTest.php in tests/
src/ Kernel/ Entity/ WishlistItemTest.php - WishlistPurchaseItem.php in src/
Plugin/ Field/ FieldType/ WishlistPurchaseItem.php - WishlistPurchaseItemList.php in src/
Plugin/ Field/ FieldType/ WishlistPurchaseItemList.php
File
- src/
WishlistPurchase.php, line 8
Namespace
Drupal\commerce_wishlistView source
final class WishlistPurchase {
/**
* The order ID.
*
* @var int
*/
protected $orderId;
/**
* The quantity.
*
* @var string
*/
protected $quantity;
/**
* The purchased timestamp.
*
* @var int
*/
protected $purchased;
/**
* Constructs a new WishlistPurchase object.
*
* @param int $order_id
* The order id.
* @param string $quantity
* The quantity.
* @param int $purchased
* The purchased timestamp.
*/
public function __construct($order_id, $quantity, $purchased) {
$this->orderId = $order_id;
$this->quantity = $quantity;
$this->purchased = $purchased;
}
/**
* Creates a new purchase from the given array.
*
* @param array $purchase
* The purchase array, with the "order_id", "quantity" and "purchased" keys.
*
* @return static
*/
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']);
}
/**
* Gets the order ID.
*
* @return int
* The order ID.
*/
public function getOrderId() {
return $this->orderId;
}
/**
* Gets the quantity.
*
* @return string
* The quantity.
*/
public function getQuantity() {
return $this->quantity;
}
/**
* Gets the purchased timestamp.
*
* @return int
* The purchased timestamp.
*/
public function getPurchasedTime() {
return $this->purchased;
}
/**
* Gets the array representation of the purchase.
*
* @return array
* The array representation of the purchase.
*/
public function toArray() {
return [
'order_id' => $this->orderId,
'quantity' => $this->quantity,
'purchased' => $this->purchased,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WishlistPurchase:: |
protected | property | The order ID. | |
WishlistPurchase:: |
protected | property | The purchased timestamp. | |
WishlistPurchase:: |
protected | property | The quantity. | |
WishlistPurchase:: |
public static | function | Creates a new purchase from the given array. | |
WishlistPurchase:: |
public | function | Gets the order ID. | |
WishlistPurchase:: |
public | function | Gets the purchased timestamp. | |
WishlistPurchase:: |
public | function | Gets the quantity. | |
WishlistPurchase:: |
public | function | Gets the array representation of the purchase. | |
WishlistPurchase:: |
public | function | Constructs a new WishlistPurchase object. |