public function run() { // Yii::import('mod.shop.models.ShopCategory'); $items = ShopCategory::model()->cache(Yii::app()->controller->cacheTime)->active()->findByPk(1)->menuArray(); //$items = ShopCategory::model()->active()->findByPk(1); $this->render('render', array('model' => $items)); }
/** * Example for jstree */ public function actionAjaxRoot($id) { header('Content-type: application/json; charset=UTF-8'); $d = ShopCategoryNode::fromArray(ShopCategory::model()->findAllByPk($id)); echo CJSON::encode($this->createHtmlTree($d)); die; }
protected function getMyItems() { $model = ShopCategory::model()->findByPk(1); if ($model) { $result = $model->menuArray(); return $result['items']; } }
public function run() { $items = ShopCategory::model()->language(Yii::app()->language->active)->findByPk($this->id)->menuArray(); if (isset($items)) { $this->render('default', array('items' => $items['items'])); } else { die("ParentCategoriesWidget: не могу найти root category."); } }
/** * Display start page */ public function _loadModel($id) { // Find category if (Yii::app()->hasModule('shop')) { $model = ShopCategory::model()->excludeRoot()->findByPk($id); if (!$model) { throw new CHttpException(404, Yii::t('ShopModule.default', 'NOFIND_CATEGORY')); } return $model; } }
public function run() { Yii::import('mod.shop.models.ShopCategory'); $model = ShopCategory::model()->findByPk(1); if (!$model) { throw new CHttpException(500, 'Error CategoriesWidget'); } else { $result = $model->menuArray(); } $this->render($this->skin, array('result' => $result)); }
public function run() { Yii::import('mod.shop.models.ShopCategory'); $model = ShopCategory::model()->findByPk(1); if (!$model) { Yii::app()->tpl->alert('danger', 'Необходимо добавать категорию'); } else { $result = $model->menuArray(); $this->render($this->skin, array('result' => $result)); } }
public function testLanguageLoad() { Yii::app()->languageManager->setActive('en'); $model = ShopCategory::model()->findByPk(1); $name = 'root_' . time(); $model->name = $name; $model->saveNode(); $this->assertTrue($model instanceof ShopCategory); $this->assertEquals($model->name, $name); Yii::app()->languageManager->setActive('ru'); $model = ShopCategory::model()->findByPk(1); $this->assertEquals($model->name, 'root'); }
public function afterUninstall() { Yii::app()->settings->clear('shop'); Yii::app()->unintallComponent('currency'); $db = Yii::app()->db; $tablesArray = array(ShopTypeAttribute::model()->tableName(), ShopAttribute::model()->tableName(), ShopAttributeOption::model()->tableName(), ShopAttributeOptionTranslate::model()->tableName(), ShopAttributeTranslate::model()->tableName(), ShopCategory::model()->tableName(), ShopCategoryTranslate::model()->tableName(), ShopCurrency::model()->tableName(), ShopManufacturer::model()->tableName(), ShopManufacturerTranslate::model()->tableName(), ShopProduct::model()->tableName(), ShopProductCategoryRef::model()->tableName(), ShopProductImage::model()->tableName(), ShopProductTranslate::model()->tableName(), ShopProductType::model()->tableName(), ShopProductVariant::model()->tableName(), ShopRelatedProduct::model()->tableName(), ShopSuppliers::model()->tableName(), $db->tablePrefix . 'shop_product_attribute_eav', $db->tablePrefix . 'shop_product_configurable_attributes', $db->tablePrefix . 'shop_product_configurations'); foreach ($tablesArray as $table) { $db->createCommand()->dropTable($table); } CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.product'), array('traverseSymlinks' => true)); CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.categories'), array('traverseSymlinks' => true)); CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.manufacturer'), array('traverseSymlinks' => true)); return parent::afterUninstall(); }
/** * @static * @param $type * @param $externalId * @param bool $loadModel */ public static function getObject($type, $externalId, $loadModel = true) { $query = Yii::app()->db->createCommand()->select("*")->from('{{exchange1c}}')->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 ShopCategory::model()->findByPk($query['object_id']); break; case self::OBJECT_TYPE_ATTRIBUTE: return ShopAttribute::model()->findByPk($query['object_id']); break; case self::OBJECT_TYPE_PRODUCT: return ShopProduct::model()->findByPk($query['object_id']); break; } } return $query['object_id']; }
}') ), 'cookies' => array( 'save_selected' => false, ), 'ui' => array( 'initially_select' => array('#ShopCategoryTreeNode_' . (int) Yii::app()->request->getParam('id')) ), 'dnd' => array( 'drag_finish' => 'js:function(data){ //alert(data); }', ), // 'plugins' => array('themes', 'html_data', 'ui', 'dnd', 'crrm', 'search', 'cookies', 'contextmenu'), ), )); */ $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'ShopCategoryTree', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->language(1)->findAllByPk(1), array('switch' => true)), 'options' => array("themes" => array("stripes" => true), 'core' => array('initially_open' => 'ShopCategoryTreeNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'dnd', 'crrm', 'search', 'cookies', 'contextmenu'), 'crrm' => array('move' => array('check_move' => 'js: function(m){ // Disallow categories without parent. // At least each category must have `root` category as parent. var p = this._get_parent(m.r); if (p == -1) return false; return true; }')), 'dnd' => array('drag_finish' => 'js:function(data){ //alert(data); }'), 'cookies' => array('save_selected' => false), 'ui' => array('initially_select' => array('#ShopCategoryTreeNode_' . (int) Yii::app()->request->getParam('id'))), 'contextmenu' => array('items' => array('view' => array('label' => Yii::t('ShopModule.admin', 'Перейти'), 'action' => 'js:function(obj){ CategoryRedirectToFront(obj); }'), 'products' => array('label' => Yii::t('ShopModule.admin', 'Продукты'), 'action' => 'js:function(obj){ CategoryRedirectToAdminProducts(obj); }', 'icon' => 'icon-cart-3'), 'create' => array('label' => Yii::t('app', 'CREATE', 1), 'action' => 'js:function(obj){ CategoryRedirectToParent(obj); }', 'icon' => 'icon-plus'), 'rename' => false, 'remove' => array('label' => Yii::t('app', 'DELETE'), 'icon' => 'icon-trashcan'), 'switch' => array('label' => Yii::t('app', 'SWITCH'), 'icon' => 'icon-eye'), 'ccp' => false))))); ?> </div> </div> </div> </div>
<div class="grid2"> <?php echo Yii::t('ShopModule.admin', 'Поиск:'); ?> </div> <div class="grid10"> <input type="text" onkeyup='$("#ShopCategoryTree").jstree("search", $(this).val());' /> </div> <div class="clear"></div> </div> <?php // Register scripts Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/products.js', CClientScript::POS_END); // Create jstree $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'ShopCategoryTree', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->active()->findAllByPk(1)), 'options' => array('core' => array('initially_open' => 'ShopCategoryTreeNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search', 'checkbox', 'cookies'), 'checkbox' => array('two_state' => true), 'cookies' => array('save_selected' => false)))); // Get categories preset if ($model->type) { $presetCategories = unserialize($model->type->categories_preset); if (!is_array($presetCategories)) { $presetCategories = array(); } } if (isset($_POST['categories']) && !empty($_POST['categories'])) { foreach ($_POST['categories'] as $id) { Yii::app()->getClientScript()->registerScript("checkNode{$id}", "\n\t\t\t\$('#ShopCategoryTree').checkNode({$id});\n\t\t"); } } elseif ($model->isNewRecord && empty($_POST['categories']) && isset($presetCategories)) { foreach ($presetCategories as $id) { if ($model->type && $id === $model->type->main_category) { continue;
/** * @param $id * @throws CHttpException */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { $model = ShopCategory::model()->findByPk($id); //Delete if not root node if ($model && $model->id != 1) { foreach (array_reverse($model->descendants()->findAll()) as $subCategory) { $subCategory->deleteNode(); } $model->deleteNode(); } if (!Yii::app()->request->isAjaxRequest) { $this->redirect('create'); } } }
/** * @return ShopCategory */ public function getRootCategory() { if ($this->_rootCategory) { return $this->_rootCategory; } $this->_rootCategory = ShopCategory::model()->findByPk(1); return $this->_rootCategory; }
/** * Set product categories and main category * @param array $categories ids. * @param integer $main_category Main category id. */ public function setCategories(array $categories, $main_category) { $dontDelete = array(); if (!ShopCategory::model()->countByAttributes(array('id' => $main_category))) { $main_category = 1; } if (!in_array($main_category, $categories)) { array_push($categories, $main_category); } foreach ($categories as $c) { $count = ShopProductCategoryRef::model()->countByAttributes(array('category' => $c, 'product' => $this->id)); if ($count == 0) { $record = new ShopProductCategoryRef(); $record->category = (int) $c; $record->product = $this->id; $record->switch = $this->switch; // new param $record->save(false, false, false); } $dontDelete[] = $c; } // Clear main category ShopProductCategoryRef::model()->updateAll(array('is_main' => 0, 'switch' => $this->switch), 'product=:p', array(':p' => $this->id)); // Set main category ShopProductCategoryRef::model()->updateAll(array('is_main' => 1, 'switch' => $this->switch), 'product=:p AND category=:c', array(':p' => $this->id, ':c' => $main_category)); // Delete not used relations if (sizeof($dontDelete) > 0) { $cr = new CDbCriteria(); $cr->addNotInCondition('category', $dontDelete); ShopProductCategoryRef::model()->deleteAllByAttributes(array('product' => $this->id), $cr); } else { // Delete all relations ShopProductCategoryRef::model()->deleteAllByAttributes(array('product' => $this->id)); } }
<?php $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'CategoryAssignTreeDialog', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->active()->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>
/** * @return array */ public static function flatTree() { $result = array(); $categories = ShopCategory::model()->cache(Yii::app()->controller->cacheTime)->active()->language(Yii::app()->languageManager->active->code)->findAll(array('order' => 'lft')); array_shift($categories); foreach ($categories as $c) { if ($c->level > 2) { $result[$c->id] = str_repeat('--', $c->level - 1) . ' ' . $c->name; } else { $result[$c->id] = ' ' . $c->name; } } return $result; }
/** * Create/update product * @param bool $new * @throws CHttpException */ public function actionUpdate($new = false) { $this->topButtons = false; $config = Yii::app()->settings->get('shop'); if ($new === true) { $model = new ShopProduct(); } else { $model = ShopProduct::model()->language(Yii::app()->language->active)->findByPk($_GET['id']); } if (!$model) { throw new CHttpException(404, Yii::t('ShopModule.admin', 'NO_FOUND_PRODUCT')); } $oldImage = $model->image; if (!$model->isNewRecord) { $this->topButtons = array(array('label' => Yii::t('ShopModule.admin', 'VIEW_PRODUCT'), 'url' => $model->getAbsoluteUrl(), 'htmlOptions' => array('class' => 'btn btn-info', 'target' => '_blank'))); } // Apply use_configurations, configurable_attributes, type_id if (isset($_GET['ShopProduct'])) { $model->attributes = $_GET['ShopProduct']; } $title = $model->isNewRecord ? Yii::t('ShopModule.admin', 'CREATE_PRODUCT') : Yii::t('ShopModule.admin', 'UPDATE_PRODUCT'); if ($model->type) { $title .= ' "' . Html::encode($model->type->name) . '"'; } $this->pageName = $title; $this->breadcrumbs = array(Yii::t('ShopModule.default', 'MODULE_NAME') => array('/admin/shop'), Yii::t('ShopModule.admin', 'PRODUCTS') => $this->createUrl('index'), $this->pageName); // On create new product first display "Choose type" form first. if ($model->isNewRecord && isset($_GET['ShopProduct']['type_id'])) { if (ShopProductType::model()->countByAttributes(array('id' => $model->type_id)) === '0') { throw new CHttpException(404, Yii::t('ShopModule.admin', 'ERR_PRODUCT_TYPE')); } } // Set main category id to have categories drop-down selected value if ($model->mainCategory) { $model->main_category_id = $model->mainCategory->id; } // Or set selected category from type pre-set. if ($model->type && !Yii::app()->request->isPostRequest && $model->isNewRecord) { $model->main_category_id = $model->type->main_category; } // Set configurable attributes on new record if ($model->isNewRecord) { if ($model->use_configurations && isset($_GET['ShopProduct']['configurable_attributes'])) { $model->configurable_attributes = $_GET['ShopProduct']['configurable_attributes']; } } $form = new TabForm($model->getForm(), $model); // $form->positionTabs = 'vertical'; // Set additional tabs $form->additionalTabs[$model->t('TAB_CAT')] = array('content' => $this->renderPartial('_tree', array('model' => $model), true)); $form->additionalTabs[$model->t('TAB_IMG')] = array('content' => $this->renderPartial('_images', array('model' => $model, 'uploadModel' => $uploadModel), true)); $form->additionalTabs[$model->t('TAB_ATTR')] = array('content' => $this->renderPartial('_attributes', array('model' => $model), true)); $form->additionalTabs[$model->t('TAB_REL')] = array('content' => $this->renderPartial('_relatedProducts', array('exclude' => $model->id, 'product' => $model), true)); //if (Yii::app()->getModule('shop')->variations) $form->additionalTabs[Yii::t('ShopModule.admin', 'UPDATE_PRODUCT_TAB_VARIANTS')] = array('content' => $this->renderPartial('_variations', array('model' => $model), true)); // if($this->isInstallModule('comments')){ // $form->additionalTabs['icon-comment'] = array( // 'content' => $this->renderPartial('_comments', array('model' => $model), true) // ); // } /* $form->additionalTabs = array( 'icon-folder-open' => array( 'content' => $this->renderPartial('_tree', array('model' => $model), true) ), 'icon-copy-3' => array( 'content' => $this->renderPartial('_relatedProducts', array('exclude' => $model->id, 'product' => $model), true) ), 'icon-images' => array( 'content' => $this->renderPartial('_images', array('model' => $model, 'uploadModel' => $uploadModel), true) ), 'icon-paragraph-justify' => array( 'content' => $this->renderPartial('_attributes', array('model' => $model), true), 'visible'=>false ), Yii::t('ShopModule.admin', 'Варианты') => array( 'content' => $this->renderPartial('_variations', array('model' => $model), true) ), 'icon-comment' => array( 'content' => $this->renderPartial('_comments', array('model' => $model), true) ), ); */ if ($model->use_configurations) { $form->additionalTabs[Yii::t('ShopModule.admin', 'UPDATE_PRODUCT_TAB_CONF')] = array('content' => $this->renderPartial('_configurations', array('product' => $model), true)); } if (isset($_GET['ShopProduct']['main_category_id'])) { $model->main_category_id = $_GET['ShopProduct']['main_category_id']; } if (Yii::app()->request->isPostRequest) { $model->attributes = $_POST['ShopProduct']; // Handle related products $model->setRelatedProducts(Yii::app()->getRequest()->getPost('RelatedProductId', array())); if ($config['auto_gen_url']) { $model->name = ShopCategory::model()->findByPk($model->main_category_id)->name . ' ' . ShopManufacturer::model()->findByPk($model->manufacturer_id)->name . ' ' . $model->sku; $model->seo_alias = CMS::translit($model->name); // die($model->name.$model->seo_alias); } /* if($model->currency_id){ $currency = ShopCurrency::model()->findByPk($model->currency_id); $convertPrice = $model->price*$currency->rate/$currency->rate_old; $model->price=$convertPrice; } */ if ($model->validate() && $this->validateAttributes($model)) { $model->uploadFile('image', 'webroot.uploads.product', $oldImage); $model->save(); // Process categories $mainCategoryId = 1; if (isset($_POST['ShopProduct']['main_category_id'])) { $mainCategoryId = $_POST['ShopProduct']['main_category_id']; } $model->setCategories(Yii::app()->request->getPost('categories', array()), $mainCategoryId); // Process attributes $this->processAttributes($model); // Process variants $this->processVariants($model); // Process configurations $this->processConfigurations($model); // Handle images $this->handleUploadedImages($model); // Set main image $this->updateMainImage($model); // Update image titles $this->updateImageTitles(); $model->save(false, false); $this->redirect(array('index')); } else { $this->setFlashMessage(Yii::t('ShopModule.admin', 'ERR_PRODUCT_TYPE')); } } $this->render('update', array('model' => $model, 'form' => $form)); }
<?php if ($this->isAjax) { $this->renderPartial('mod.admin.views.layouts._content-top'); echo Html::openTag('div', array('class' => 'wrapper')); } $this->widget('ext.fancybox.Fancybox', array('target' => 'a.overview-image', 'config' => array())); $checkRoot = ShopCategory::model()->findByPk(1); if (!$checkRoot) { // throw new CHttpException(404,'no root'); Yii::app()->tpl->alert('warning', 'Необходимо создать root категорию. <a href="/admin/shop/category/createRoot">создать</a>', false); } else { ?> <div class="row"> <div class="col-lg-8"> <?php Yii::app()->tpl->openWidget(array('title' => $this->pageName, 'htmlOptions' => array('class' => ''))); echo $model->getForm()->tabs(); Yii::app()->tpl->closeWidget(); ?> </div> <div class="col-lg-4"> <?php $this->renderPartial('_categories', array('model' => $model)); ?> </div> </div> <script type="text/javascript">init_translitter('ShopCategory','<?php echo $model->primaryKey;
<div class="form-group"> <div class="col-sm-4"> <label class="control-label" for="tree-search"><?php echo Yii::t('ShopModule.admin', 'Поиск:'); ?> </label> </div> <div class="col-sm-8"> <input id="tree-search" class="form-control" type="text" onkeyup='$("#ShopTypeCategoryTree").jstree("search", $(this).val());' /> </div> </div> <div class="form-group clearfix"> <div class="col-sm-12"> <?php echo Yii::app()->tpl->alert('info', Yii::t('ShopModule.admin', "TYPE_PRODUCT_ALERT_INFO"), false); ?> </div> </div> <?php // Create jstree $cats = ShopCategory::model()->findByPk(1); $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'ShopTypeCategoryTree', 'data' => ShopCategoryNode::fromArray($cats->children()->findAll()), 'options' => array("themes" => array("stripes" => true), 'core' => array('initially_open' => 'ShopTypeCategoryTreeNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search', 'checkbox', 'cookies'), 'checkbox' => array('two_state' => true), 'cookies' => array('save_selected' => false), 'ui' => array('initially_select' => 'ShopTypeCategoryTreeNode_' . $model->main_category)))); // Check tree nodes $categories = unserialize($model->categories_preset); if (!is_array($categories)) { $categories = array(); } foreach ($categories as $id) { Yii::app()->getClientScript()->registerScript("checkNode{$id}", "\n\t\t\$('#ShopTypeCategoryTree').checkNode({$id});\n\t"); }
/** * Load category by url * @param $url * @return ShopCategory * @throws CHttpException */ public function _loadModel($url) { // Find category $model = ShopCategory::model()->cache($this->cacheTime)->excludeRoot()->withFullPath($url)->find(); if (!$model) { throw new CHttpException(404, Yii::t('ShopModule.default', 'NOFIND_CATEGORY')); } return $model; }
<?php if (Yii::app()->hasModule('cart')) { $this->widget('cart.widgets.cart.CartWidget'); } ?> <div class="clr"></div> </div> </div> <div id="header-nav"> <div class="indent"> <div id="cssmenu"> <?php //Yii::import('mod.shop.models.ShopCategory'); $items = ShopCategory::model()->language(Yii::app()->language->active)->findByPk(1); if (isset($items)) { $menuArray = $items->menuArray(); } else { die("не могу найти root category."); } if (isset($menuArray['items'])) { $this->widget('ext.mbmenu.MbMenu', array('cssFile' => Yii::app()->theme->baseUrl . '/assets/css/menu.css', 'htmlOptions' => array('class' => '', 'id' => ''), 'items' => $menuArray['items'])); } ?> </div> <div class="clr"></div> </div>
/** * 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 = ShopCategory::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 = ShopCategory::model()->find($cr); if (!$model) { $model = new ShopCategory(); $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 }
echo CHtml::textField('search', '', array('onkeyup' => '$("#ShopCategoryTreeFilter").jstree("search", $(this).val())')); ?> </div> <?php $this->beginWidget('zii.widgets.jui.CJuiButton', array('buttonType' => 'buttonset', 'name' => 'tree-set', 'htmlOptions' => array('style' => 'padding-top:2px;'))); $this->endWidget(); ?> <div class="clear"></div> <?php // Create jstree to filter products $this->widget('ext.jstree.SJsTree', array('id' => 'ShopCategoryTreeFilter', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->findAllByPk(1), array('displayCount' => true)), 'options' => array('core' => array('initially_open' => 'ShopCategoryTreeFilterNode_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', ' $("#ShopCategoryTreeFilter").bind("loaded.jstree", function (event, data) { $(this).jstree("create",-1,false,{attr:{id:"ShopCategoryTreeFilterNode_0"}, data:{title:"' . Yii::t('ShopModule.admin', 'Все категории') . '"}},false,true); $(this).jstree("select_node","#ShopCategoryTreeFilterNode_' . $activeCategoryId . '"); }); '); Yii::app()->getClientScript()->registerCss("ShopCategoryTreeStyles", "\n\t#ShopCategoryTree { width:90% }\n\t#ShopCategoryTreeFilter {width: 255px}\n"); ?>
/** * Write categories to xm file */ public function renderCategories() { $categories = ShopCategory::model()->excludeRoot()->findAll(); $this->write('<categories>'); foreach ($categories as $c) { $parentId = null; $parent = $c->parent(); //getparent() if ($parent && $parent->id != 1) { $parentId = 'parentId="' . $parent->id . '"'; } $this->write('<category id="' . $c->id . '" ' . $parentId . '>' . CHtml::encode($c->name) . '</category>'); } $this->write('</categories>'); }