/**
  * View: Video Index
  * @return Respanse
  */
 public function getVideoIndex()
 {
     $articles = Article::orderBy('created_at', 'desc')->where('post_status', 'open')->paginate(6);
     $travel = Travel::orderBy('created_at', 'desc')->where('post_status', 'open')->paginate(4);
     $product = Product::orderBy('created_at', 'desc')->where('post_status', 'open')->where('quantity', '>', '0')->paginate(12);
     $productCategories = ProductCategories::orderBy('sort_order')->where('cat_status', 'open')->get();
     $job = Job::orderBy('created_at', 'desc')->where('post_status', 'open')->paginate(4);
     $categories = Category::orderBy('sort_order')->where('cat_status', 'open')->get();
     if (Auth::check()) {
         $timeline = Timeline::orderBy('created_at', 'desc')->where('user_id', Auth::user()->id)->paginate(6);
     } else {
         $timeline = Timeline::orderBy('created_at', 'desc');
     }
     return View::make('home.videoindex')->with(compact('articles', 'categories', 'travel', 'product', 'productCategories', 'job', 'timeline'));
 }
 public function actionProducts()
 {
     $criteria = new CDbCriteria();
     $criteria->addCondition("t.active=1");
     $criteria->addCondition("t.delete=0");
     $criteria->order = "t.order, t.id DESC";
     $category = null;
     if (isset($_GET['category'])) {
         //$criteria->addCondition("t.productCategories=".$_GET['category']);
         //$categories=ProductCategories::model()->findByPk($_GET['category']);
         $category = ProductCategories::model()->findByAttributes(array('non_utf8_name' => $_GET['category']));
         if ($category === null || $category->active == 0 || $category->delete == 1) {
             throw new CHttpException(404, 'Địa chỉ bạn yêu cầu không tồn tại.');
         }
         //$criteria->addCondition("t.productCategories=".$category->id);
         // danh sach cac danh muc con
         $sub_categories = array();
         array_push($sub_categories, $category->id);
         foreach ($category->childCategories as $key => $item) {
             array_push($sub_categories, $item->id);
         }
         //$sub_categories = "'".implode("', '", $sub_categories)."'";
         $criteria->addInCondition('t.productCategories', $sub_categories);
     }
     $count = Product::model()->count($criteria);
     $pages = new CPagination($count);
     // results per page
     $pages->pageSize = Config::model()->getValueByKey('rowsperpageproduct');
     $pages->applyLimit($criteria);
     $models = Product::model()->findAll($criteria);
     //$pageTitle = Yii::t('site', 'AllProducts');
     $pageTitle = 'Tất cả sản phẩm';
     $metaDescription = Config::model()->getValueByKey('metadescription');
     $metaKeywords = Config::model()->getValueByKey('metakeywords');
     if (isset($category)) {
         $pageTitle = $category->name;
         $metaDescription = $category->metadescription;
         $metaKeywords = $category->metakeywords;
     }
     $this->pageTitle = $pageTitle . ' - ' . Config::model()->getValueByKey('sitetitle');
     $this->metaDescription = $metaDescription;
     $this->metaKeywords = $metaKeywords;
     $this->render('products', array('products' => $models, 'categories' => $category, 'pages' => $pages));
 }
 public function getDropdown()
 {
     global $dataDropdown;
     $dataDropdown = array();
     $parents = ProductCategories::model()->with('levelTop')->findALl();
     foreach ($parents as $parent) {
         $dataDropdown[$parent->id] = $parent->name;
         $this->_subDropDown($parent->childCategories);
     }
     return $dataDropdown;
 }
 /**
  * Resource show view
  * @param  string $slug Slug
  * @return response
  */
 public function show($slug)
 {
     $product = $this->model->where('slug', $slug)->first();
     is_null($product) and App::abort(404);
     $categories = ProductCategories::orderBy('sort_order')->get();
     if (Auth::check()) {
         $inCart = ShoppingCart::where('buyer_id', Auth::user()->id)->where('product_id', $product->id)->first();
     } else {
         $inCart = false;
     }
     return View::make('product.show')->with(compact('product', 'categories', 'inCart'));
 }
        <div id="leftNav">
            <div class="h">
                <a href="<?php 
echo $this->createAbsoluteUrl('sitemap');
?>
" id="leftDmSp">
					<span class="sp_all_prod _rounded">Danh mục sản phẩm</span>
				</a>
            </div>
            <div class="c">
                <ul class="leftNavMenu">
				<?php 
foreach ($categories as $item) {
    ?>
				<?php 
    $categoriesSub = ProductCategories::model()->findAll('t.parentid = ' . $item->id . ' AND t.active=1 AND t.delete=0 ORDER BY t.order, t.id DESC');
    ?>
				<?php 
    if (count($categoriesSub)) {
        ?>
					<li class="mnu-item">
						<a href="<?php 
        echo $item->getPublicURL();
        ?>
"><span class="menu-text"><?php 
        echo $item->name;
        ?>
</span><span class="menu-icon"></span></a>
					<ul class="leftSubNavMenu">
						<?php 
        foreach ($categoriesSub as $subitem) {
echo $form->textArea($model, 'summary', array('class' => 'input-xxlarge', 'size' => 60, 'maxlength' => 500));
?>
</div>
		<div class="controls"><?php 
echo $form->error($model, 'summary');
?>
</div>
	</div>

	<div class="control-group">
		<div class="control-label"><?php 
echo $form->labelEx($model, 'productCategories');
?>
</div>
		<div class="controls"><?php 
$categories = new ProductCategories();
echo $form->dropDownList($model, 'productCategories', $categories->getDropdown(), array('empty' => '---', 'class' => 'span4'));
?>
</div>
		<div class="controls"><?php 
echo $form->error($model, 'productCategories');
?>
</div>
	</div>
    
    <div class="control-group">
		<div class="control-label"><?php 
echo $form->labelEx($model, 'manufacturer');
?>
</div>
		<div class="controls"><?php 
 /**
  * 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 integer $id the ID of the model to be loaded
  * @return ProductCategories the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ProductCategories::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Resource edit view
  * GET         /resource/{id}/edit
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $data = $this->model->find($id);
     $categoryLists = ProductCategories::lists('name', 'id');
     $product = $this->model->where('slug', $data->slug)->first();
     return View::make($this->resourceView . '.edit')->with(compact('data', 'categoryLists', 'product'));
 }
 public function actionImport()
 {
     if (isset($_POST['media'])) {
         $arr = preg_split('/[,]/', $_POST['media']);
         $file_path = Yii::getPathOfAlias('webroot') . '/uploads/' . $arr[0];
         $sheet_array = Yii::app()->yexcel->readActiveSheet($file_path);
         $countError = 0;
         $rowError = '';
         $index = 1;
         foreach ($sheet_array as $row) {
             if ($index > 1) {
                 try {
                     $code = trim($sheet_array[$index]['B']);
                     $model = Product::model()->findByAttributes(array('code' => $code));
                     if ($model === null) {
                         $model = new Product();
                     }
                     $model->name = trim($sheet_array[$index]['A']);
                     $model->non_utf8_name = Common::removeUnicodeURL($model->name);
                     if ($code == '') {
                         $model->code = 'SP_';
                     } else {
                         $model->code = $code;
                     }
                     $model->model = trim($sheet_array[$index]['C']);
                     $model->color = trim($sheet_array[$index]['D']);
                     $model->origin = trim($sheet_array[$index]['E']);
                     $model->unit = trim($sheet_array[$index]['F']);
                     $model->price = trim($sheet_array[$index]['G']);
                     $model->discount = trim($sheet_array[$index]['H']);
                     $model->summary = trim($sheet_array[$index]['I']);
                     $strCategory = trim($sheet_array[$index]['J']);
                     $strCategory = Common::removeUnicodeURL($strCategory);
                     $category = ProductCategories::model()->findByAttributes(array('non_utf8_name' => $strCategory));
                     if ($category != null) {
                         $model->productCategories = $category->id;
                     }
                     $model->description = trim($sheet_array[$index]['K']);
                     $model->order = trim($sheet_array[$index]['L']);
                     $media = trim($sheet_array[$index]['M']);
                     if ($media == '') {
                         $media = '-';
                     }
                     $model->createdby = Yii::app()->user->id;
                     $model->createdatetime = new CDbExpression('NOW()');
                     $model->setRelationRecords('media', $this->getRelationMedia('tbl_product', $media));
                     if (!$model->save()) {
                         $rowError = $rowError . $index . ',';
                         $countError += 1;
                     } else {
                         if ($code == '') {
                             $model->code = sprintf('SP_%1$06d', $model->id);
                             $model->save();
                         }
                     }
                 } catch (Exception $e) {
                     //throw new CHttpException(500,$e->getMessage());
                     $rowError = $rowError . $index . ',';
                     $countError += 1;
                 }
             }
             $index += 1;
         }
         if ($countError == 0) {
             Yii::app()->user->setFlash('importdata', 'Quá trình nhập liệu thành công!');
         } else {
             Yii::app()->user->setFlash('importdata', 'Có ' . $countError . ' dòng (' . substr($rowError, 0, -1) . ') trong ' . (count($sheet_array) - 1) . ' dòng dữ liệu xảy ra lỗi trong quá trình nhập liệu!');
         }
         $this->refresh();
     }
     $this->render('import');
 }
Exemple #10
0
 function __construct($optionId, $showDisabled = false)
 {
     $option = new ProductOption($optionId);
     $allGroups = new ProductCategories($option->productId(), $showDisabled);
     parent::__construct($option->id(), $allGroups->IDs());
 }