You are here

public function CartTable::loggedInActionCart in Basic cart 8

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

File

src/CartTable.php, line 111

Class

CartTable
Class CartTable.

Namespace

Drupal\basic_cart

Code

public function loggedInActionCart() {
  if (isset($_SESSION['basic_cart']['cart']) && isset($_SESSION['basic_cart']['cart_quantity'])) {
    foreach ($_SESSION['basic_cart']['cart'] as $id => $value) {
      $param = array();
      $param['uid'] = $this->user_id;
      $param['id'] = $id;
      $param['entitytype'] = $value
        ->getEntityTypeId();
      $table_data = $this->cart_storage
        ->load($param);
      if ($table_data) {
        $param['quantity'] = $_SESSION['basic_cart']['cart_quantity'][$id];
        $table_data = $this->cart_storage
          ->update($param);
      }
      else {
        $param['quantity'] = $_SESSION['basic_cart']['cart_quantity'][$id];
        $this->cart_storage
          ->insert($param);
      }
    }
  }
  $param = array();
  $param['uid'] = $this->user_id;
  $exist_data = $this->cart_storage
    ->load($param);
  foreach ($exist_data as $key) {
    if (!isset($_SESSION['basic_cart']['cart'][$key->id])) {
      $_SESSION['basic_cart']['cart_quantity'][$key->id] = $key->quantity;
      $_SESSION['basic_cart']['cart'][$key->id] = \Drupal::entityTypeManager()
        ->getStorage($key->entitytype)
        ->load($key->id);
    }
  }
}