public function testAppBoot()
 {
     $app = app();
     $app->settings = new StoreSettings();
     $app->taxService = new TaxService();
     $app->currencyService = new CurrencyService();
     $app->languageService = new LanguageService();
     $app->settings->currencies = $app->currencyService->getAll();
     $app->settings->languages = $app->languageService->getAll();
     $app->settings->language = $app->languageService->getById(1);
     $app->settings->currency = $app->currencyService->getById(3);
     $this->assertEquals(1, $app->settings->language->language_id);
     $this->assertEquals(3, $app->settings->currency->currency_id);
     $catalogService = new CatalogService();
     $app->settings->carts[Cart::SHOPPING_CART]->add(1, $catalogService->getCartItem(43));
     //MacBook price:500)
     $app->settings->carts[Cart::SHOPPING_CART]->add(1, $catalogService->getCartItem(44));
     //MacBook Air price:1000)
     //Save to Session
     $app->settings->save();
     //Restore From session
     $app->settings = Session::get("settings");
     $this->assertEquals(1, $app->settings->language->language_id);
     $this->assertEquals(3, $app->settings->currency->currency_id);
     $this->assertEquals(3, count($app->settings->carts[Cart::SHOPPING_CART]->items) == 2);
     $cart_items = $app->settings->carts[Cart::SHOPPING_CART]->items;
     $this->assertEquals(43, $app->settings->carts[Cart::SHOPPING_CART]->items[43]->product->product_id);
     $this->assertEquals(44, $app->settings->carts[Cart::SHOPPING_CART]->items[44]->product->product_id);
 }
Example #2
0
 public function run()
 {
     $limit = CatalogConfig::model()->findByPk(1, array('select' => 'widget_count'));
     $limit = $limit->widget_count;
     $criteria = new CDbCriteria();
     $criteria->limit = $limit;
     $criteria->order = 'id ASC';
     $services = CatalogService::model()->findAll($criteria);
     $this->render('main_page_services', array('services' => $services));
 }
Example #3
0
 /**
  * Parse url
  *
  * @param $manager
  * @param $request
  * @param $pathInfo
  * @param $rawPathInfo
  *
  * @return bool|string
  */
 public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
 {
     if (preg_match('%^(/?([\\w\\-.]+))+$%', $pathInfo, $matches)) {
         $pages = preg_split("/\\//", $pathInfo);
         $element_arr = explode('.', end($pages));
         $element = $element_arr[0];
         if ($page = CatalogCategory::model()->find(array('condition' => 'link=:link', 'params' => array(':link' => $element)))) {
             return '/services/default/category/link/' . $element;
         } else {
             if ($service = CatalogService::model()->find(array('condition' => 'link=:link', 'params' => array(':link' => $element)))) {
                 return '/services/default/service/id/' . $service->id;
             } else {
                 return false;
             }
         }
     }
     return false;
 }
Example #4
0
 /**
  * Output category (categories and services)
  *
  * @param int $id
  */
 public function actionIndex($id = 0)
 {
     if (!($category = $this->loadModel($id))) {
         $category = new CatalogCategory();
         $category->id = 0;
         $category->short_title = 'Управление услугами';
     }
     $this->breadcrumbs = CatalogCategory::getParents($category->id);
     $this->breadcrumbs[] = $category->short_title;
     $categoryData = new CatalogCategory();
     $services = new CatalogService('search');
     $services->unsetAttributes();
     $services->id_category = $category->id;
     if (isset($_GET['CatalogService'])) {
         $services->attributes = $_GET['CatalogService'];
     }
     $this->render('index', array('services' => $services, 'categoryData' => $categoryData, 'category' => $category));
 }
Example #5
0
 /**
  * Before save
  *
  * @return bool
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $catalogConfig = CatalogConfig::model()->findByPk(1);
         if (!$this->isNewRecord) {
             $old_model = CatalogService::model()->findByPk($this->id);
             $old_image = $old_model->photo;
         } else {
             $old_image = '';
         }
         if ($photo = CUploadedFile::getInstance($this, 'photo')) {
             $name = md5(time() . $photo) . '.' . $photo->getExtensionName();
             $this->photo = $name;
             $photo->saveAs($this->folder . '/' . $name);
             if ($catalogConfig->watermark_image && !$catalogConfig->no_watermark) {
                 Yii::app()->ih->load($this->folder . '/' . $this->photo)->watermark($this->folder . '/watermark/' . $catalogConfig->watermark_image, $catalogConfig->watermark_x, $catalogConfig->watermark_y)->save();
             }
             switch ($catalogConfig->resize_mode) {
                 case 2:
                     Yii::app()->ih->load($this->folder . '/' . $this->photo)->resizeCanvas($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/medium/' . $this->photo)->reload()->resizeCanvas($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/small/' . $this->photo);
                     break;
                 default:
                     Yii::app()->ih->load($this->folder . '/' . $this->photo)->resize($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/medium/' . $this->photo)->reload()->resize($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/small/' . $this->photo);
                     break;
             }
             if ($old_image) {
                 @unlink($this->folder . '/' . $old_image);
                 @unlink($this->folder . '/medium/' . $old_image);
                 @unlink($this->folder . '/small/' . $old_image);
             }
         } else {
             $this->photo = $old_image;
         }
         $serviceImages = new CatalogImage();
         if ($serviceImagesUpload = CUploadedFile::getInstances($serviceImages, 'image')) {
             foreach ($serviceImagesUpload as $file) {
                 $serviceImages = new CatalogImage();
                 $serviceImagesName = md5(time() . $file->name) . '.' . $file->getExtensionName();
                 $serviceImages->image = $serviceImagesName;
                 $file->saveAs($this->folder . '/moreimages/' . $serviceImagesName);
                 $this->images[] = $serviceImages;
                 if ($catalogConfig->watermark_image && !$catalogConfig->no_watermark) {
                     Yii::app()->ih->load($this->folder . '/moreimages/' . $serviceImagesName)->watermark($this->folder . '/watermark/' . $catalogConfig->watermark_image, $catalogConfig->watermark_x, $catalogConfig->watermark_y)->save();
                 }
                 switch ($catalogConfig->resize_mode) {
                     case 2:
                         Yii::app()->ih->load($this->folder . '/moreimages/' . $serviceImagesName)->resizeCanvas($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/moreimages/small/' . $serviceImagesName)->reload()->resizeCanvas($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/moreimages/medium/' . $serviceImagesName);
                         break;
                     default:
                         Yii::app()->ih->load($this->folder . '/moreimages/' . $serviceImagesName)->resize($catalogConfig->s_image_small_w, $catalogConfig->s_image_small_h)->save($this->folder . '/moreimages/small/' . $serviceImagesName)->reload()->resize($catalogConfig->s_image_middle_w, $catalogConfig->s_image_middle_h)->save($this->folder . '/moreimages/medium/' . $serviceImagesName);
                         break;
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }
Example #6
0
 /**
  * Returns the data model based on the primary key given in the GET variable
  * If the data model is not found, an HTTP exception will be raised
  *
  * @param $id the ID of the model to be loaded
  *
  * @return mixed
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = CatalogService::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }