You are here

public function CartStorageSelect::__construct in Basic cart 8.5

Same name and namespace in other branches
  1. 8.6 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
  2. 8 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
  3. 8.0 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
  4. 8.2 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
  5. 8.3 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
  6. 8.4 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()

Construct object using whether it is table class or session class.

Parameters

object $user: Drupal user object.

bool $use_table: Boolean to define the storage type.

File

src/CartStorageSelect.php, line 21

Class

CartStorageSelect
Class CartStorageSelect to select either db or session.

Namespace

Drupal\basic_cart

Code

public function __construct($user, $use_table = NULL) {
  $enable = $user
    ->id() && $use_table ? $user
    ->id() : 0;
  switch ($enable) {
    case 0:
      $this->cart = new CartSession($user);
      break;
    default:
      $cartStorage = new CartStorage();
      $this->cart = new CartTable($cartStorage, $user);
      break;
  }
}