public function actionSearch() { $keyword = $_GET['keyword'] ? trim($_GET['keyword']) : ""; $num = 0; $products = null; $brands = null; // 品牌搜索 $criteria = new CDbCriteria(); $criteria->addSearchCondition('t.title', $keyword, true, 'OR'); $criteria->addSearchCondition('t.sub_content', $keyword, true, 'OR'); $criteria->addSearchCondition('t.content', $keyword, true, 'OR'); if ($_GET['lang'] === 'en') { $criteria->addSearchCondition('localized.title', $keyword, true, 'OR'); $criteria->addSearchCondition('localized.sub_content', $keyword, true, 'OR'); $criteria->addSearchCondition('localized.content', $keyword, true, 'OR'); } $brands = Brand::model()->localized()->findAll($criteria); // 产品搜索 $criteria = new CDbCriteria(); $criteria->select = 't.series_id'; $criteria->addSearchCondition('t.title', $keyword, true, 'OR'); $criteria->addSearchCondition('t.norms', $keyword, true, 'OR'); $criteria->addSearchCondition('t.series_model', $keyword, true, 'OR'); $criteria->addSearchCondition('t.content', $keyword, true, 'OR'); if ($_GET['lang'] === 'en') { $criteria->select = 'localized.owner_id as series_id'; $criteria->addSearchCondition('localized.title', $keyword, true, 'OR'); $criteria->addSearchCondition('localized.norms', $keyword, true, 'OR'); $criteria->addSearchCondition('localized.series_model', $keyword, true, 'OR'); $criteria->addSearchCondition('localized.content', $keyword, true, 'OR'); } $serieids = ProductSeries::model()->localized()->findAll($criteria); $ids = array(); foreach ($serieids as $key => $value) { $ids[] = $value->series_id; } $criteria = new CDbCriteria(); if (!empty($ids)) { $criteria->addInCondition('t.series_id', $ids); } $criteria->addSearchCondition('t.name', $keyword, true, 'OR'); if ($_GET['lang'] === 'en') { $criteria->addSearchCondition('localized.name', $keyword, true, 'OR'); } $products = Product::model()->localized()->findAll($criteria); $num = count($products) + count($brands); $this->pageTitle = Yii::t('common', '首页') . SEPARATOR . Setting::getValueByCode('inside_title', true); $this->render('search', array('keyword' => $keyword, 'brands' => $brands, 'products' => $products, 'num' => $num)); }
public function actionView() { $previd = 0; // 上一个品牌 $nextid = 0; // 下一个品牌 $serie = null; $prevname = ''; $nextname = ''; $products = null; if (isset($_GET['seriesid'])) { $id = Yii::app()->request->getQuery('seriesid'); $serie = ProductSeries::model()->localized()->findByPk($id); $criteria = new CDbCriteria(); $criteria->compare('t.is_released', 1); $criteria->compare('t.series_id', $id); $products = Product::model()->localized()->findAll($criteria); $criteria = new CDbCriteria(); $criteria->compare('t.is_released', 1); $series = ProductSeries::model()->localized()->findAll($criteria); foreach ($series as $key => $value) { if ($value->series_id == $id && $key != 0) { $previd = isset($series[$key - 1]) ? $series[$key - 1]['series_id'] : 0; $nextid = isset($series[$key + 1]) ? $series[$key + 1]['series_id'] : 0; $prevname = isset($series[$key - 1]) ? $series[$key - 1]['title'] : ''; $nextname = isset($series[$key + 1]) ? $series[$key + 1]['title'] : ''; } else { if ($value->series_id == $id && $key == 0) { $nextid = isset($series[$key + 1]) ? $series[$key + 1]['series_id'] : 0; $nextname = isset($series[$key + 1]) ? $series[$key + 1]['title'] : ''; } } } } if (empty($serie)) { throw new CHttpException(404); } // 广告图 $criteria = new CDbCriteria(); $criteria->compare('t.banner_position_id', 1); $banner = Banner::model()->localized()->find($criteria); $this->pageTitle = Yii::t('common', '产品中心') . SEPARATOR . Setting::getValueByCode('inside_title', true); $this->render('view', array('serie' => $serie, 'banner' => $banner, 'previd' => $previd, 'nextid' => $nextid, 'prevname' => $prevname, 'nextname' => $nextname, 'products' => $products)); }
public function actionUpdate($id) { if (Yii::app()->user->checkAccess('updateProduct') == false) { throw new CHttpException(403); } $product = Product::model()->multilingual()->findByPk($id); if (is_null($product)) { throw new CHttpException(404); } $imageList = array(); if (isset($_POST['Product'])) { $product->attributes = Yii::app()->request->getPost('Product'); $product->productFile = CUploadedFile::getInstance($product, 'productFile'); foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { $product->i18nFormData['productFile_' . $lang] = CUploadedFile::getInstance($product, 'i18nFormData[productFile_' . $lang . ']'); } $imageList = Yii::app()->request->getPost('imageList'); $product->category_id = $product->series->category->category_id; $product->brand_id = $product->series->brand_id; $product->update_time = time(); if ($product->validate() && $product->save()) { // 保存图片数据 // if (count($imageList) > 0) { // foreach ($imageList as $productImageId => $imageInfo) { // $productImage = ProductImage::model() // ->findByPk($productImageId); // $productImage->sort_order = $imageInfo['sort_order']; // $productImage->file_name = $imageInfo['file_name']; // if (isset($imageInfo['is_released'])) { // $productImage->is_released = $imageInfo['is_released']; // } else { // $productImage->is_released = 0; // } // $productImage // ->save(true, // array('label', 'file_name','sort_order', // 'is_released')); // } // } $this->setFlashMessage(strtr('<strong>{link}</strong> 产品修改成功', array('{link}' => CHtml::link($product->name, array('view', 'id' => $product->primaryKey))))); $this->redirect($this->getReturnUrl()); } } else { $product->i18nFormData = $product->getI18nAttributes(); // foreach ($product->images as $productImage) { // $imageList[$productImage->primaryKey] = array( // 'product_id' => $productImage->product_id, // 'file_name' => $productImage->file_name, // 'thumbnail_image_url' => $productImage // ->getThumbnailImageUrl(), // 'sort_order' => $productImage->sort_order, // 'is_released' => $productImage->is_released); // } } $this->breadcrumbs = array('产品' => array('index'), '修改'); // $productCategoryOptions = ProductCategory::model()->getLeaveOptions(); $productSeriesOptions = ProductSeries::model()->getOptions(); $this->render('create', array('product' => $product, 'imageList' => $imageList, 'productSeriesOptions' => $productSeriesOptions, 'returnUrl' => $this->getReturnUrl())); }