/var/www/vhosts/ihelp.ro/httpdocs/src/View/Cell
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/View/Cell/CountItemsCartCell.php (1845B)
loadModel('Carts');
$conditions_cart_product = [];
$session = $this->request->getSession();
$countItemsCart = 0;
if (!empty($session->check('Auth.id'))) {
$userAuthId = $session->read('Auth.id');
}
// daca este user logat
if (!empty($userAuthId) && $userAuthId) {
$cart = $this->Carts->find()
->where(['Carts.user_id' => $userAuthId, 'Carts.is_active' => true])
->first();
} else { // nu este logat
$session = $this->request->getSession();
if ($session->check('cart_identifier')) {
$cart_identifier = $session->read('cart_identifier');
$cart = $this->Carts->find()
->where(['Carts.uuid' => $cart_identifier, 'Carts.is_active' => true])
->first();
}
}
if (!empty($cart)) {
$conditions_cart_product = ['CartProducts.cart_id' => $cart->id];
$countItemsCart = $this->Carts->CartProducts->find()
->contain(['Carts'])
->where($conditions_cart_product)
->count();
}
$this->set(compact('countItemsCart'));
}
}