Commit ca815dbb by semenov

Merge branch 'master' into 'release'

Master

See merge request !11
parents b49d2c90 f7cd8a2d
Процесс разработки проекта.
==============
1.0.6 (unreleased)
-----------------
*
1.0.5
-----------------
* Глобальные изменения
* Доработка свойств товаров
\ No newline at end of file
......@@ -23,7 +23,7 @@ class Module extends CmsModule
protected function _descriptor()
{
return array_merge(parent::_descriptor(), [
"version" => "1.0.4",
"version" => "1.0.5",
"name" => "Каталог продукции",
]);
......
{
"1.0.5" :
[
"Доработка свойств товаров",
]
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 09.03.2015
*/
namespace skeeks\modules\cms\catalog\controllers;
use skeeks\cms\modules\admin\controllers\AdminModelEditorSmartController;
use skeeks\modules\cms\catalog\models\Product;
use skeeks\modules\cms\catalog\models\ProductPropertyEnum;
/**
* Class AdminProductController
* @package skeeks\modules\cms\catalog\controllers
*/
class AdminProductPropertyEnumController extends AdminModelEditorSmartController
{
public function init()
{
$this->_label = "Управление значениями свойств";
$this->_modelShowAttribute = "value";
$this->_modelClassName = ProductPropertyEnum::className();
$this->modelValidate = true;
$this->enableScenarios = true;
parent::init();
}
}
\ No newline at end of file
......@@ -50,8 +50,6 @@ class m150310_110557_create_product_property__product__map extends Migration
$this->execute("ALTER TABLE {{%catalog_product_property_map}} ADD INDEX(value);");
$this->execute("ALTER TABLE {{%catalog_product_property_map}} ADD UNIQUE(property_id,product_id);");
$this->execute("ALTER TABLE {{%catalog_product_property_map}} COMMENT = 'Связь товара свойства и значения';");
$this->addForeignKey(
......
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 29.04.2015
*/
use yii\db\Schema;
use yii\db\Migration;
class m150429_110857_alter_table__catalog_product_property extends Migration
{
public function safeUp()
{
$this->execute("ALTER TABLE {{%catalog_product_property%}} DROP `files`;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} DROP `description`;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `active` CHAR(1) NOT NULL DEFAULT 'Y' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `priority` INT NOT NULL DEFAULT '500' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `default_value` TEXT NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `property_type` CHAR(1) NOT NULL DEFAULT 'S' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `row_count` INT NOT NULL DEFAULT '1' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `col_count` INT NOT NULL DEFAULT '30' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `list_type` CHAR(1) NOT NULL DEFAULT 'L' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `multiple` CHAR(1) NOT NULL DEFAULT 'N' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `file_type` VARCHAR(200) NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `multiple_cnt` INT NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `tmp_id` VARCHAR(40) NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `with_description` CHAR(1) NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `searchable` CHAR(1) NOT NULL DEFAULT 'N' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `filtrable` CHAR(1) NOT NULL DEFAULT 'N' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `is_required` CHAR(1) NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `version` INT NOT NULL DEFAULT '1' ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `component` VARCHAR(255) NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `component_settings` TEXT NULL ;");
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `hint` VARCHAR(255) NULL ;");
}
public function safeDown()
{
echo "m150324_273205_alter_table__cms_infoblock cannot be reverted.\n";
return false;
}
}
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 10.03.2015
*/
use yii\db\Schema;
use yii\db\Migration;
class m150514_110557_create_table__catalog_product_property_enum extends Migration
{
public function up()
{
$tableExist = $this->db->getTableSchema("{{%catalog_product_property_enum}}", true);
if ($tableExist)
{
return true;
}
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable("{{%catalog_product_property_enum}}", [
'id' => Schema::TYPE_PK,
'created_by' => Schema::TYPE_INTEGER . ' NULL',
'updated_by' => Schema::TYPE_INTEGER . ' NULL',
'created_at' => Schema::TYPE_INTEGER . ' NULL',
'updated_at' => Schema::TYPE_INTEGER . ' NULL',
'property_id' => Schema::TYPE_INTEGER . ' NULL',
'value' => Schema::TYPE_STRING . '(255) NOT NULL',
'def' => "CHAR(1) NOT NULL DEFAULT 'N'",
'code' => Schema::TYPE_STRING. '(32) NOT NULL',
'priority' => Schema::TYPE_INTEGER. "(11) NOT NULL DEFAULT '500'",
], $tableOptions);
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(updated_by);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(created_by);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(created_at);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(updated_at);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(property_id);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(def);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(code);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(priority);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} ADD INDEX(value);");
$this->execute("ALTER TABLE {{%catalog_product_property_enum}} COMMENT = 'Справочник значений свойств типа список';");
$this->addForeignKey(
'catalog_product_property_enum_created_by', "{{%catalog_product_property_enum}}",
'created_by', '{{%cms_user}}', 'id', 'RESTRICT', 'RESTRICT'
);
$this->addForeignKey(
'catalog_product_property_enum_updated_by', "{{%catalog_product_property_enum}}",
'updated_by', '{{%cms_user}}', 'id', 'RESTRICT', 'RESTRICT'
);
$this->addForeignKey(
'catalog_product_property_enum_property_id', "{{%catalog_product_property_enum}}",
'property_id', '{{%catalog_product_property}}', 'id', 'CASCADE', 'CASCADE'
);
}
public function down()
{
$this->dropForeignKey("catalog_product_property_enum_created_by", "{{%catalog_product_property_enum}}");
$this->dropForeignKey("catalog_product_property_enum_updated_by", "{{%catalog_product_property_enum}}");
$this->dropForeignKey("catalog_product_property_enum_property_id", "{{%catalog_product_property_enum}}");
$this->dropTable("{{%catalog_product_property_enum}}");
}
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 29.04.2015
*/
use yii\db\Schema;
use yii\db\Migration;
class m150514_120857_alter_table__catalog_product_property extends Migration
{
public function safeUp()
{
$this->execute("ALTER TABLE {{%catalog_product_property%}} ADD `smart_filtrable` CHAR(1) NOT NULL DEFAULT 'N' ;");
}
public function safeDown()
{
echo "m150514_120857_alter_table__catalog_product_property cannot be reverted.\n";
return false;
}
}
......@@ -12,15 +12,18 @@ use skeeks\cms\models\behaviors\CanBeLinkedToModel;
use skeeks\cms\models\behaviors\CanBeLinkedToTree;
use skeeks\cms\models\behaviors\HasDescriptionsBehavior;
use skeeks\cms\models\behaviors\HasPageOptions;
use skeeks\cms\models\behaviors\HasProperties;
use skeeks\cms\models\behaviors\HasStatus;
use skeeks\cms\models\behaviors\Implode;
use skeeks\cms\models\behaviors\TimestampPublishedBehavior;
use skeeks\cms\models\Core;
use skeeks\cms\models\PageAdvanced;
use skeeks\cms\models\PropertiesValidateModel;
use skeeks\cms\models\Tree;
use skeeks\modules\cms\money\Currency;
use skeeks\modules\cms\money\Money;
use Yii;
use yii\web\ErrorHandler;
/**
* This is the model class for table "catalog_product".
......@@ -84,6 +87,7 @@ class Product extends PageAdvanced
CanBeLinkedToTree::className(),
TimestampPublishedBehavior::className() => TimestampPublishedBehavior::className(),
HasPageOptions::className() => HasPageOptions::className(),
HasProperties::className() => HasProperties::className(),
]);
}
......@@ -273,9 +277,53 @@ class Product extends PageAdvanced
public function getProperties()
{
return $this->hasMany(ProductProperty::className(), ['id' => 'property_id'])
//->viaTable('catalog_product_property_map', ['product_id' => 'id']);
->via('propertyValues');
->via('propertyValues');
}
/**
* @return array|\yii\db\ActiveRecord[]
*/
public function getPropertiesAll()
{
return ProductProperty::find()->active()->orderBy("priority DESC")->all();
}
/**
* @param $id
* @return array|null|\yii\db\ActiveRecord
*/
public function findPropertyValue($id)
{
return $this->getPropertyValues()->where(['property_id' => $id]);
}
/**
* @return string
*/
public function renderPropertiesForm()
{
try
{
return \Yii::$app->view->render('@skeeks/modules/cms/catalog/views/blank-form', [
'modelWithProperties' => $this,
'validateModel' => $this->createPropertiesValidateModel()
]);
} catch (\Exception $e)
{
ob_end_clean();
ErrorHandler::convertExceptionToError($e);
return 'Ошибка рендеринга формы: ' . $e->getMessage();
}
}
/**
* @return PropertiesValidateModel
*/
public function createPropertiesValidateModel()
{
return new PropertiesValidateModel([
'modelWithProperties' => $this
]);
}
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 14.05.2015
*/
namespace skeeks\modules\cms\catalog\models;
use skeeks\cms\base\db\ActiveRecord;
use skeeks\cms\models\behaviors\HasDescriptionsBehavior;
use skeeks\cms\models\behaviors\HasFiles;
use skeeks\cms\models\behaviors\HasStatus;
use skeeks\cms\models\behaviors\Implode;
use skeeks\cms\models\Core;
use \Yii;
/**
* Class ProductPropertyEnum
* @package skeeks\modules\cms\catalog\models
*/
class ProductPropertyEnum extends Core
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%catalog_product_property_enum}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(),[
[['created_by', 'updated_by', 'created_at', 'updated_at', 'property_id', 'priority'], 'integer'],
[['value'], 'required'],
[['value'], 'string', 'max' => 255],
[['def'], 'string', 'max' => 1],
[['code'], 'string', 'max' => 32],
['code', 'default', 'value' => function($model, $attribute)
{
return "sx_auto_" . md5(rand(1, 10) . time());
}],
['priority', 'default', 'value' => function($model, $attribute)
{
return 500;
}],
]);
}
public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios['create'] = $scenarios[self::SCENARIO_DEFAULT];
$scenarios['update'] = $scenarios[self::SCENARIO_DEFAULT];
return $scenarios;
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return array_merge(parent::attributeLabels(), [
'id' => Yii::t('app', 'ID'),
'created_by' => Yii::t('app', 'Created By'),
'updated_by' => Yii::t('app', 'Updated By'),
'created_at' => Yii::t('app', 'Created At'),
'updated_at' => Yii::t('app', 'Updated At'),
'property_id' => Yii::t('app', 'Property ID'),
'value' => Yii::t('app', 'Value'),
'def' => Yii::t('app', 'Def'),
'code' => Yii::t('app', 'Code'),
'priority' => Yii::t('app', 'Priority'),
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProperty()
{
return $this->hasOne(CatalogProductProperty::className(), ['id' => 'property_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCreatedBy()
{
return $this->hasOne(CmsUser::className(), ['id' => 'created_by']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUpdatedBy()
{
return $this->hasOne(CmsUser::className(), ['id' => 'updated_by']);
}
}
\ No newline at end of file
<?php
use yii\helpers\Html;
use skeeks\cms\modules\admin\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model \yii\db\ActiveRecord */
?>
<?php $form = ActiveForm::begin(); ?>
<? if ($form_id = \Yii::$app->request->get('property_id')) : ?>
<?= $form->field($model, 'property_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<? else: ?>
<?= $form->field($model, 'property_id')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\catalog\models\ProductProperty::find()->all(),
"id",
"name"
),
]);
?>
<? endif; ?>
<?= $form->field($model, 'value')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'code')->textInput(['maxlength' => 32]) ?>
<?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?>
......@@ -13,7 +13,7 @@ use skeeks\cms\modules\admin\widgets\ActiveForm;
\skeeks\modules\cms\catalog\models\ProductProperty::find()->all(),
"id",
"name"
),
),
]);
?>
......
......@@ -108,6 +108,9 @@ use skeeks\cms\modules\admin\widgets\Pjax;
<? if (!$model->isNewRecord) : ?>
<?= $form->fieldSet('Свойства товара') ?>
<?= \skeeks\cms\modules\admin\widgets\RelatedModelsGrid::widget([
'label' => "Дополнительные свойства",
'hint' => "Вы можете привязать к товару несколько свойст, и задать им значение",
......@@ -115,6 +118,7 @@ use skeeks\cms\modules\admin\widgets\Pjax;
'relation' => [
'product_id' => 'id'
],
'controllerRoute' => 'catalog/admin-product-property-map',
'gridViewOptions' => [
......@@ -164,11 +168,14 @@ use skeeks\cms\modules\admin\widgets\Pjax;
<? endif;?>
<?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?>
<div class="sx-box sx-p-10 sx-mt-10">
<h2>Дополнительные свойства</h2>
<?= $model->renderPropertiesForm(); ?>
</div>
<?php ActiveForm::end(); ?>
......
<?php
use yii\helpers\Html;
......@@ -12,7 +11,7 @@ use skeeks\cms\modules\admin\widgets\Pjax;
<?php $form = ActiveForm::begin(); ?>
<?= $form->fieldSet('Основная информация') ?>
<?= $form->fieldSet('Основные настройки') ?>
<? if ($group_id = \Yii::$app->request->get('group_id')) : ?>
......@@ -33,11 +32,79 @@ use skeeks\cms\modules\admin\widgets\Pjax;
<? endif; ?>
<?= $form->fieldSelect($model, 'component', [
'Базовые типы' => \Yii::$app->cms->basePropertyTypes(),
'Пользовательские типы' => \Yii::$app->cms->userPropertyTypes(),
]); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'hint')->textInput() ?>
<?= $form->field($model, 'code')->textInput() ?>
<?= $form->fieldRadioListBoolean($model, 'active') ?>
<?/*= $form->fieldRadioListBoolean($model, 'multiple') */?>
<?= $form->fieldRadioListBoolean($model, 'is_required') ?>
<?= $form->fieldRadioListBoolean($model, 'searchable') ?>
<?= $form->fieldRadioListBoolean($model, 'filtrable') ?>
<?= $form->fieldRadioListBoolean($model, 'smart_filtrable') ?>
<?= $form->fieldRadioListBoolean($model, 'with_description') ?>
<?= $form->fieldInputInt($model, 'priority') ?>
<?/*= $form->field($model, 'default_value')->textInput() */?>
<!--
--><?/*= $form->fieldInputInt($model, 'multiple_cnt') */?>
<?= $form->fieldSetEnd(); ?>
<? if (!$model->isNewRecord) : ?>
<?= $form->fieldSet('Значения для списка') ?>
<?= \skeeks\cms\modules\admin\widgets\RelatedModelsGrid::widget([
'label' => "Значения для списка",
'hint' => "Вы можете привязать к товару несколько свойст, и задать им значение",
'parentModel' => $model,
'relation' => [
'property_id' => 'id'
],
'sort' => [
'defaultOrder' =>
[
'priority' => SORT_DESC
]
],
'controllerRoute' => 'catalog/admin-product-property-enum',
'gridViewOptions' => [
'sortable' => true,
'columns' => [
//['class' => 'yii\grid\SerialColumn'],
/*[
'class' => \yii\grid\DataColumn::className(),
'value' => function(\skeeks\modules\cms\catalog\models\ProductPropertyMap $model)
{
return $model->fetchProductProperty()->name;
},
'format' => 'html',
'label' => 'Свойство',
'enableSorting' => true,
'attribute' => "property_id"
],*/
'id',
'code',
'value',
'priority',
'def',
],
],
]); ?>
<?= $form->fieldSetEnd(); ?>
<? endif; ?>
<?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?>
......
......@@ -15,12 +15,15 @@ use skeeks\cms\modules\admin\widgets\GridView;
/* @var $searchModel \skeeks\cms\models\Search */
/* @var $dataProvider yii\data\ActiveDataProvider */
//$dataProvider->query->orderBy('published_at DESC');
$dataProvider->sort->defaultOrder = ['priority' => SORT_DESC];
$dataProvider->pagination->pageSize = 10000;
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'sortable' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
......@@ -31,7 +34,13 @@ use skeeks\cms\modules\admin\widgets\GridView;
'name',
//['class' => \skeeks\cms\grid\UpdatedByColumn::className()],
[
'class' => \skeeks\cms\grid\BooleanColumn::className(),
'attribute' => 'active',
'falseValue' => \skeeks\cms\components\Cms::BOOL_N,
'trueValue' => \skeeks\cms\components\Cms::BOOL_Y
],
[
......@@ -47,6 +56,9 @@ use skeeks\cms\modules\admin\widgets\GridView;
'filter' => false
],
'code',
'priority',
],
]); ?>
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 17.03.2015
*
* @var $formField \skeeks\modules\cms\form\models\FormField
* @var $model \skeeks\modules\cms\form\models\FormValidateModel
*/
use skeeks\cms\widgets\ActiveFormModelPropertyValues as ActiveForm;
?>
<?php $form = ActiveForm::begin([
'modelWithProperties' => $modelWithProperties,
]);
?>
<? if ($properties = $modelWithProperties->getPropertiesAll()) : ?>
<? foreach ($properties as $property) : ?>
<?= $property->renderActiveForm($form, $validateModel)?>
<? endforeach; ?>
<? endif; ?>
<?= \yii\helpers\Html::button('Сохранить', [
'type' => 'submit',
'class' => 'btn btn-primary'
]); ?>
<?php ActiveForm::end(); ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment