本文整理汇总了PHP中ProductCategory::model方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::model方法的具体用法?PHP ProductCategory::model怎么用?PHP ProductCategory::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actions
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'));
}
示例2: run
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'));
}
示例3: getListItems
/**
* 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;
}
示例4: loadModel
public function loadModel($id)
{
$model = ProductCategory::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例5: actionIndex
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));
}
示例6: actionIndex
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);
}
示例7: getData
/**
* 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;
}
示例8: byBrandOptions
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;
}
示例9: run
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'));
}
示例10: actionDetail
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));
}
示例11: actionIndex
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);
}
}
示例12: run
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;
}
示例13: actionAdmin
/**
* 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));
}
示例14: actionView
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));
}
示例15: setCurrentIdCategory
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));
}
}
}