Skip to content

Commit

Permalink
closed #2415
Browse files Browse the repository at this point in the history
  • Loading branch information
yupe committed May 5, 2016
1 parent 35a0b4c commit 484dc61
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 155 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- #2407: В формах авторизации поле "Запомнить меня" активно по-умолчанию (@sabian, @ilvval)
- #2409: Можно создавать атрибуты товара типа "Файл" (@yupe)
- #2414: Назначение ответственного за заказ менеджера (@yupe, @sabian)
- #2415: Новый тип атрибута "Список чекбоксов" (@syrexby, @Divan4ik, @yupe)
- #2417: ZendSearch поиск по цифрам (@gaidar, @sabian)
- #2419: Убрана лишняя вложенность пункта меню "Юпи!" (@Divan4ik, @yupe)
- #2423: Исправлены стили главного меню темы default для мобильной версии (@ilvval, @sabian)
Expand Down
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protected/modules/store/components/AttributeFilter.php
Expand Up @@ -154,7 +154,7 @@ public function isFieldChecked(Attribute $attribute, $value = null)
*/
public function getDropdownOptionName(AttributeOption $option)
{
if ((int)$option->parent->type === Attribute::TYPE_DROPDOWN) {
if ((int)$option->parent->isMultipleValues()) {
return sprintf($this->dropdownTemplate, $option->parent->name, $option->id);
}

Expand Down
13 changes: 10 additions & 3 deletions protected/modules/store/components/AttributeRender.php
Expand Up @@ -35,6 +35,7 @@ public static function renderField($attribute, $value = null, $name = null, $htm
return CHtml::dropDownList($name, $value, $data, array_merge($htmlOptions, (['empty' => '---'])));
break;
case Attribute::TYPE_CHECKBOX_LIST:

$data = CHtml::listData($attribute->options, 'id', 'value');

return CHtml::checkBoxList($name.'[]', $value, $data, $htmlOptions);
Expand All @@ -58,10 +59,10 @@ public static function renderField($attribute, $value = null, $name = null, $htm
* @param $value
* @return string
*/
public static function renderValue(Attribute $attribute, $value)
public static function renderValue(Attribute $attribute, $value, $template = '<p>{item}</p>')
{
$unit = $attribute->unit ? ' '.$attribute->unit : '';
$res = '';
$res = null;
switch ($attribute->type) {
case Attribute::TYPE_TEXT:
case Attribute::TYPE_SHORT_TEXT:
Expand All @@ -71,7 +72,13 @@ public static function renderValue(Attribute $attribute, $value)
case Attribute::TYPE_DROPDOWN:
$data = CHtml::listData($attribute->options, 'id', 'value');
if (!is_array($value) && isset($data[$value])) {
$res = $data[$value];
$res .= $data[$value];
}
break;
case Attribute::TYPE_CHECKBOX_LIST:
$data = CHtml::listData($attribute->options, 'id', 'value');
foreach (array_intersect(array_keys($data), $value) as $val) {
$res .= strtr($template, ['{item}' => $data[$val]]);
}
break;
case Attribute::TYPE_CHECKBOX:
Expand Down
Expand Up @@ -30,6 +30,7 @@ public function getByFilter(array $mainSearchAttributes, array $typeSearchAttrib
$criteria->params = [];
$criteria->addCondition('t.status = :status');
$criteria->params['status'] = Product::STATUS_ACTIVE;
$criteria->distinct = true;


//поиск по категории, производителю и цене
Expand Down
Expand Up @@ -99,7 +99,7 @@ public function actionCreate()
$model->setAttributes($data);

if ($model->save() && $model->setTypes(Yii::app()->getRequest()->getPost('types',
[])) && $model->setDropDownAttributes(explode(PHP_EOL, $model->rawOptions))
[])) && $model->setMultipleValuesAttributes(explode(PHP_EOL, $model->rawOptions))
) {
Yii::app()->getUser()->setFlash(
yupe\widgets\YFlashMessages::SUCCESS_MESSAGE,
Expand Down
16 changes: 10 additions & 6 deletions protected/modules/store/controllers/ProductBackendController.php
Expand Up @@ -362,24 +362,28 @@ public function actionTypeAttributes($id)
throw new CHttpException(404);
}

$out = [];
$types = [];

$noSupported = [Attribute::TYPE_FILE, Attribute::TYPE_TEXT, Attribute::TYPE_CHECKBOX_LIST];

foreach ($type->typeAttributes as $attr) {
if ($attr->type == Attribute::TYPE_FILE || $attr->type === Attribute::TYPE_TEXT) {

if (in_array($attr->type, $noSupported)) {
continue;
}

if ($attr->type == Attribute::TYPE_DROPDOWN) {
$out[] = array_merge($attr->attributes, ['options' => $attr->options]);
$types[] = array_merge($attr->attributes, ['options' => $attr->options]);
} else {
if (in_array($attr->type, [Attribute::TYPE_CHECKBOX, Attribute::TYPE_SHORT_TEXT])) {
$out[] = array_merge($attr->attributes, ['options' => []]);
$types[] = array_merge($attr->attributes, ['options' => []]);
} else {
$out[] = $attr->attributes;
$types[] = $attr->attributes;
}
}
}

Yii::app()->ajax->raw($out);
Yii::app()->ajax->raw($types);
}

/**
Expand Down
1 change: 1 addition & 0 deletions protected/modules/store/messages/ru/store.php
@@ -1,5 +1,6 @@
<?php
return [
'Checkbox list' => 'Список чекбоксов (множественный)',
'or' => 'или',
'Download' => 'Скачать',
'Use in types' => 'Использовать в следующих типах товаров:',
Expand Down
23 changes: 5 additions & 18 deletions protected/modules/store/models/Attribute.php
Expand Up @@ -190,6 +190,7 @@ public function getTypesList()
self::TYPE_CHECKBOX => Yii::t('StoreModule.store', 'Checkbox'),
self::TYPE_NUMBER => Yii::t('StoreModule.store', 'Number'),
self::TYPE_FILE => Yii::t('StoreModule.store', 'File'),
self::TYPE_CHECKBOX_LIST => Yii::t('StoreModule.store', 'Checkbox list')
];
}

Expand Down Expand Up @@ -239,20 +240,6 @@ public function isRequired()
return $this->required;
}


/**
* @return string Список опций, разделенных переносом строки
*/
public function getRawOptions()
{
$tmp = '';
foreach ((array)$this->options as $option) {
$tmp .= $option->value."\n";
}

return $tmp;
}

/**
* @param $currentType
* @param $newType
Expand Down Expand Up @@ -365,9 +352,9 @@ public function getTypes()
* @return bool
* @throws CDbException
*/
public function setDropDownAttributes(array $attributes)
public function setMultipleValuesAttributes(array $attributes)
{
if(!$this->isDropDown()){
if(!$this->isMultipleValues()){
return true;
}

Expand Down Expand Up @@ -400,8 +387,8 @@ public function setDropDownAttributes(array $attributes)
/**
* @return bool
*/
public function isDropDown()
public function isMultipleValues()
{
return $this->type == self::TYPE_DROPDOWN;
return $this->type == self::TYPE_DROPDOWN || $this->type == self::TYPE_CHECKBOX_LIST;
}
}

0 comments on commit 484dc61

Please sign in to comment.