/var/www/vhosts/ihelp.ro/httpdocs/src/Controller
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/AppController.php (6090B)
loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Tools');
$this->loadComponent('UserAuth');
// Add this line to check authentication result and lock your site
$this->loadComponent('Authentication.Authentication');
$this->loadComponent('Authorization.Authorization');
setlocale(LC_TIME, ['ro.utf-8', 'ro_RO.UTF-8', 'ro_RO.utf-8', 'ro', 'ro_RO', 'ro_RO.ISO8859-2']);
}
# --------------------------------
# App > beforeFilter
# --------------------------------
public function beforeFilter(EventInterface $event)
{
$this->_setUserAuth();
// $this->_getCart();
}
private function _setUserAuth(): void
{
$auth = $this->Authentication->getIdentity();
$this->userAuth = $auth;
$this->set('userAuth', $this->userAuth);
}
/**
* identifireIdCartSession
*/
function identifireIdCartSession()
{
$session = $this->request->getSession();
if ($session->check('cart_identifier')) {
$cart_identifier = $session->read('cart_identifier');
} else {
$cart_identifier = $this->Tools->generateUUID();
$session->write('cart_identifier', $cart_identifier);
}
return $cart_identifier;
}
/**
* identifireIdFavoriteSession
*/
function identifireIdFavoriteSession()
{
$session = $this->request->getSession();
if ($session->check('favorite_identifier')) {
$favorite_identifier = $session->read('favorite_identifier');
} else {
$favorite_identifier = $this->Tools->generateUUID();
$session->write('favorite_identifier', $favorite_identifier);
}
return $favorite_identifier;
}
//
protected function getFavorites(): void
{
$conditions = [];
$productFavorites = [];
if (!empty($this->userAuth->id) && $this->userAuth->id) { //is login
$conditions = ['ProductFavorites.user_id' => $this->userAuth->id];
} else {
$session = $this->request->getSession();
if ($session->check('favorite_identifier')) {
$favorite_identifier = $session->read('favorite_identifier');
$conditions = ['ProductFavorites.uuid' => $favorite_identifier];
}
}
if (!empty($conditions)) {
$this->loadModel('ProductFavorites');
$productFavorites = $this->ProductFavorites->find('list', [
'keyField' => 'product_id',
'valueField' => 'product_id'
])
->where($conditions)
->toArray();
}
$this->set(compact('productFavorites'));
}
public function getFiltersPageCategory()
{
$keywords = $this->request->getQuery();
if (!empty($keywords)) {
$conditions = [];
foreach ($keywords as $keyword => $value) {
switch ($keyword) {
case 'picture':
if (!empty($value)) {
$conditions['FeaturedImage.is_featured'] = true;
}
break;
//list orders
case 'price':
[$min, $max] = explode('-', $value);
if (!empty($min)) {
$conditions['Products.price >= '] = $min;
}
if (!empty($max)) {
$conditions['Products.price <= '] = $max;
}
break;
default:
break;
}
}
return $conditions;
}
}
// public function _getCart()
// {
// $this->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) {
// $cartItems = $this->Carts->find()
// ->contain(['CartProducts'])
// ->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');
// $cartItems = $this->Carts->find()
// ->contain(['CartProducts'])
// ->where(['Carts.uuid' => $cart_identifier, 'Carts.is_active' => true])
// ->first();
// }
// }
// if (!empty($cartItems)) {
// $countItemsCart = count($cartItems->cart_products);
// }
// $this->set(compact('countItemsCart', 'cartItems'));
// }
}