/**
  * Delete type
  * @param array $id
  */
 public function actionDelete($id = array())
 {
     if (Yii::app()->request->isPostRequest) {
         $model = StoreProductType::model()->findAllByPk($_REQUEST['id']);
         if (!empty($model)) {
             foreach ($model as $m) {
                 if ($m->productsCount > 0) {
                     throw new CHttpException(404, Yii::t('StoreModule.admin', 'Ошибка удаления типа продукта. Он используется в продуктах.'));
                 } else {
                     $m->delete();
                 }
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('index');
         }
     }
 }
Example #2
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 #3
0
    $attributeError = false;
}
if ($model->isNewRecord && !$model->type_id || $attributeError === true) {
    // Display "choose type" form
    echo CHtml::form('', 'get');
    if ($attributeError) {
        echo '<div class="errorSummary"><p>' . Yii::t('StoreModule', 'Необходимо исправить следующие ошибки:') . '</p>
					<ul>
						<li>' . Yii::t('StoreModule.admin', 'Выберите атрибуты для конфигурации продуктов.') . '</li>
					</ul>
			</div>';
    }
    // Type
    echo CHtml::openTag('div', array('class' => 'row'));
    echo CHtml::activeLabel($model, 'type_id');
    echo CHtml::activeDropDownList($model, 'type_id', CHtml::listData(StoreProductType::model()->orderByName()->findAll(), 'id', 'name'));
    echo CHtml::closeTag('div');
    // Use configurations
    echo CHtml::openTag('div', array('class' => 'row'));
    echo CHtml::activeLabel($model, 'use_configurations');
    echo CHtml::activeDropDownList($model, 'use_configurations', array(0 => Yii::t('StoreModule.admin', 'Нет'), 1 => Yii::t('StoreModule.admin', 'Да')));
    echo CHtml::closeTag('div');
    // Available attributes
    echo CHtml::openTag('div', array('id' => 'availableAttributes', 'class' => 'row'));
    echo CHtml::closeTag('div');
    echo CHtml::openTag('div', array('class' => 'row rowInput'));
    echo CHtml::submitButton(Yii::t('StoreModule.admin', 'Создать'), array('name' => false));
    echo CHtml::closeTag('div');
    echo CHtml::endForm();
    $this->widget('application.modules.admin.widgets.schosen.SChosen', array('elements' => array('StoreProduct_type_id')));
} else {
Example #4
0
 /**
  * Get product type by name. If type not exists - create new one.
  * @param $name
  * @return int
  */
 public function getTypeIdByName($name)
 {
     if (isset($this->productTypeCache[$name])) {
         return $this->productTypeCache[$name];
     }
     $model = StoreProductType::model()->findByAttributes(array('name' => $name));
     if (!$model) {
         $model = new StoreProductType();
         $model->name = $name;
         $model->save();
     }
     $this->productTypeCache[$name] = $model->id;
     return $model->id;
 }
 /**
  * Load attributes relative to type and available for product configurations.
  * Used on creating new product.
  */
 public function actionLoadConfigurableOptions()
 {
     // For configurations that  are available only dropdown and radio lists.
     $cr = new CDbCriteria();
     $cr->addInCondition('StoreAttribute.type', array(StoreAttribute::TYPE_DROPDOWN, StoreAttribute::TYPE_RADIO_LIST));
     $type = StoreProductType::model()->with(array('storeAttributes'))->findByPk($_GET['type_id'], $cr);
     $data = array();
     foreach ($type->storeAttributes as $attr) {
         $data[] = array('id' => $attr->id, 'title' => $attr->title);
     }
     echo json_encode($data);
 }