public static function addGroup($groupName, $messages)
 {
     if (!Util::isEmpty($messages)) {
         foreach ($messages as $k => $v) {
             FlashMessageStorage::add($k, $v, $groupName);
         }
     }
 }
 public function setDefault()
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     ThemeModel::getInstance()->setDefaultTheme();
     messages::add('Theme_ThemeRestored', ['name' => ThemeModel::getInstance()->getDefaultTheme()], 'success');
     $this->systemRedirect('/theme');
 }
 public function destroy($catalogId, $productId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         SpecialOfferModel::getInstance()->delete($catalogId, $productId);
         messages::add('SpecialOffer_Deleted', 1, 'success');
         $this->systemRedirect('/specialOffer');
     } catch (\Exception $e) {
         messages::add('UnknownError', 1, 'error');
         $this->systemRedirect('/specialOffer');
     }
 }
 public function save($currencyId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         $exchangeRate = $this->param('exchangeRate');
         $exchangeRate['currency'] = $currencyId;
         CurrencyModel::getInstance()->saveExchangeRate($exchangeRate);
         messages::add('Currency_Saved', 1, 'success');
         $this->redirectBack();
     } catch (\Exception $e) {
         messages::add('Error', 1, 'error');
         $this->redirectBack();
     }
 }
Ejemplo n.º 5
0
 public function login()
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     $userLogin = $this->paramPost('user')['login'];
     $userPassword = $this->paramPost('user')['password'];
     try {
         $loggedInUser = AuthModel::getInstance()->login($userLogin, $userPassword);
         messages::add('Auth_UserLoggedIn', ['login' => $loggedInUser['login']], 'success');
         $this->systemRedirect('/');
     } catch (PhException $e) {
         messages::add('Auth_WrongLoginPassword', 1, 'error');
         $this->systemRedirect('/auth');
     }
 }
Ejemplo n.º 6
0
 public function saveImage($catalogId, $productId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         $uploadedFile = $_FILES['productImage'];
         if (empty($uploadedFile) || $uploadedFile['error'] != 0) {
             messages::add('Product_ImageNotUploaded', 1, 'error');
             $this->redirectBack();
         }
         $fileExt = FileUtil::getFileExtension($uploadedFile['name']);
         if (!in_array($fileExt, ImageUtil::getSupportedExtension())) {
             messages::add('Product_InvalidImageFormat', 1, 'error');
             $this->redirectBack();
         }
         $imgDir = ProductModel::getInstance()->getImagesDir($catalogId);
         FileUtil::createDirIfNotExist($imgDir);
         $targetFilename = $productId . '.' . $fileExt;
         move_uploaded_file($uploadedFile['tmp_name'], $imgDir . $targetFilename);
         ImageUtil::convertToJpeg($imgDir . $targetFilename);
         messages::add('Product_ImageSaved', 1, 'success');
         $this->systemRedirect('/catalog/editProducts/' . $catalogId);
     } catch (PhException $e) {
         messages::add('Product_ImageUploadError', 1, 'success');
         $this->redirectBack();
     }
 }
Ejemplo n.º 7
0
 public function destroy($userId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         if ($userId === AuthModel::getInstance()->getLoggedInUserId()) {
             PhException::throwErrors(['User_DeleteCurrentUser' => 1]);
         }
         $user = UserModel::getInstance()->getById($userId);
         UserModel::getInstance()->delete($userId);
         messages::add('User_Deleted', ['login' => $user['login']], 'success');
         $this->systemRedirect('/user');
     } catch (PhException $e) {
         messages::addGroup('error', $e->getErrors());
         $this->systemRedirect('/user');
     }
 }