class CartStorageSelect in Basic cart 8.6
Same name and namespace in other branches
- 8 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect
- 8.0 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect
- 8.2 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect
- 8.3 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect
- 8.4 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect
- 8.5 src/CartStorageSelect.php \Drupal\basic_cart\CartStorageSelect
Class CartStorageSelect to select either db or session.
Hierarchy
- class \Drupal\basic_cart\CartStorageSelect
Expanded class hierarchy of CartStorageSelect
File
- src/
CartStorageSelect.php, line 8
Namespace
Drupal\basic_cartView source
class CartStorageSelect {
private $cart = NULL;
private $cartStorage;
/**
* Construct object using whether it is table class or session class.
*
* @param object $user
* Drupal user object.
* @param bool $use_table
* Boolean to define the storage type.
*/
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;
}
}
/**
* Get the cart data.
*
* @param int $nid
* Node id of the basic cart content.
*
* @return array
* array of cart data
*/
public function getCart($nid = NULL) {
return $this->cart
->getCart($nid);
}
/**
* Remove the cart data by nid.
*
* @param int $nid
* Removes the node from cart.
*
* @return bool
* return true or false
*/
public function removeFromCart($nid) {
return $this->cart
->removeFromCart($nid);
}
/**
* Empty the cart.
*
* @return string
* Text message
*/
public function emptyCart() {
return $this->cart
->emptyCart();
}
/**
* Add the content to cart.
*
* @param int $id
* Node id of node.
* @param array $params
* Will contain quantity and entity type if exists.
*
* @return string
* Message
*/
public function addToCart($id, array $params = array()) {
return $this->cart
->addToCart($id, $params);
}
/**
* Sync cart data in session and database.
*/
public function loggedInActionCart() {
return $this->cart
->loggedInActionCart();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CartStorageSelect:: |
private | property | ||
CartStorageSelect:: |
private | property | ||
CartStorageSelect:: |
public | function | Add the content to cart. | |
CartStorageSelect:: |
public | function | Empty the cart. | |
CartStorageSelect:: |
public | function | Get the cart data. | |
CartStorageSelect:: |
public | function | Sync cart data in session and database. | |
CartStorageSelect:: |
public | function | Remove the cart data by nid. | |
CartStorageSelect:: |
public | function | Construct object using whether it is table class or session class. |