Example #1
0
 /**
  * Get active/applied filters to make easier to cancel them.
  */
 public function getActiveFilters()
 {
     // Render links to cancel applied filters like prices, manufacturers, attributes.
     $menuItems = array();
     $manufacturers = array_filter(explode(';', Yii::app()->request->getQuery('manufacturer')));
     $manufacturers = StoreManufacturer::model()->findAllByPk($manufacturers);
     if (Yii::app()->request->getQuery('min_price')) {
         array_push($menuItems, array('label' => Yii::t('StoreModule.core', 'от {minPrice} {c}', array('{minPrice}' => (int) $this->getCurrentMinPrice(), '{c}' => Yii::app()->currency->active->symbol)), 'url' => Yii::app()->request->removeUrlParam('/store/category/view', 'min_price')));
     }
     if (Yii::app()->request->getQuery('max_price')) {
         array_push($menuItems, array('label' => Yii::t('StoreModule.core', 'до {maxPrice} {c}', array('{maxPrice}' => (int) $this->getCurrentMaxPrice(), '{c}' => Yii::app()->currency->active->symbol)), 'url' => Yii::app()->request->removeUrlParam('/store/category/view', 'max_price')));
     }
     if (!empty($manufacturers)) {
         foreach ($manufacturers as $manufacturer) {
             array_push($menuItems, array('label' => $manufacturer->name, 'url' => Yii::app()->request->removeUrlParam('/store/category/view', 'manufacturer', $manufacturer->id)));
         }
     }
     // Process eav attributes
     $activeAttributes = $this->getOwner()->activeAttributes;
     if (!empty($activeAttributes)) {
         foreach ($activeAttributes as $attributeName => $value) {
             if (isset($this->getOwner()->eavAttributes[$attributeName])) {
                 $attribute = $this->getOwner()->eavAttributes[$attributeName];
                 foreach ($attribute->options as $option) {
                     if (isset($activeAttributes[$attribute->name]) && in_array($option->id, $activeAttributes[$attribute->name])) {
                         array_push($menuItems, array('label' => $option->value, 'url' => Yii::app()->request->removeUrlParam('/store/category/view', $attribute->name, $option->id)));
                     }
                 }
             }
         }
     }
     return $menuItems;
 }
 /**
  * Display products by manufacturer
  *
  * @param $url
  * @throws CHttpException
  */
 public function actionIndex($url)
 {
     $this->model = StoreManufacturer::model()->findByAttributes(array('url' => $url));
     if (!$this->model) {
         throw new CHttpException(404, Yii::t('StoreModule.core', 'Производитель не найден.'));
     }
     $query = new StoreProduct(null);
     $query->attachBehaviors($query->behaviors());
     $query->active();
     $query->applyManufacturers($this->model->id);
     $provider = new CActiveDataProvider($query, array('id' => false, 'pagination' => array('pageSize' => $this->allowedPageLimit[0])));
     $this->render('index', array('provider' => $provider));
 }
 /**
  * Delete manufacturer
  * @param array $id
  */
 public function actionDelete($id = array())
 {
     if (Yii::app()->request->isPostRequest) {
         $model = StoreManufacturer::model()->findAllByPk($_REQUEST['id']);
         if (!empty($model)) {
             foreach ($model as $m) {
                 $m->delete();
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('index');
         }
     }
 }
Example #4
0
<?php

/**
 * Display products list
 * @var StoreProduct $model
 **/
$this->pageHeader = Yii::t('StoreModule.admin', 'Продукты');
$this->sidebarContent = $this->renderPartial('_sidebar', array(), true);
// Register scripts
Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/products.index.js', CClientScript::POS_END);
$this->breadcrumbs = array('Home' => $this->createUrl('/admin'), Yii::t('StoreModule.admin', 'Продукты'));
$this->topButtons = $this->widget('application.modules.admin.widgets.SAdminTopButtons', array('template' => array('create', 'showSidebar'), 'elements' => array('create' => array('link' => $this->createUrl('create'), 'title' => Yii::t('StoreModule.admin', 'Создать продукт'), 'options' => array('icons' => array('primary' => 'ui-icon-plus'))), 'showSidebar' => array('link' => '#', 'title' => Yii::t('StoreModule.admin', 'Переключить сайдбар'), 'onclick' => 'js:function(){productToggleSidebar()}', 'options' => array('text' => false, 'icons' => array('primary' => 'ui-icon-triangle-2-e-w'))))));
$this->widget('ext.sgridview.SGridView', array('dataProvider' => $dataProvider, 'id' => 'productsListGrid', 'ajaxUpdate' => true, 'filter' => $model, 'customActions' => array(array('label' => Yii::t('StoreModule.admin', 'Активен'), 'url' => '#', 'linkOptions' => array('onClick' => 'return setProductsStatus(1, this);')), array('label' => Yii::t('StoreModule.admin', 'Не активен'), 'url' => '#', 'linkOptions' => array('onClick' => 'return setProductsStatus(0, this);')), array('label' => Yii::t('StoreModule.admin', 'Назначить категории'), 'url' => '#', 'linkOptions' => array('onClick' => 'return showCategoryAssignWindow(this);')), array('label' => Yii::t('StoreModule.admin', 'Копировать'), 'url' => '#', 'linkOptions' => array('onClick' => 'return showDuplicateProductsWindow(this);'))), 'columns' => array(array('class' => 'CCheckBoxColumn'), array('class' => 'SGridIdColumn', 'name' => 'id'), array('name' => 'name', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->name), array("/store/admin/products/update", "id"=>$data->id))'), 'sku', array('name' => 'price', 'type' => 'raw', 'value' => 'Yii::app()->currency->main->symbol .(string)$data->price." / ".StoreProduct::formatPrice($data->toCurrentCurrency()) . Yii::app()->currency->active->symbol;'), array('name' => 'manufacturer_id', 'type' => 'raw', 'value' => '$data->manufacturer ? CHtml::encode($data->manufacturer->name) : ""', 'filter' => CHtml::listData(StoreManufacturer::model()->orderByName()->findAll(), 'id', 'name')), array('name' => 'type_id', 'type' => 'raw', 'value' => 'CHtml::encode($data->type->name)', 'filter' => CHtml::listData(StoreProductType::model()->findAll(), "id", "name")), array('name' => 'is_active', 'filter' => array(1 => Yii::t('StoreModule.admin', 'Да'), 0 => Yii::t('StoreModule.admin', 'Нет')), 'value' => '$data->is_active ? Yii::t("StoreModule.admin", "Да") : Yii::t("StoreModule.admin", "Нет")'), array('class' => 'CButtonColumn', 'template' => '{update}{delete}'))));
Example #5
0
 /**
  * Find or create manufacturer
  * @param $name
  * @return integer
  */
 public function getManufacturerIdByName($name)
 {
     if (isset($this->manufacturerCache[$name])) {
         return $this->manufacturerCache[$name];
     }
     $cr = new CDbCriteria();
     $cr->with = array('man_translate');
     $cr->compare('man_translate.name', $name);
     $model = StoreManufacturer::model()->find($cr);
     if (!$model) {
         $model = new StoreManufacturer();
         $model->name = $name;
         $model->save();
     }
     $this->manufacturerCache[$name] = $model->id;
     return $model->id;
 }
Example #6
0
<?php

Yii::import('application.modules.store.models.StoreManufacturer');
Yii::import('application.modules.discounts.components.DiscountHelper');
Yii::import('zii.widgets.jui.CJuiDatePicker');
return array('id' => 'discountUpdateForm', 'elements' => array('common_info' => array('type' => 'form', 'title' => Yii::t('DiscountsModule.admin', 'Общая информация'), 'elements' => array('name' => array('type' => 'text'), 'active' => array('type' => 'checkbox'), 'sum' => array('type' => 'text', 'hint' => Yii::t('DiscountsModule.admin', 'Укажите целое число или процент. Например 10%.')), 'start_date' => array('type' => 'CJuiDatePicker', 'options' => array('dateFormat' => 'yy-mm-dd ' . date('H:i:s'))), 'end_date' => array('type' => 'CJuiDatePicker', 'options' => array('dateFormat' => 'yy-mm-dd ' . date('H:i:s'))), 'manufacturers' => array('type' => 'dropdownlist', 'items' => CHtml::listData(StoreManufacturer::model()->orderByName()->findAll(), 'id', 'name'), 'multiple' => 'multiple', 'data-placeholder' => Yii::t('DiscountsModule.admin', 'Выберите производителя')), 'userRoles' => array('type' => 'dropdownlist', 'items' => DiscountHelper::getRoles(), 'multiple' => 'multiple', 'data-placeholder' => Yii::t('DiscountsModule.admin', 'Выберите роли'), 'hint' => Yii::t('DiscountsModule.admin', '<b>Внимание:</b> Скидки для администраторов запрещены.'))))));
Example #7
0
 public function beforeSave()
 {
     if (empty($this->url)) {
         // Create slug
         Yii::import('ext.SlugHelper.SlugHelper');
         $this->url = SlugHelper::run($this->name);
     }
     // Check if url available
     if ($this->isNewRecord) {
         $test = StoreManufacturer::model()->withUrl($this->url)->count();
     } else {
         $test = StoreManufacturer::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id));
     }
     // Create unique url
     if ($test > 0) {
         $this->url .= '-' . date('YmdHis');
     }
     return parent::beforeSave();
 }
Example #8
0
<?php

return array('id' => 'productUpdateForm', 'showErrorSummary' => true, 'enctype' => 'multipart/form-data', 'elements' => array('content' => array('type' => 'form', 'title' => Yii::t('StoreModule.admin', 'Общая информация'), 'elements' => array('name' => array('type' => 'text'), 'price' => array('type' => $this->model->use_configurations ? 'hidden' : 'text'), 'url' => array('type' => 'text'), 'main_category_id' => array('type' => 'dropdownlist', 'items' => StoreCategory::flatTree(), 'empty' => '---'), 'is_active' => array('type' => 'dropdownlist', 'items' => array(1 => Yii::t('StoreModule.admin', 'Да'), 0 => Yii::t('StoreModule.admin', 'Нет')), 'hint' => Yii::t('StoreModule.admin', 'Отображать товар на сайте')), 'manufacturer_id' => array('type' => 'dropdownlist', 'items' => CHtml::listData(StoreManufacturer::model()->findAll(), 'id', 'name'), 'empty' => Yii::t('StoreModule.admin', 'Выберите производителя')), 'short_description' => array('type' => 'SRichTextarea'), 'full_description' => array('type' => 'SRichTextarea'))), 'warehouse' => array('type' => 'form', 'title' => Yii::t('StoreModule.admin', 'Склад'), 'elements' => array('sku' => array('type' => 'text'), 'quantity' => array('type' => 'text'), 'discount' => array('type' => 'text', 'hint' => Yii::t('StoreModule.admin', 'Укажите целое число или процент. Например 10%.')), 'auto_decrease_quantity' => array('type' => 'dropdownlist', 'items' => array(1 => Yii::t('StoreModule.admin', 'Да'), 0 => Yii::t('StoreModule.admin', 'Нет')), 'hint' => Yii::t('StoreModule.admin', 'Автоматически уменьшать количество при создании заказа')), 'availability' => array('type' => 'dropdownlist', 'items' => StoreProduct::getAvailabilityItems()))), 'seo' => array('type' => 'form', 'title' => Yii::t('StoreModule.admin', 'Мета данные'), 'elements' => array('meta_title' => array('type' => 'text'), 'meta_keywords' => array('type' => 'textarea'), 'meta_description' => array('type' => 'textarea'))), 'design' => array('type' => 'form', 'title' => Yii::t('StoreModule.admin', 'Дизайн'), 'elements' => array('layout' => array('type' => 'text', 'hint' => Yii::t('StoreModule.admin', 'Пример: application.views.layouts.file_name')), 'view' => array('type' => 'text', 'hint' => Yii::t('StoreModule.admin', 'Пример: view_name'))))));