コード例 #1
0
ファイル: add-value.php プロジェクト: black-lamp/blcms-shop
use yii\widgets\Pjax;
?>

<?php 
Pjax::begin(['enablePushState' => false, 'timeout' => 5000]);
?>

<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterRowOptions' => ['class' => 'm-b-sm m-t-sm'], 'options' => ['class' => 'project-list'], 'tableOptions' => ['id' => 'my-grid', 'class' => 'table table-hover'], 'summary' => "", 'columns' => ['id', ['label' => \Yii::t('shop', 'Title'), 'value' => 'translation.title'], ['attribute' => 'value', 'value' => function ($model) {
    $attribute = ShopAttribute::findOne($model->attribute_id);
    if ($attribute->type_id == 3) {
        $color = ShopAttributeValueColorTexture::findOne($model->translation->value)->color;
        return Html::tag('div', '', ['style' => 'width: 50px; height: 50px; background-color:' . $color]);
    }
    if (ShopAttribute::findOne($model->attribute_id)->type_id == 4) {
        return ShopAttributeValueColorTexture::getTexture($model->translation->value);
    }
    return $model->translation->value;
}, 'format' => 'raw']]]);
?>

<div class="shop-attribute-value-form">

    <?php 
$valueForm = ActiveForm::begin(['method' => 'post', 'options' => ['data-pjax' => true, 'enctype' => 'multipart/form-data'], 'action' => ['attribute/add-value', 'attrId' => $attribute->id, 'languageId' => $selectedLanguage->id]]);
?>

    <?php 
echo $valueForm->field($valueModelTranslation, 'title')->textInput(['maxlength' => true]);
?>
コード例 #2
0
 /**
  * @param integer $attrId
  * @param integer $languageId
  * @return mixed
  * @throws Exception
  */
 public function actionAddValue($attrId, $languageId)
 {
     if (!empty($attrId)) {
         $languageId = empty($languageId) ? Language::getCurrent()->id : $languageId;
         $model = new ShopAttributeValue();
         $modelTranslation = new ShopAttributeValueTranslation();
         $attributeTextureModel = new AttributeTextureForm();
         if (Yii::$app->request->post()) {
             if ($modelTranslation->load(Yii::$app->request->post())) {
                 $model->attribute_id = $attrId;
                 if (ShopAttribute::findOne($attrId)->type_id == 3 || ShopAttribute::findOne($attrId)->type_id == 4) {
                     $colorTexture = new ShopAttributeValueColorTexture();
                     if (ShopAttribute::findOne($attrId)->type_id == 3) {
                         if ($attributeTextureModel->load(Yii::$app->request->post())) {
                             $colorTexture->color = $attributeTextureModel->color;
                         }
                     } elseif (ShopAttribute::findOne($attrId)->type_id == 4) {
                         if ($attributeTextureModel->load(Yii::$app->request->post())) {
                             $attributeTextureModel->imageFile = UploadedFile::getInstance($attributeTextureModel, 'imageFile');
                             $colorTexture->texture = $attributeTextureModel->upload();
                         }
                     }
                     $colorTexture->save();
                     $modelTranslation->value = $colorTexture->id;
                 }
                 if ($model->save()) {
                     $modelTranslation->value_id = $model->id;
                     $modelTranslation->language_id = $languageId;
                     if ($modelTranslation->save()) {
                         if (\Yii::$app->request->isPjax) {
                             $searchAttributeValueModel = new SearchAttributeValue();
                             $dataProviderAttributeValue = $searchAttributeValueModel->search(Yii::$app->request->queryParams);
                             return $this->renderPartial('add-value', ['dataProvider' => $dataProviderAttributeValue, 'attribute' => ShopAttribute::findOne($attrId), 'selectedLanguage' => Language::findOne($languageId), 'valueModel' => new ShopAttributeValue(), 'valueModelTranslation' => new ShopAttributeValueTranslation(), 'attributeTextureModel' => $attributeTextureModel]);
                         } else {
                             return $this->redirect(Url::toRoute(['save', 'attrId' => $attrId, 'languageId' => $languageId]));
                         }
                     }
                 } else {
                     throw new Exception($model->errors);
                 }
             }
         } else {
             return $this->render(Url::toRoute(['add-value', 'attrId' => $attrId, 'languageId' => $languageId]));
         }
     }
 }