public function CartStorageSelect::__construct in Basic cart 8.4
Same name and namespace in other branches
- 8.6 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
- 8 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
- 8.0 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
- 8.2 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
- 8.3 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect::__construct()
- 8.5 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_cartCode
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;
}
}