The followings are the available columns in table 'StoreCategory':
Inheritance: extends BaseModel
コード例 #1
0
ファイル: AttributesRepository.php プロジェクト: yupe/yupe
 /**
  * @param StoreCategory $category
  * @return Attribute[]
  */
 public function getForCategory(StoreCategory $category)
 {
     $criteria = new CDbCriteria(['condition' => 't.is_filter = 1 AND t.type != :type', 'params' => [':type' => Attribute::TYPE_TEXT], 'join' => 'LEFT JOIN {{store_type_attribute}} ON t.id = {{store_type_attribute}}.attribute_id
                    LEFT JOIN {{store_type}} ON {{store_type_attribute}}.type_id = {{store_type}}.id
                    LEFT JOIN {{store_product}} AS products ON products.type_id = {{store_type}}.id', 'distinct' => true]);
     $categories = $category->getChildsArray();
     if (!empty($categories)) {
         $categoriesCriteria = new CDbCriteria(['condition' => 'products.category_id = :category', 'params' => [':category' => $category->id]]);
         $categoriesCriteria->addInCondition('products.category_id', $categories, 'OR');
         $criteria->mergeWith($categoriesCriteria, 'AND');
     } else {
         $criteria->addCondition('products.category_id = :category');
         $criteria->params[':category'] = $category->id;
     }
     return Attribute::model()->findAll($criteria);
 }
コード例 #2
0
 public function run($args)
 {
     mb_internal_encoding("UTF-8");
     mb_regex_encoding("UTF-8");
     Yii::app()->setImport(['application.modules.store.models.*']);
     $models = StoreCategory::model()->findAll();
     foreach ($models as $model) {
         $res = preg_replace('/\\s\\s+/', ' ', $model->name_ru);
         if ($res !== FALSE) {
             if (mb_strlen($res) !== mb_strlen($model->name_ru)) {
                 $model->name_ru = $res;
                 $model->update(['name_ru']);
                 print_r($model->id . ' ');
             }
         }
     }
     Yii::import('application.components.spreadsheetReader.SpreadsheetReader');
     $reader = new SpreadsheetReader(Yii::getPathOfAlias('application.components.spreadsheetReader.translates') . '/' . 'site_store_category.ods');
     foreach ($reader as $row) {
         if ($row[0] != 'id') {
             $res = Yii::app()->db->createCommand('
                 UPDATE `site_store_category` SET `name_en`= :row2, `name_zh_cn`= :row3, `name_zh_tw`= :row4 WHERE  `name_ru`= :row1;
             ')->execute([':row1' => $row[1], ':row2' => $row[2], ':row3' => $row[3], ':row4' => $row[4]]);
             print_r($res . ' ' . $row[2] . ' ');
         }
     }
 }
コード例 #3
0
 public function beforeValidate()
 {
     //Сброс значения parent_id в NUll, т.к. от APi приходят нули
     if ($this->parent_id == 0) {
         $this->parent_id = NULL;
     }
     return parent::beforeValidate();
 }
コード例 #4
0
ファイル: CategoryController.php プロジェクト: yupe/yupe
 /**
  * @param $path
  * @throws CHttpException
  */
 public function actionView($path)
 {
     $category = StoreCategory::model()->published()->findByPath($path);
     if (null === $category) {
         throw new CHttpException(404);
     }
     $data = Yii::app()->getRequest()->getQueryString() ? $this->productRepository->getByFilter($this->attributeFilter->getMainAttributesForSearchFromQuery(Yii::app()->getRequest(), [AttributeFilter::MAIN_SEARCH_PARAM_CATEGORY => [$category->id]]), $this->attributeFilter->getTypeAttributesForSearchFromQuery(Yii::app()->getRequest())) : $this->productRepository->getListForCategory($category);
     $this->render('view', ['dataProvider' => $data, 'category' => $category]);
 }
コード例 #5
0
 public function catename($data, $row)
 {
     $cate = StoreCategory::model()->findByAttributes(array('ca_id' => $data->c_id));
     if ($cate != NULL) {
         return ucfirst($cate->ca_name);
     } else {
         return '-';
     }
 }
コード例 #6
0
 public function run()
 {
     $data = StoreCategory::model()->getMenuList(10);
     echo CHtml::openTag('div', ['id' => $this->id]);
     echo CHtml::openTag('ul');
     $this->createHtmlTree($data);
     echo CHtml::closeTag('ul');
     echo CHtml::closeTag('div');
     $options = CJavaScript::encode($this->options);
     Yii::app()->clientScript->registerScript('JsTreeScript', "\n\t\t\t\$('#{$this->id}').jstree({$options});\n\t\t");
 }
コード例 #7
0
ファイル: CatalogController.php プロジェクト: RexGalicie/yupe
 public function actionSearch()
 {
     if (Yii::app()->getRequest()->getQuery('SearchForm')) {
         $form = new SearchForm();
         $form->setAttributes(Yii::app()->getRequest()->getQuery('SearchForm'));
         if ($form->validate()) {
             $category = $form->category ? StoreCategory::model()->findByPk($form->category) : null;
             $this->render('search', ['category' => $category, 'searchForm' => $form, 'dataProvider' => $this->productRepository->search($form->q, $form->category)]);
         }
     }
 }
コード例 #8
0
 public function run($args)
 {
     Yii::app()->setImport(['application.modules.store.models.*']);
     $db = \Yii::app()->db;
     $dump_category = $db->createCommand()->select('t1.id')->from('site_store_category t1')->leftJoin('site_store_category t2', 't1.id = t2.parent_id')->where('t2.id IS NULL')->queryColumn();
     foreach ($dump_category as $category_id) {
         $category = StoreCategory::model()->findByPk($category_id);
         $category->updateFilterData();
     }
     echo 'End';
 }
コード例 #9
0
ファイル: ExportController.php プロジェクト: RexGalicie/yupe
 private function getCategoriesElement()
 {
     $models = StoreCategory::model()->findAll();
     $res = '';
     $res .= CHtml::openTag('categories');
     /* @var $models StoreCategory[] */
     foreach ($models as $model) {
         $res .= CHtml::tag('category', ['id' => $model->id, 'parentId' => $model->parent_id], $model->name);
     }
     $res .= CHtml::closeTag('categories');
     return $res;
 }
コード例 #10
0
 public function actionSearch()
 {
     if (!Yii::app()->getRequest()->getQuery('SearchForm')) {
         throw new CHttpException(404);
     }
     $form = new SearchForm();
     $form->setAttributes(Yii::app()->getRequest()->getQuery('SearchForm'));
     if ($form->validate()) {
         $category = $form->category ? StoreCategory::model()->findByPk($form->category) : null;
         $this->render('search', ['category' => $category, 'searchForm' => $form, 'dataProvider' => $this->productRepository->getByFilter($this->attributeFilter->getMainAttributesForSearchFromQuery(Yii::app()->getRequest(), [AttributeFilter::MAIN_SEARCH_PARAM_NAME => $form->q]), $this->attributeFilter->getEavAttributesForSearchFromQuery(Yii::app()->getRequest()))]);
     }
 }
コード例 #11
0
 public function testLanguageLoad()
 {
     Yii::app()->languageManager->setActive('en');
     $model = StoreCategory::model()->findByPk(1);
     $name = 'root_' . time();
     $model->name = $name;
     $model->saveNode();
     $this->assertTrue($model instanceof StoreCategory);
     $this->assertEquals($model->name, $name);
     Yii::app()->languageManager->setActive('ru');
     $model = StoreCategory::model()->findByPk(1);
     $this->assertEquals($model->name, 'root');
 }
コード例 #12
0
 public function up()
 {
     mb_internal_encoding("UTF-8");
     mb_regex_encoding("UTF-8");
     Yii::app()->setImport(['application.modules.store.models.*']);
     $models = StoreCategory::model()->findAll();
     foreach ($models as $model) {
         //$res = mb_ereg_replace('/\s\s+/', ' ', $model->name_ru);
         $res = preg_replace('/\\s\\s+/', ' ', $model->name_ru);
         if ($res !== FALSE) {
             $model->name_ru = $res;
             $model->update(['name_ru']);
         }
     }
 }
コード例 #13
0
 /**
  * @param $id
  * @throws CHttpException
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         $model = StoreCategory::model()->findByPk($id);
         //Delete if not root node
         if ($model && $model->id != 1) {
             foreach ($model->descendants()->findAll() as $subCategory) {
                 $subCategory->deleteNode();
             }
             $model->deleteNode();
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('create');
         }
     }
 }
コード例 #14
0
 public function actionUpdate($id)
 {
     $breadcrumb = [];
     if (isset($_POST['StoreCategory'])) {
         \StoreCategory::model()->updateByPk($_POST['StoreCategory']['id'], ['name_ru' => $_POST['StoreCategory']['name_ru']]);
         $this->redirect(array('index'));
     }
     $model = \StoreCategory::model()->findByPk($id);
     $StoreCategory = \StoreCategory::model()->findByPk($id);
     $breadcrumb[] = ['url' => $StoreCategory->id, 'name' => $StoreCategory->name];
     while ($StoreCategory->parent_id != null) {
         $StoreCategory = \StoreCategory::model()->findByPk($StoreCategory->parent_id);
         $breadcrumb[] = ['url' => $StoreCategory->id, 'name' => $StoreCategory->name];
     }
     $this->render('update', ['model' => $model, 'breadcrumb' => $breadcrumb]);
     // $this->redirect('index');
 }
コード例 #15
0
 /**
  * Generate store category tree
  *
  * @param string $order
  *
  * @return array
  */
 private static function generateTree($order = 'sort')
 {
     $tree = [];
     $data = StoreCategory::model()->findAll(['order' => $order]);
     foreach ($data as $item) {
         $tree[$item->id] = ['id' => $item->id, 'parent_id' => $item->parent_id, 'name' => $item->name, 'status' => $item->status];
     }
     foreach ($tree as $key => &$value) {
         if (isset($tree[$value['parent_id']])) {
             $tree[$value['parent_id']]['items'][$key] =& $value;
         }
         unset($value);
     }
     $tree = array_filter($tree, function ($value) {
         return $value['parent_id'] == 0;
     });
     Yii::app()->getCache()->set(self::CACHE_CATEGORY_TREE, $tree, 0, new TagsCache(self::CACHE_CATEGORY_TAG));
     return $tree;
 }
コード例 #16
0
 public function actionView($id)
 {
     $model = Export::model()->findByPk($id);
     if (false === $model) {
         throw new CHttpException(404);
     }
     $criteria = new CDbCriteria();
     $criteria->compare('t.status', Product::STATUS_ACTIVE);
     if (!empty($model->categories)) {
         $criteria->addInCondition('t.category_id', (array) $model->categories);
     }
     if (!empty($model->brands)) {
         $criteria->addInCondition('t.producer_id', (array) $model->brands);
     }
     $dataProvider = new CActiveDataProvider('Product', ['criteria' => $criteria]);
     $offers = new CDataProviderIterator($dataProvider, 100);
     ContentType::setHeader(ContentType::TYPE_XML);
     $this->renderPartial('view', ['model' => $model, 'currencies' => Yii::app()->getModule('store')->getCurrencyList(), 'categories' => StoreCategory::model()->published()->findAll(), 'offers' => $offers]);
 }
コード例 #17
0
 /**
  * @static
  * @param $type
  * @param $externalId
  * @param bool $loadModel
  */
 public static function getObject($type, $externalId, $loadModel = true)
 {
     $query = Yii::app()->db->createCommand()->select("*")->from('accounting1c')->where('object_type=:type AND external_id=:externalId', array(':type' => $type, ':externalId' => $externalId))->limit(1)->queryRow();
     if ($query === false) {
         return false;
     }
     if ($loadModel === true && $query['object_id']) {
         switch ($type) {
             case self::OBJECT_TYPE_CATEGORY:
                 return StoreCategory::model()->findByPk($query['object_id']);
                 break;
             case self::OBJECT_TYPE_ATTRIBUTE:
                 return StoreAttribute::model()->findByPk($query['object_id']);
                 break;
             case self::OBJECT_TYPE_PRODUCT:
                 return StoreProduct::model()->findByPk($query['object_id']);
                 break;
         }
     }
     return $query['object_id'];
 }
コード例 #18
0
 public function SetCategoryId($category_id)
 {
     \Yii::import('application.modules.store.models.*');
     \Yii::import('application.modules.cabinet.*');
     //->category_id
     if (empty($category_id)) {
         $category_id = 1;
     }
     $mas = [];
     //$mas[]=$category_id;
     $model = \StoreCategory::model()->findByPk($category_id);
     $mas[] = $model->id;
     while ($model->parent_id != NULL) {
         $mas[] = $model->parent_id;
         $model = \StoreCategory::model()->findByPk($model->parent_id);
         // break;
     }
     switch (count($mas)) {
         case 5:
             $this->category_id_1 = $mas[3];
             $this->category_id_2 = $mas[2];
             $this->category_id_3 = $mas[1];
             $this->category_id_4 = $mas[0];
             break;
         case 4:
             $this->category_id_1 = $mas[2];
             $this->category_id_2 = $mas[1];
             $this->category_id_3 = $mas[0];
             $this->category_id_4 = null;
             break;
         case 3:
             $this->category_id_1 = $mas[1];
             $this->category_id_2 = $mas[0];
             break;
         case 2:
             $this->category_id_1 = $mas[0];
             break;
     }
     return $mas;
 }
コード例 #19
0
 /**
  * @param $slug
  *
  * @return array|mixed|null
  */
 public function getByAlias($slug)
 {
     return StoreCategory::model()->published()->find('slug = :slug', [':slug' => $slug]);
 }
コード例 #20
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 integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = StoreCategory::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #21
0
 protected function getChildrenCategories($category)
 {
     foreach ($category->children as $cat) {
         $this->categories[] = $cat->id;
         $childCat = StoreCategory::model()->findByPk($cat->id);
         if (!empty($childCat->children)) {
             $this->getChildrenCategories($childCat);
         }
     }
     return $this->categories;
 }
コード例 #22
0
ファイル: _sidebar.php プロジェクト: kolbensky/rybolove
	<?php 
$this->beginWidget('zii.widgets.jui.CJuiButton', array('buttonType' => 'buttonset', 'name' => 'tree-set', 'htmlOptions' => array('style' => 'padding-top:2px;')));
$this->widget('zii.widgets.jui.CJuiButton', array('name' => 'button1', 'buttonType' => 'button', 'caption' => Yii::t('StoreModule.admin', 'Развернуть все'), 'onclick' => 'js:function(){
				 $("#StoreCategoryTreeFilter").jstree("open_all");
			}', 'options' => array('text' => false, 'icons' => array('primary' => 'ui-icon-triangle-1-s'))));
$this->widget('zii.widgets.jui.CJuiButton', array('name' => 'button12', 'buttonType' => 'button', 'caption' => Yii::t('StoreModule.admin', 'Свернуть все'), 'onclick' => 'js:function(){
				 $("#StoreCategoryTreeFilter").jstree("close_all");
				 $("#StoreCategoryTreeFilter").jstree("open_node", "#StoreCategoryTreeFilterNode_1", false, true);
			}', 'options' => array('text' => false, 'icons' => array('primary' => 'ui-icon-triangle-1-n'))));
$this->endWidget();
?>

</div>

<div style="clear: both;"></div>

<?php 
// Create jstree to filter products
$this->widget('ext.jstree.SJsTree', array('id' => 'StoreCategoryTreeFilter', 'data' => StoreCategoryNode::fromArray(StoreCategory::model()->findAllByPk(1), array('displayCount' => true)), 'options' => array('core' => array('initially_open' => 'StoreCategoryTreeFilterNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search'), 'cookies' => array('save_selected' => false))));
// Category id to select in sidebar.
$activeCategoryId = Yii::app()->request->getQuery('category', 0);
if (is_array($activeCategoryId)) {
    $activeCategoryId = 0;
}
Yii::app()->getClientScript()->registerScript('insertAllCategory', '
$("#StoreCategoryTreeFilter").bind("loaded.jstree", function (event, data) {
	$(this).jstree("create",-1,false,{attr:{id:"StoreCategoryTreeFilterNode_0"}, data:{title:"' . Yii::t('StoreModule.admin', 'Все категории') . '"}},false,true);
	$(this).jstree("select_node","#StoreCategoryTreeFilterNode_' . $activeCategoryId . '");
});
');
Yii::app()->getClientScript()->registerCss("StoreCategoryTreeStyles", "\n\t#StoreCategoryTree { width:90% }\n\t#StoreCategoryTreeFilter {width: 255px}\n");
コード例 #23
0
ファイル: CsvImporter.php プロジェクト: kolbensky/rybolove
 /**
  * Get category id by path. If category not exits it will new one.
  * @param $path string Main/Music/Rock
  * @return integer category id
  */
 protected function getCategoryByPath($path)
 {
     if (isset($this->categoriesPathCache[$path])) {
         return $this->categoriesPathCache[$path];
     }
     if ($this->rootCategory === null) {
         $this->rootCategory = StoreCategory::model()->findByPk(1);
     }
     $result = preg_split($this->subCategoryPattern, $path, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     $result = array_map('stripcslashes', $result);
     $parent = $this->rootCategory;
     $level = 2;
     // Level 1 is only root
     foreach ($result as $name) {
         $cr = new CDbCriteria();
         $cr->with = array('cat_translate');
         $cr->compare('cat_translate.name', $name);
         $model = StoreCategory::model()->find($cr);
         if (!$model) {
             $model = new StoreCategory();
             $model->name = $name;
             $model->appendTo($parent);
         }
         $parent = $model;
         $level++;
     }
     // Cache category id
     $this->categoriesPathCache[$path] = $model->id;
     if (isset($model)) {
         return $model->id;
     }
     return 1;
     // root category
 }
コード例 #24
0
 /**
  * @return StoreCategory
  */
 public function getRootCategory()
 {
     if ($this->_rootCategory) {
         return $this->_rootCategory;
     }
     $this->_rootCategory = StoreCategory::model()->findByPk(1);
     return $this->_rootCategory;
 }
コード例 #25
0
ファイル: StoreImage.php プロジェクト: alextravin/yupe
 /**
  * @param StoreCategory $category
  * @param int $width
  * @param int $height
  * @param bool|true $crop
  * @return mixed
  */
 public static function category(StoreCategory $category, $width = 0, $height = 0, $crop = true)
 {
     return $category->getImageUrl($width, $height, $crop, static::getDefaultImage());
 }
コード例 #26
0
ファイル: ProductRepository.php プロジェクト: yupe/yupe
 /**
  * @param StoreCategory $category
  * @param bool $withChild
  * @param null $limit
  * @return CActiveDataProvider
  */
 public function getListForCategory(StoreCategory $category, $withChild = true, $limit = null)
 {
     $categories = [];
     if (true === $withChild) {
         $categories = $category->getChildsArray();
     }
     $categories[] = $category->id;
     $criteria = new CDbCriteria(['scopes' => ['published']]);
     $builder = new CDbCommandBuilder(Yii::app()->getDb()->getSchema());
     $criteria->addInCondition('t.category_id', array_unique($categories));
     $criteria->addCondition(sprintf('t.id IN (SELECT product_id FROM {{store_product_category}} WHERE %s)', $builder->createInCondition('{{store_product_category}}', 'category_id', $categories)), 'OR');
     $pagination = ['pageSize' => (int) Yii::app()->getModule('store')->itemsPerPage, 'pageVar' => 'page'];
     if ($limit) {
         $pagination = false;
         $criteria->limit = (int) $limit;
     }
     return new CActiveDataProvider(Product::model(), ['criteria' => $criteria, 'pagination' => $pagination, 'sort' => ['sortVar' => 'sort', 'defaultOrder' => 't.position']]);
 }
コード例 #27
0
<?php

$this->widget('ext.jstree.SJsTree', array('id' => 'CategoryAssignTreeDialog', 'data' => StoreCategoryNode::fromArray(StoreCategory::model()->findAllByPk(1))));
?>

<script type="text/javascript">
	$("#CategoryAssignTreeDialog").jstree(<?php 
echo CJavaScript::encode(array('core' => array('initially_open' => 'CategoryAssignTreeDialogNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search', 'checkbox', 'cookies'), 'checkbox' => array('two_state' => true), 'cookies' => array('save_selected' => true)));
?>
);
</script>
コード例 #28
0
 public function actionSearch()
 {
     if (!Yii::app()->getRequest()->getQuery('SearchForm')) {
         throw new CHttpException(404);
     }
     $form = new SearchForm();
     $form->setAttributes(Yii::app()->getRequest()->getQuery('SearchForm'));
     if ($form->validate()) {
         $category = $form->category ? StoreCategory::model()->findByPk($form->category) : null;
         $countries['list'] = [];
         $countries['checked'] = [];
         $price['minValue'] = [];
         $price['maxValue'] = [];
         //$countries['list'] = $this->productRepository->getCountriesFilter($form->q);
         if (Yii::app()->request->getQuery('strana')) {
             foreach (Yii::app()->request->getQuery('strana') as $item) {
                 $countries['checked'] += [$item => $item];
             }
         }
         $price = $this->productRepository->getPricesFilter($form->q);
         if (Yii::app()->request->getQuery('minPrice')) {
             $price['minValue'] = Yii::app()->request->getQuery('minPrice');
         }
         if (Yii::app()->request->getQuery('maxPrice')) {
             $price['maxValue'] = Yii::app()->request->getQuery('maxPrice');
         }
         $this->render('search', ['category' => $category, 'searchForm' => $form, 'price' => $price, 'countries' => $countries, 'dataProvider' => $this->productRepository->getByFilter($this->attributeFilter->getMainAttributesForSearchFromQuery(Yii::app()->getRequest(), [AttributeFilter::MAIN_SEARCH_PARAM_NAME => $form->q]), $this->attributeFilter->getEavAttributesForSearchFromQuery(Yii::app()->getRequest()))]);
     } else {
         if ($form->category) {
             $category = StoreCategory::model()->findByPk($form->category);
             $this->redirect('/store/' . $category->type);
         }
     }
 }
コード例 #29
0
ファイル: _form.php プロジェクト: RonLab1987/43berega
?>
    <span class="required">*</span>
    <?php 
echo Yii::t('StoreModule.store', 'are required');
?>
</div>

<?php 
echo $form->errorSummary($model);
?>


<div class='row'>
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'parent_id', ['widgetOptions' => ['data' => StoreCategory::model()->getFormattedList(), 'htmlOptions' => ['empty' => Yii::t('StoreModule.store', '--no--'), 'encode' => false]]]);
?>
    </div>
    <div class="col-sm-4">
        <?php 
echo $form->dropDownListGroup($model, 'status', ['widgetOptions' => ['data' => $model->getStatusList()]]);
?>
    </div>
</div>
<div class='row'>
    <div class="col-sm-7">
        <?php 
echo $form->textFieldGroup($model, 'name');
?>
    </div>
</div>
コード例 #30
0
ファイル: StoreCategory.php プロジェクト: jackycgq/advanced
 public function getDescendantsId()
 {
     $category = StoreCategory::model()->findByPk($this->id);
     $descendants = $category->descendants()->findAll();
     foreach ($descendants as $descendant) {
         $ids[] = $descendant->id;
     }
     $cid = $ids ? implode(',', $ids) : NULL;
     return $cid;
 }