public function actions() { $formSettings = array('redirect' => $this->createUrl('admin'), 'forms' => array('id' => 'mainForm', 'varName' => 'productCategory', 'models' => 'ProductCategory', 'onAfterSave' => function ($event) { $model = $event->params['model']; if ($model->location != 'nochange') { $decode = CJSON::decode($_POST['ProductCategory']['location']); $to = ProductCategory::model()->findByPk((int) $decode['to']); $action = $decode['action']; switch ($action) { case 'child': $model->moveAsLast($to); break; case 'before': if ($to->isRoot()) { $model->moveAsRoot(); } else { $model->moveBefore($to); } break; case 'after': if ($to->isRoot()) { $model->moveAsRoot(); } else { $model->moveAfter($to); } break; } } })); return array('create' => array('class' => 'application.components.actions.Create', 'formSettings' => $formSettings), 'update' => array('class' => 'application.components.actions.Update', 'formSettings' => $formSettings), 'delete' => array('class' => 'application.components.actions.Delete', 'modelClass' => 'ProductCategory'), 'admin' => array('class' => 'application.components.actions.Admin', 'modelClass' => 'ProductCategory')); }
public function run() { $categoriesTree = ProductCategory::model()->getTree(); $currentCategory = Yii::app()->daShop->currentIdCategory !== null ? $categoriesTree->getById(Yii::app()->daShop->currentIdCategory) : null; $tree = array('items' => $this->buildTree($categoriesTree, $currentCategory)); $this->render('categoryWidget', compact('tree')); }
/** * getListItems - Phương thức dùng để lấy dữ liệu */ public function getListItems($category_id = null) { Yii::import('application.modules.products.models.ProductItem'); $model = new ProductItem('search'); $model->unsetAttributes(); $criteria = new CDbCriteria(); $criteria->order = 'created DESC'; if ($category_id) { Yii::import('application.modules.products.models.ProductCategory'); $categories = ProductCategory::model()->findByPk($category_id); if (!$categories) { return null; } $this->__category = $categories; $descendants = $categories->descendants()->findAll('is_active = 1'); $arrCat = array($category_id); foreach ($descendants as $cat) { $arrCat[] = $cat->id; } $criteria->with = array('categoryitem'); $criteria->together = true; foreach ($arrCat as $cat) { $criteria->compare('categoryitem.category_id', $cat, false, 'OR'); } } $criteria->compare('status', 1); $search = new CActiveDataProvider($model, array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->getModule('products')->entriesShow))); $data = $search->getData(); $this->__pagination = $search->pagination; return $data; }
public function loadModel($id) { $model = ProductCategory::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionIndex() { $brand_id = isset($_GET['brand_id']) ? $_GET['brand_id'] : 0; $productCategoryOptions = ProductCategory::model()->byBrandOptions($brand_id); // 产品 $criteria = new CDbCriteria(); $criteria->compare('t.is_released', 1); $productarr = Product::model()->localized()->findAll($criteria); $brand = array(); if ($brand_id != 0) { $criteria = new CDbCriteria(); $criteria->compare('t.brand_id', $brand_id); $criteria->order = 'sort_order ASC'; $brand = Brand::model()->localized()->find($criteria); $productCategoryOptions = ProductCategory::model()->byBrandOptions($brand_id); // 产品 $criteria = new CDbCriteria(); $criteria->compare('t.brand_id', $brand_id); $productarr = Product::model()->localized()->findAll($criteria); } $products = array(); foreach ($productarr as $model) { $products[] = $model->attributes; } // 广告图 $criteria = new CDbCriteria(); $criteria->compare('t.banner_position_id', 1); $banner = Banner::model()->localized()->find($criteria); $brands = array(); $criteria = new CDbCriteria(); $criteria->select = 'brand_id,title'; $criteria->compare('t.is_released', 1); $brandsarr = Brand::model()->localized()->findAll($criteria); foreach ($brandsarr as $model) { $brands[$model->brand_id] = $model->title; } $series = array(); $criteria = new CDbCriteria(); $criteria->select = 'series_id,title'; $criteria->compare('t.is_released', 1); $seriesarr = ProductSeries::model()->localized()->findAll($criteria); foreach ($seriesarr as $model) { $series[$model->series_id] = $model->title; } $categorys = array(); $criteria = new CDbCriteria(); $criteria->select = 'category_id,name'; $criteria->compare('t.is_released', 1); $categorysarr = ProductCategory::model()->localized()->findAll($criteria); foreach ($categorysarr as $model) { $categorys[$model->category_id] = $model->name; } $this->layout = 'main'; $this->pageTitle = Yii::t('common', '产品中心') . SEPARATOR . Setting::getValueByCode('inside_title', true); $this->render('index', array('brand_id' => $brand_id, 'brand' => $brand, 'products' => $products, 'brands' => $brands, 'series' => $series, 'categorys' => $categorys, 'productCategoryOptions' => $productCategoryOptions, 'banner' => $banner)); }
public function actionIndex() { $criteria = new CDbCriteria(); $criteria->order = 'name'; $types = ProductType::model()->findAll($criteria); $manufacturers = ProductManufacturer::model()->findAll($criteria); $categories = ProductCategory::model()->findAll($criteria); $data = array('types' => $types, 'manufacturers' => $manufacturers, 'categories' => $categories); $this->render('index', $data); }
/** * getData - Phương thức dùng để lấy dữ liệu */ public function getData() { $arrTrees = array(); Yii::import('application.modules.products.models.ProductCategory'); $treeRoot = ProductCategory::model()->roots()->find(); if ($treeRoot) { $descendants = $treeRoot->descendants()->findAll('is_active = 1'); $tree = $treeRoot->toArray($descendants); $arrTrees = $this->__getListChilds($tree); } return $arrTrees; }
public static function byBrandOptions($brand_id) { $items = array(); $criteria = new CDbCriteria(); if ($brand_id == 0) { $sql = "select name,category_id,brand_id from {{product_category}} where is_released=1 and category_id NOT IN(select parent_id from {{product_category}})"; } else { $sql = "select name,category_id,brand_id from {{product_category}} where is_released=1 and brand_id={$brand_id} and category_id NOT IN(select parent_id from {{product_category}} where brand_id={$brand_id})"; } $items = ProductCategory::model()->localized()->findAllBySql($sql); return $items; }
public function run() { $categoriesTree = ProductCategory::model()->getTree(); $currentCategory = Yii::app()->daShop->currentIdCategory !== null ? $categoriesTree->getById(Yii::app()->daShop->currentIdCategory) : null; if ($currentCategory == null) { return; } // брэнды рисуем только для текущей категории $brands = $currentCategory->brands(array('with' => 'productCount')); if (count($brands) == 0) { return; } $this->render('brandWidget', compact('brands')); }
public function actionDetail($c, $n) { // Get product if (!($product = Product::model()->find('i18nProduct.l_name_url=:n', array('n' => $n)))) { throw new CHttpException(404, 'The requested page does not exist.'); } $productMultilang = Product::model()->multilang()->find('i18nProduct.l_name_url=:n', array('n' => $n)); // Get category if (!($category = ProductCategory::model()->find('i18nProductCategory.l_name_url=:c', array('c' => $c)))) { throw new CHttpException(404, 'The requested page does not exist.'); } $categoryMultilang = ProductCategory::model()->multilang()->find('i18nProductCategory.l_name_url=:c', array('c' => $c)); Yii::app()->languageManager->translatedGetVars['n'] = array(); foreach (array_keys(Yii::app()->languageManager->languages) as $language) { Yii::app()->languageManager->translatedGetVars['n'][$language] = $productMultilang->{'name_url_' . $language}; Yii::app()->languageManager->translatedGetVars['c'][$language] = $categoryMultilang->{'name_url_' . $language}; } $this->render('detail', array('product' => $product, 'category' => $category)); }
public function actionIndex($key) { if ($key != $this->module->exportKey) { echo 'invalid key'; return; } $file = Yii::app()->getRuntimePath() . '/catalog_export_market.dat'; if ($this->echoFile($file)) { return; } // генерируем новый файл и сразу выводим содержимое на экран if (!file_exists($file) || is_writable($file)) { $handle = fopen($file, 'w'); if (!$handle) { echo 'can not write to file'; return; } $this->writeLine($handle, time()); $this->writeLine($handle, 'id;type;available;url;price;currencyId;category;picture;vendor;model;store;delivery;description'); $criteria = new CDbCriteria(); $criteria->condition = 't.id_brand IS NOT NULL'; $criteria->mergeWith($this->module->exportCriteria); $products = Product::model()->with('brand', 'mainPhoto')->findAll($criteria); $domain = Yii::app()->domain->getModel(); $categories = ProductCategory::model()->getTree(); foreach ($products as $product) { /** * @var $product Product * @var $category ProductCategory */ $category = $product->id_product_category == null ? null : $categories->getById($product->id_product_category); if ($category == null) { continue; } $product->category = $category; $name = str_replace(array("\n", "\r", ";", "\t", '"'), array(' ', ' ', ',', ' ', ''), $product->name); $this->writeElements($handle, array($product->id_product, 'vendor.model', 'true', 'http://' . $domain->getDomainName() . $product->getUrl(), $product->getPriceWithMarkup(), 'RUR', $category->name, $product->image == null ? '' : 'http://' . $domain->getDomainName() . $product->mainPhoto->getUrlPath(), $product->id_brand == null ? '' : $product->brand->name, $name, 'false', 'true', str_replace(array("\n", "\r", ";", "\t", '"'), array(' ', ' ', ',', ' ', ''), $product->description))); } fclose($handle); $this->echoFile($file); } }
public function run() { $selecter = ''; $rootCategoties = Helper::getCategories($this->companyId); //var_dump($this->categoryId,$rootCategoties);exit; if ($this->categoryId != 0 && ($category = ProductCategory::model()->find('t.lid = :cid and t.dpid=:dpid', array(':cid' => $this->categoryId, ':dpid' => $this->companyId)))) { //var_dump($category->tree);exit; $categoryTree = explode(',', $category['tree']); echo $this->getSelecter($categoryTree); } else { // var_dump($rootCategoties);exit; $selecter = '<select class="form-control category_selecter" tabindex="-1" name="category_id_selecter">'; $selecter .= yii::t('app', '<option value="">--请选择--</option>'); foreach ($rootCategoties as $c1) { $selecter .= '<option value="' . $c1['lid'] . '">' . $c1['category_name'] . '</option>'; } $selecter .= '</select>'; } echo $selecter; }
/** * Manages all models. */ public function actionAdmin($category = '') { $baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets'); Yii::app()->getClientScript()->registerCssFile($baseScriptUrl . '/products.css'); if (isset($_POST['product-item-grid_c0'])) { foreach ($_POST['product-item-grid_c0'] as $strNewID) { $model = $this->loadModel($strNewID); $model->delete(); } } $model = new ProductItem('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['ProductItem'])) { $model->attributes = $_GET['ProductItem']; } if ($category) { $arrCat = array($category); $categories = ProductCategory::model()->findByPk($category); if ($categories) { $descendants = $categories->descendants()->findAll('is_active = 1'); foreach ($descendants as $cat) { $arrCat[] = $cat->id; } } $model->categories = $arrCat; } $this->render('admin', array('model' => $model)); }
public function actionView($idProduct) { /** * @var Product $product */ $product = $this->throw404IfNull(Product::model()->with('mainPhoto')->findByPk($idProduct)); //категория может быть скрыта, и тогда этот раздел не должен показываться $category = $this->throw404IfNull(ProductCategory::model()->getTree()->getById($product->id_product_category)); Yii::app()->daShop->currentIdCategory = $category->id_product_category; $this->breadcrumbs[$product->name] = $product->getUrl(); $this->setPageTitle($product->name . ', ' . $this->getPageTitle()); $this->render('/product', array('product' => $product)); }
public function setCurrentIdCategory($idCategory) { if (!is_numeric($idCategory)) { return; } $this->_currentIdCategory = $idCategory; // настраиваем цепочку навигаций if (isset(Yii::app()->controller->breadcrumbs)) { $tree = ProductCategory::model()->getTree(); $currentCategory = $tree->getById($idCategory); $arr = array(); while ($currentCategory != null) { $arr[$currentCategory->name] = $currentCategory->getUrl(); $currentCategory = $currentCategory->getParent(); } if (count($arr) > 0) { Yii::app()->controller->breadcrumbs = array_merge(Yii::app()->controller->breadcrumbs, array_reverse($arr)); } } }
public function run() { $this->render('productCategoryWidget', array('categories' => ProductCategory::model()->findAll(array('condition' => 'level = 2', 'order' => 'lft ASC')))); }
public function loadProducts($id) { $model = ProductCategory::model()->findByPk($id); if (!$model) { throw new CHttpException(404, 'Продукция не найдена.'); } return $model; }
</h1> </div><!--/.page-header--> <div class="row-fluid"> <div class="span12"> <a href="<?php echo PIUrl::createUrl('/admin/product/create/', array('id' => $id)); ?> " class="btn btn-primary"> <i class="icon-ok bigger-110"></i> <?php echo translate('Thêm'); ?> </a> <form method="post"> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'product-grid', 'dataProvider' => $model->search($id), 'filter' => $model, 'htmlOptions' => array(), 'itemsCssClass' => 'table table-striped table-bordered table-hover', 'emptyText' => 'Không có kết quả hiển thị', 'selectableRows' => 2, 'summaryText' => 'Hiển thị {start} - {end} của {count} kết quả ', 'columns' => array(array('id' => 'id', 'class' => 'CCheckBoxColumn'), array('header' => 'STT', 'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)'), 'image' => array('name' => 'image', 'type' => 'raw', 'filter' => false, 'value' => 'CHtml::image(getImage($data->image,"80", "60" ))', 'htmlOptions' => array("class" => "image")), 'name', 'productCategory.name' => array('name' => 'product_category_id', 'type' => 'raw', 'value' => 'isset($data->productCategory->name) ? $data->productCategory->name : ""', 'filter' => CHtml::dropDownList('Product[product_category_id]', 0, ProductCategory::model()->getDataCategories($id))), 'price' => array('name' => 'price', 'type' => 'raw', 'filter' => false, 'value' => '$data->price'), 'created' => array('name' => 'created', 'type' => 'raw', 'filter' => false, 'value' => 'date(Yii::app()->params["date"],$data->created)'), 'updated' => array('name' => 'updated', 'type' => 'raw', 'filter' => false, 'value' => '($data->updated != "") ? date(Yii::app()->params["date"],$data->updated) : "" '), array('header' => '<input type="button" name="deleteAll" class="deleteAll btn btn-mini btn-danger icon-trash bigger-120" value="Xóa" />', 'class' => 'CButtonColumn', 'template' => '{update}{delete}', 'buttons' => array('update' => array('options' => array('class' => 'btn btn-mini btn-info icon-edit bigger-120', 'title' => 'Sửa tin tức'), 'imageUrl' => false, 'label' => false, 'url' => 'PIUrl::createUrl("/admin/product/update", array("id"=>$data->id, "type"=>' . $id . '))'), 'delete' => array('label' => false, 'options' => array('class' => 'btn btn-mini btn-danger icon-trash bigger-120', 'title' => 'Xóa tin tức'), 'imageUrl' => false)), 'deleteConfirmation' => 'Bạn có muốn xóa sản phẩm này không?')))); ?> </form> </div><!--/.span--> </div><!--/.row-fluid--> </div><!--/.page-content--> </div><!--/.main-content--> <style> .grid-view .filters input, .grid-view .filters select { width: 92%; } .image img{ width:80px; height:60px; } .btn-info{margin-right:3px;}
public function actionBatchDelete() { if (Yii::app()->user->checkAccess('deleteProductCategory') == false) { throw new CHttpException(403); } $idList = Yii::app()->request->getPost('category_id', array()); if (count($idList) > 0) { $criteria = new CDbCriteria(); $criteria->addInCondition('category_id', $idList); $categorys = ProductCategory::model()->findAll($criteria); $flag = 0; foreach ($categorys as $category) { if ($category->delete()) { $flag++; } } if ($flag > 0) { $this->setFlashMessage('产品类型已成功删除'); } else { $this->setFlashMessage('产品类型删除失败', 'warn'); } } else { $this->setFlashMessage('没有记录被选中', 'warn'); } $this->redirect(array('index')); }
public function actionAddProductAll() { $companyId = Yii::app()->request->getParam('companyId', '0'); $typeId = Yii::app()->request->getParam('typeId', '0'); $orderId = Yii::app()->request->getParam('orderId', '0'); $criteria = new CDbCriteria(); $criteria->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteria->order = ' order_num asc '; $categories = ProductCategory::model()->findAll($criteria); $criteriaps = new CDbCriteria(); $criteriaps->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteriaps->with = "productsetdetail"; $criteriaps->order = ' t.lid asc '; $productSets = ProductSet::model()->findAll($criteriaps); $criteriap = new CDbCriteria(); $criteriap->condition = 'delete_flag=0 and t.dpid=' . $companyId; // and is_show=1 $criteriap->order = ' t.category_id asc,t.lid asc '; $products = Product::model()->findAll($criteriap); $productidnameArr = array(); foreach ($products as $product) { $productidnameArr[$product->lid] = $product->product_name; } //var_dump($productidnameArr);exit; if (Yii::app()->request->isPostRequest) { Until::validOperate($companyId, $this); //$isset = Yii::app()->request->getPost('isset',0); //$setid = Yii::app()->request->getParam('setid',0); $selectlist = Yii::app()->request->getPost('selectproductlist', '0'); $db = Yii::app()->db; $transaction = $db->beginTransaction(); try { if (strlen($selectlist) > 10) { $productlist = explode(';', $selectlist); foreach ($productlist as $product) { //var_dump($productId); $productUnit = explode(',', $product); $sorderProduct = new OrderProduct(); $sorderProduct->dpid = $companyId; $sorderProduct->delete_flag = '0'; $sorderProduct->product_order_status = '0'; $sorderProduct->set_id = $productUnit[0]; $sorderProduct->main_id = '0000000000'; $sorderProduct->order_id = $orderId; $sorderProduct->create_at = date('Y-m-d H:i:s', time()); $sorderProduct->product_id = $productUnit[1]; $sorderProduct->amount = $productUnit[2]; $sorderProduct->zhiamount = $productUnit[3]; $sorderProduct->price = $productUnit[4]; $sorderProduct->is_giving = $productUnit[5]; $se = new Sequence("order_product"); $sorderProduct->lid = $se->nextval(); //var_dump($orderProduct);exit; $sorderProduct->save(); } } $transaction->commit(); Yii::app()->user->setFlash('success', yii::t('app', '添加单品成功')); $this->redirect(array('defaultOrder/order', 'companyId' => $this->companyId, 'orderId' => $orderId, 'typeId' => $typeId)); } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 //echo json_encode(array('status'=>0,'message'=>'换台失败')); Yii::app()->user->setFlash('success', yii::t('app', '添加失败')); return false; } //var_dump($orderProduct);exit; //第一个菜需要更新订单状态。。。。 //添加产品时,还可以添加套餐。。。 } // var_dump($productidnameArr);exit; $this->renderPartial('addproductall', array('orderId' => $orderId, 'categories' => $categories, 'products' => $products, 'productSets' => $productSets, 'typeId' => $typeId, "pn" => $productidnameArr)); }
public function run() { $currentMenuId = Yii::app()->controller->productCategoryId; $arr[0] = $currentMenuId; $currProductCategory = ProductCategory::model()->localized()->findByPk($currentMenuId); while ($currProductCategory && $currProductCategory->parent) { array_push($arr, $currProductCategory->parent->product_category_id); $currProductCategory = $currProductCategory->parent; } foreach (ProductCategory::model()->localized()->findAll(array('condition' => 'parent_id=0', 'order' => 'sort_order asc')) as $i => $model) { $i++; // 是否有下级分类产品 $hasChildrenProduct = 0; $children = $model->getChildren(); foreach ($children as $child) { if ($child->is_released == 1) { $count = Product::model()->localized()->count('product_category_id=' . $child->getPrimaryKey()); if ($count) { $hasChildrenProduct = 1; break; } } } $items[$i] = array('label' => $model->title, 'url' => $hasChildrenProduct ? Yii::app()->createUrl('product/detail', array('id' => $model->primaryKey)) : Yii::app()->createUrl('product/series', array('id' => $model->primaryKey)), 'active' => $currentMenuId && in_array($model->getPrimaryKey(), $arr), 'itemOptions' => null); if ($count = ProductCategory::model()->localized()->count('parent_id=' . $model->getPrimaryKey())) { $items2 = array(); foreach (ProductCategory::model()->localized()->findAll(array('condition' => 'parent_id=' . $model->getPrimaryKey(), 'order' => 'sort_order asc')) as $i2 => $model2) { // 当前目录是否有产品 $productCount = Product::model()->localized()->count('product_category_id=' . $model2->getPrimaryKey()); // 是否有下级分类产品 $hasChildrenProduct = 0; $children = $model2->getChildren(); foreach ($children as $child) { if ($child->is_released == 1) { $count = Product::model()->localized()->count('product_category_id=' . $child->getPrimaryKey()); if ($count) { $hasChildrenProduct = 1; break; } } } if ($productCount == 0 && $hasChildrenProduct == 0) { continue; } $items2[$i2] = array('label' => $model2->title, 'url' => Yii::app()->createUrl('product/category', array('id' => $model->primaryKey)), 'active' => $currentMenuId && in_array($model2->getPrimaryKey(), $arr), 'itemOptions' => array('class' => 'probar')); if ($count = ProductCategory::model()->localized()->count('parent_id=' . $model2->getPrimaryKey())) { $items3 = array(); foreach (ProductCategory::model()->localized()->findAll(array('condition' => 'parent_id=' . $model2->getPrimaryKey(), 'order' => 'sort_order asc')) as $i3 => $model3) { // 当前目录是否有产品 $productCount = Product::model()->localized()->count('product_category_id=' . $model3->getPrimaryKey()); // 是否有下级分类产品 $hasChildrenProduct = 0; $children = $model3->getChildren(); foreach ($children as $child) { if ($child->is_released == 1) { $count = Product::model()->localized()->count('product_category_id=' . $child->getPrimaryKey()); if ($count) { $hasChildrenProduct = 1; break; } } } if ($productCount == 0 && $hasChildrenProduct == 0) { continue; } $items3[$i3] = array('label' => $model3->title, 'url' => Yii::app()->createUrl('product/series', array('id' => $model3->primaryKey)), 'active' => $currentMenuId && in_array($model3->getPrimaryKey(), $arr), 'itemOptions' => array('class' => 'active')); if ($count = ProductCategory::model()->localized()->count('parent_id=' . $model3->getPrimaryKey())) { $items4 = array(); foreach (ProductCategory::model()->localized()->findAll(array('condition' => 'parent_id=' . $model3->getPrimaryKey(), 'order' => 'sort_order asc')) as $i4 => $model4) { $items4[$i4] = array('label' => $model4->title, 'url' => Yii::app()->createUrl('product/series', array('id' => $model4->primaryKey)), 'active' => $currentMenuId && in_array($model4->getPrimaryKey(), $arr), 'itemOptions' => array('class' => 'active')); } $items3[$i3]['items'] = $items4; } } $items2[$i2]['items'] = $items3; } } $items[$i]['items'] = $items2; } } $title = Page::model()->localized()->findByPk(4)->title; $this->render('productSidebar', array('title' => $title, 'items' => $items)); }
<?php echo Helper::fieldTips('如果你已知道数据编号,可用 #编号 来搜索数据,如:#12'); ?> <?php echo CHtml::endForm(); ?> </div> <div class="clearfix"> <?php echo CHtml::form(array('batchDelete'), 'post', array('onsubmit' => 'batchDelete("确认要删除选中数据吗?", this, "category_id[]"); return false;')); ?> <?php $this->widget('zii.widgets.grid.CGridView', array('pager' => array('cssFile' => false), 'cssFile' => false, 'htmlOptions' => array('class' => 'list-view'), 'itemsCssClass' => 'list tree-table', 'loadingCssClass' => 'list-view-loading', 'dataProvider' => $dataProvider, 'selectableRows' => 2, 'columns' => array(array('class' => 'CCheckBoxColumn', 'id' => 'category_id', 'headerHtmlOptions' => array('style' => 'width:20px;'), 'htmlOptions' => array('align' => 'center')), array('name' => 'category_id', 'headerHtmlOptions' => array('style' => 'width:80px;'), 'htmlOptions' => array('align' => 'center')), array('name' => 'name', 'value' => '$data->getI18nColumn("name", true)', 'type' => 'html'), array('name' => 'parent_id', 'value' => '$data->parent_id > 0 && empty($data->childrenCount) == false ? $data->childrenCount->name : "顶级分类"', 'headerHtmlOptions' => array('style' => 'width:200px;'), 'htmlOptions' => array('align' => 'center')), array('name' => 'brand_name', 'value' => '$data->brand_name', 'headerHtmlOptions' => array('style' => 'width:200px;'), 'htmlOptions' => array('align' => 'center')), array('class' => 'CButtonColumn', 'header' => ProductCategory::model()->getAttributeLabel('sort_order'), 'headerHtmlOptions' => array('style' => 'width:100px;'), 'htmlOptions' => array('align' => 'center'), 'template' => '{sort_first} {sort_previous} {sort_next} {sort_last} {sort_specify}', 'buttons' => array('sort_first' => array('label' => '置顶', 'url' => 'array("sortFirst", "id" => $data->primaryKey)', 'click' => 'function(){ Sort.toFirst(this); return false; }', 'imageUrl' => 'image/sort_first.png'), 'sort_previous' => array('label' => '向上', 'url' => 'array("sortPrevious", "id" => $data->primaryKey)', 'click' => 'function(){ Sort.toPrevious(this); return false; }', 'imageUrl' => 'image/sort_previous.png'), 'sort_next' => array('label' => '向下', 'url' => 'array("sortNext", "id" => $data->primaryKey)', 'click' => 'function(){ Sort.toNext(this); return false; }', 'imageUrl' => 'image/sort_next.png'), 'sort_last' => array('label' => '置低', 'url' => 'array("sortLast", "id" => $data->primaryKey)', 'click' => 'function(){ Sort.toLast(this); return false; }', 'imageUrl' => 'image/sort_last.png'), 'sort_specify' => array('label' => '指定位置', 'url' => 'array("sortSpecify", "id" => $data->primaryKey)', 'click' => 'function(){ Sort.toSpecify(this); return false; }', 'imageUrl' => 'image/sort_specify.png')), 'visible' => Yii::app()->user->checkAccess('updateProductCategory')), array('name' => 'sort_order', 'header' => ProductCategory::model()->getAttributeLabel('sort_order') . '2', 'headerHtmlOptions' => array('style' => 'width:90px;'), 'htmlOptions' => array('align' => 'center'), 'value' => 'CHtml::textField("sort_order_" . $data->primaryKey, $data->sort_order, array("class" => "sort-field"))', 'type' => 'raw', 'visible' => Yii::app()->user->checkAccess('updateProductCategory')), array('class' => 'CButtonColumn', 'header' => '操作', 'headerHtmlOptions' => array('style' => 'width:100px;'), 'htmlOptions' => array('align' => 'center'), 'template' => '{update} {delete}', 'buttons' => array('update' => array('url' => 'array("update", "id" => $data->primaryKey, "return_url" => Yii::app()->request->url)', 'visible' => 'Yii::app()->user->checkAccess("updateProductCategory")'), 'delete' => array('visible' => 'Yii::app()->user->checkAccess("deleteProductCategory")')))))); ?> <?php if (Yii::app()->user->checkAccess('deleteProductCategory')) { ?> <input type="submit" value="删除选中项" /> <?php } ?> <?php echo CHtml::endForm(); ?> </div>
public function loadModel($id) { $model = ProductCategory::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'Запись не найдена.'); } return $model; }
public function actionDelete() { $id = Yii::app()->request->getParam('id'); Until::isUpdateValid(array($id), $this->companyId, $this); //0,表示企业任何时候都在云端更新。 $model = ProductCategory::model()->find('lid=:id and dpid=:companyId', array(':id' => $id, ':companyId' => $this->companyId)); //var_dump($id, $this->companyId,$model);exit; if ($model) { $model->deleteCategory(); Yii::app()->user->setFlash('success', yii::t('app', '删除成功!')); } $this->redirect(array('productCategory/index', 'companyId' => $this->companyId, 'id' => $model->pid)); }
protected function productUpdate($model) { $id = $model->id; ProductCategory::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); if (!empty($model->categories)) { foreach ($model->categories as $catid) { $productCategories = new ProductCategory(); $productCategories->product_id = $model->id; $productCategories->category_id = $catid; $productCategories->save(); } } ProductRelated::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); if (!empty($model->relatedA)) { foreach ($model->relatedA as $rid) { $productRelations = new ProductRelated(); $productRelations->product_id = $id; $productRelations->related_id = $rid; $productRelations->save(); } } ProductStore::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); if (!empty($model->stores)) { foreach ($model->stores as $sid) { $productStores = new ProductStore(); $productStores->product_id = $id; $productStores->store_id = $sid; $productStores->save(); } } $this->deleteImages($model); $productImages = Yii::app()->user->getState('product_images'); if (!empty($productImages)) { $this->addImages($model->id, 'ProductImage', 'product_images', 'Product'); } //This needs to be updated, you cant delete ProductOption::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); ProductOptionValue::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); foreach ($this->_productoption as $productoption) { $optionModel = $productoption[0]; $valueModel = $productoption[1]; $optionModel->product_id = $id; $optionModel->save(); foreach ($valueModel as $value) { $value->product_option_id = $optionModel->id; $value->product_id = $id; $value->option_id = $optionModel->option_id; $value->save(); } } ProductAttribute::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); if (!empty($this->_productattribute)) { foreach ($this->_productattribute as $productattribute) { $productattribute->product_id = $id; $productattribute->save(); } } ProductDiscount::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); if (!empty($this->_productdiscount)) { foreach ($this->_productdiscount as $productdiscount) { $productdiscount->product_id = $id; //$productdiscount->date_start = date('Y-m-d',strtotime($productdiscount->date_start)); //$productdiscount->date_end = date('Y-m-d',strtotime($productdiscount->date_end)); $productdiscount->save(); } } ProductSpecial::model()->deleteAll('product_id=:product_id', array(':product_id' => $id)); if (!empty($this->_productspecial)) { foreach ($this->_productspecial as $productspecial) { $productspecial->product_id = $id; //$productspecial->date_start = date('Y-m-d',strtotime($productspecial->date_start)); //$productspecial->date_end = date('Y-m-d',strtotime($productspecial->date_end)); $productspecial->save(); } } }
public static function getCategoryList($companyId) { $categories = ProductCategory::model()->findAll('delete_flag=0 and dpid=:companyId', array(':companyId' => $companyId)); //var_dump($categories);exit; return CHtml::listData($categories, 'lid', 'category_name'); }
public function actionUpdate($id = null, $type = null) { $model = Product::model()->findByPk($id); $flag = 0; $image_old = $model->attributes['image']; if (!empty($_POST['Product'])) { if (!empty(CUploadedFile::getInstance($model, 'image')->name)) { $image_old = $model->attributes['image']; $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image_old); if (file_exists($path) && !empty($image_old)) { unlink($path); } $model->attributes = $_POST['Product']; $model->image = CUploadedFile::getInstance($model, 'image'); $image = $model->image; $imageType = explode('.', $model->image->name); $imageType = $imageType[count($imageType) - 1]; $imageName = md5(uniqid()) . '.' . $imageType; $model->image = $imageName; $images_path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName; $flag = 1; } else { $model->attributes = $_POST['Product']; $model->image = $image_old; } $model->type = $id; $model->updated = time(); $model->alias = alias($_POST['Product']['name']); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Sửa sản phẩm thành công.')); if ($flag == 1) { $image->saveAs($images_path); } // Them hinh anh $arrImage = CUploadedFile::getInstancesByName('images'); foreach ($arrImage as $image) { $modelImage = new ProductImage(); $modelImage->product_id = $model->id; $nameImage = explode(".", $image->name); $type = end($nameImage); $modelImage->image = md5(uniqid()) . '.' . $type; $modelImage->created = time(); $path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $modelImage->image; $image->saveAs($path); $modelImage->save(); } $this->redirect(PIUrl::createUrl('/admin/Product/', array('id' => $id))); } } $dataCategories = ProductCategory::model()->getDataCategories($type); $criteria = new CDBCriteria(); $criteria->addCondition("product_id = {$id}"); $arrProductImage = ProductImage::model()->findAll($criteria); $this->render('update', array('model' => $model, 'dataCategories' => $dataCategories, 'arrProductImage' => $arrProductImage)); }
public function actionDelete($id) { ProductCategory::model()->findByPk($id)->delete(); $this->redirect(Yii::app()->createUrl('/category/index')); }
private function getCategories() { $criteria = new CDbCriteria(); $criteria->with = 'company'; $criteria->condition = 't.delete_flag=0 and t.dpid=' . $this->companyId; $criteria->order = ' tree,t.lid asc '; $models = ProductCategory::model()->findAll($criteria); //return CHtml::listData($models, 'lid', 'category_name','pid'); $options = array(); $optionsReturn = array(yii::t('app', '--请选择分类--')); if ($models) { foreach ($models as $model) { if ($model->pid == '0') { $options[$model->lid] = array(); } else { $options[$model->pid][$model->lid] = $model->category_name; } } //var_dump($options);exit; } foreach ($options as $k => $v) { //var_dump($k,$v);exit; $model = ProductCategory::model()->find('t.lid = :lid and dpid=:dpid', array(':lid' => $k, ':dpid' => $this->companyId)); $optionsReturn[$model->category_name] = $v; } return $optionsReturn; }
public function actionIndex() { // $companyId = Yii::app()->request->getParam('companyId', '0'); $typeId = Yii::app()->request->getParam('typeId', '0'); $siteTypes = SiteClass::getTypes($this->companyId); if (empty($siteTypes)) { $typeId = 'tempsite'; } if ($typeId != 'tempsite') { $typeKeys = array_keys($siteTypes); $typeId = array_search($typeId, $typeKeys) ? $typeId : $typeKeys[0]; } $criteria = new CDbCriteria(); $criteria->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteria->order = ' pid,lid '; $categories = ProductCategory::model()->findAll($criteria); // var_dump($categories);exit; $criteriaps = new CDbCriteria(); $criteriaps->condition = 't.delete_flag=0 and t.dpid=' . $companyId; $criteriaps->with = "productsetdetail"; $criteriaps->order = ' t.lid asc '; $productSets = ProductSet::model()->findAll($criteriaps); $setprice = array(); foreach ($productSets as $productSet) { $sqlsetsum = "select sum(price * number) as tprice from nb_product_set_detail where dpid=" . $companyId . " and set_id=" . $productSet->lid . " and is_select=1 and delete_flag=0"; $nowval = Yii::app()->db->createCommand($sqlsetsum)->queryScalar(); $setprice[$productSet->lid] = empty($nowval) ? "0.00" : $nowval; } //var_dump($setprice);exit; $criteriap = new CDbCriteria(); $criteriap->condition = 'delete_flag=0 and t.dpid=' . $companyId; // and is_show=1 $criteriap->order = ' t.category_id asc,t.lid asc '; $products = Product::model()->findAll($criteriap); //var_dump($products);exit; $productidnameArr = array(); foreach ($products as $product) { $productidnameArr[$product->lid] = $product->product_name; } //var_dump($productidnameArr);exit; $this->render('indexall', array('siteTypes' => $siteTypes, 'typeId' => $typeId, "categories" => $categories, "productSets" => $productSets, 'setprice' => $setprice, "products" => $products, "pn" => $productidnameArr)); }