/** * @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); }
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] . ' '); } } }
public function beforeValidate() { //Сброс значения parent_id в NUll, т.к. от APi приходят нули if ($this->parent_id == 0) { $this->parent_id = NULL; } return parent::beforeValidate(); }
/** * @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]); }
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 '-'; } }
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"); }
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)]); } } }
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'; }
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; }
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()))]); } }
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'); }
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']); } } }
/** * @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'); } } }
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'); }
/** * 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; }
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]); }
/** * @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']; }
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; }
/** * @param $slug * * @return array|mixed|null */ public function getByAlias($slug) { return StoreCategory::model()->published()->find('slug = :slug', [':slug' => $slug]); }
/** * 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; }
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; }
<?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");
/** * 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 }
/** * @return StoreCategory */ public function getRootCategory() { if ($this->_rootCategory) { return $this->_rootCategory; } $this->_rootCategory = StoreCategory::model()->findByPk(1); return $this->_rootCategory; }
/** * @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()); }
/** * @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']]); }
<?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>
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); } } }
?> <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>
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; }