You are here

final class WishlistPurchase in Commerce Wishlist 8.3

Provides a value object for wishlist purchases.

Hierarchy

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

... See full list

File

src/WishlistPurchase.php, line 8

Namespace

Drupal\commerce_wishlist
View 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

Namesort descending Modifiers Type Description Overrides
WishlistPurchase::$orderId protected property The order ID.
WishlistPurchase::$purchased protected property The purchased timestamp.
WishlistPurchase::$quantity protected property The quantity.
WishlistPurchase::fromArray public static function Creates a new purchase from the given array.
WishlistPurchase::getOrderId public function Gets the order ID.
WishlistPurchase::getPurchasedTime public function Gets the purchased timestamp.
WishlistPurchase::getQuantity public function Gets the quantity.
WishlistPurchase::toArray public function Gets the array representation of the purchase.
WishlistPurchase::__construct public function Constructs a new WishlistPurchase object.