/var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Component
NameSizeModeActions
MailHelpComponent.php39810644editdlrm
SpreadsheetComponent.php40260644editdlrm
ToolsComponent.php50230644editdlrm
UserAuthComponent.php155410644editdlrm
UserConnectComponent.php61770644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Component/ToolsComponent.php (5023B)
registry = $registry; parent::__construct($registry, $config); } /** * method */ public function beforeFilter(EventInterface $event) { $this->setConfigureCache(); $this->setSettings(); $this->setSponsors(); } /** * isStock method */ /* public function isStock($cartItems = null, $CartProducts) { if ($cartItems) { foreach ($cartItems as $cartItem) { $stock = $cartItem->product->stock; $qnt = $cartItem['qnt']; // daca stocul este mai mic decat cantitatea selectata if ($stock < $qnt) { if ($stock < 1) { if ($cartItem && $this->Carts->CartProducts->delete($cartItem)) { return $cartIsUpdated = true; } $this->Flash->error(__('Ne pare rau, produsul {0} nu mai este in stoc.', $cartItem->product->name)); } else { $CartProducts->id = $cartItem->id; $CartProducts->saveField('qnt', $stock); $this->Flash->error(__('Ne pare rau, produsul {0} mai are doar {1} bucati.', $cartItem->product->name, $stock)); return $cartIsUpdated = true; } } } } } */ /** * totalCart method */ public function totalPriceCart($cart = null) { if (!empty($cart)) { $this->Carts = TableRegistry::get('Carts'); $itemsCart = $this->Carts->CartProducts->find('all') ->contain(['Products']) ->where(['cart_id' => $cart->id]) ->toList(); $total = 0; foreach ($itemsCart as $itemCart) { $priceProduct = (!$itemCart->product->is_price_fixed && !empty($itemCart->custom_price)) ? $itemCart->custom_price : $itemCart->product->price; $total += $itemCart->qnt * $priceProduct; } $total = number_format($total, 2, '.', ''); return $total; } else { return false; } } /** * method */ public function setSettings() { $cacheKey = 'all_settings'; $allSettings = []; if (!Configure::read('debug')) { $allSettings = Cache::read($cacheKey, 'iHelpSettings'); } if (empty($allSettings)) { $allSettings = TableRegistry::getTableLocator()->get('Settings')->getAllSettings(); Cache::write($cacheKey, $allSettings, 'iHelpSettings'); } foreach ($allSettings as $key => $variable) { Configure::write("{$key}", $variable['value']); if (!defined(strtoupper($key))) { define(strtoupper($key), $variable['value']); } } } /** * method */ public function setSponsors() { $cacheKey = 'all_sponsors'; $allSponsors = []; if (!Configure::read('debug')) { $allSponsors = Cache::read($cacheKey, 'iHelpSponsors'); } if (empty($allSponsors)) { $allSponsors = TableRegistry::getTableLocator()->get('Sponsors')->getAllSponsors(); Cache::write($cacheKey, $allSponsors, 'iHelpSponsors'); } $sponsorActivitiesTable = TableRegistry::getTableLocator()->get('SponsorsActivities'); foreach ($allSponsors as $sponsor) { $sponsorActivities = $sponsorActivitiesTable->find() ->where(['sponsor_id' => $sponsor['id']]) ->toArray(); $sponsor['sponsor_activities'] = $sponsorActivities; } } /** * method */ public function setConfigureCache() { $configured = Cache::configured(); if (!in_array('iHelpSettings', $configured)) { Cache::setConfig('iHelpSettings', [ 'className' => 'File', 'duration' => '+1 day', 'path' => CACHE, 'prefix' => 'iHelp_' ]); } if (!in_array('iHelpSponsors', $configured)) { Cache::setConfig('iHelpSponsors', [ 'className' => 'File', 'duration' => '+1 day', 'path' => CACHE, 'prefix' => 'iHelp_' ]); } } /** * method */ public function generateUUID() { $uuid = hexdec(uniqid()); return $uuid; } }