_form_options.php 2.11 KB
<?php
    
    use artbox\catalog\models\Product;
    use artbox\catalog\models\ProductLang;
    use artbox\catalog\models\VariantOptionGroupCompl;
    use artbox\catalog\models\VariantOptionGroupExcl;
    use yii\helpers\ArrayHelper;
    use yii\web\View;
    use yii\widgets\ActiveForm;
    
    /**
     * @var ProductLang[]             $modelLangs
     * @var Product                   $model
     * @var ActiveForm                $form
     * @var View                      $this
     * @var VariantOptionGroupCompl[] $groups_compl
     * @var VariantOptionGroupExcl[]  $groups_excl
     */
?>
<?php
    if (!empty( $groups_compl )) {
        foreach ($groups_compl as $group) {
            echo $form->field($model, 'variantOptionCompls')
                      ->checkboxList(
                          ArrayHelper::map(
                              $group->options,
                              'id',
                              'lang.value'
                          ),
                          [
                              'multiple'    => true,
                              'unselect'    => null,
                              'itemOptions' => [
                                  'class' => 'flat',
                              ],
                          ]
                      )
                      ->label($group->lang->title);
        }
    }
    if (!empty( $groups_excl )) {
        foreach ($groups_excl as $index => $group) {
            $optionIds = ArrayHelper::map(
                $group->options,
                'id',
                'lang.value'
            );
            $optionIds = [ 0 => \Yii::t('catalog', 'Not set') ] + $optionIds;
            echo $form->field($model, "variantOptionExcls[$index]")
                      ->radioList(
                          $optionIds,
                          [
                              'unselect'    => null,
                              'itemOptions' => [
                                  'class' => 'flat',
                              ],
                          ]
                      )
                      ->label($group->lang->title);
        }
    }
?>