model() публичный статический Метод

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : Attribute
Результат Attribute the static model class
Пример #1
0
 public function beforeValidate()
 {
     if ($this->attribute_option_id) {
         $option = AttributeOption::model()->findByPk($this->attribute_option_id);
         $this->attribute_value = $option ? $option->value : null;
     }
     if (!$this->attribute_value) {
         $this->addErrors(['attribute_value' => Yii::t('StoreModule.store', 'You must specify the attribute value')]);
     }
     return parent::beforeValidate();
 }
Пример #2
0
echo $variant->attribute->title;
?>
        <input type="hidden" value="<?php 
echo $variant->attribute_id;
?>
" name="ProductVariant[<?php 
echo $variant->id;
?>
][attribute_id]"/>
    </td>
    <td>
        <?php 
if ($variant->attribute->type == Attribute::TYPE_DROPDOWN) {
    ?>
            <?php 
    $option = AttributeOption::model()->findByAttributes(['attribute_id' => $variant->attribute_id, 'value' => $variant->attribute_value]);
    echo $variant->attribute->renderField($option ? $option->id : null, 'ProductVariant[' . $variant->id . '][attribute_option_id]');
    ?>
        <?php 
} else {
    ?>
            <?php 
    echo $variant->attribute->renderField($variant->attribute_value, 'ProductVariant[' . $variant->id . '][attribute_value]');
    ?>
        <?php 
}
?>
    </td>
    <td>
        <?php 
echo CHtml::dropDownList('ProductVariant[' . $variant->id . '][type]', $variant->type, $variant->getTypeList(), ['class' => 'form-control']);
Пример #3
0
 /**
  * @param $id
  * @throws CHttpException
  */
 public function actionDeleteOption($id)
 {
     if (Yii::app()->getRequest()->getIsPostRequest()) {
         $option = AttributeOption::model()->findByPk($id);
         if (null === $option) {
             throw new CHttpException(404);
         }
         $option->delete();
         if (!isset($_GET['ajax'])) {
             $this->redirect((array) Yii::app()->getRequest()->getPost('returnUrl', 'index'));
         }
     } else {
         throw new CHttpException(400, Yii::t('StoreModule.store', 'Bad request. Please don\'t use similar requests anymore'));
     }
 }
Пример #4
0
echo CHtml::encode($product->name);
?>
</span>
                            <div class="row price-info">
                                <section class="col-md-12 price">
                                    <?php 
echo Yii::t('StoreModule.default', 'Цена от:');
?>
                                    <span><?php 
echo $product->getResultPrice();
?>
                                        <?php 
//$valyuta = $product->attribute('valyuta');
$valyuta = $product->currency_id;
if (!empty($valyuta)) {
    echo AttributeOption::model()->findByPk($valyuta)->value;
} else {
    echo Yii::t('StoreModule.default', 'RUB');
}
?>
                                            </span>
                                </section>
                                <section class="col-md-12 other">
                                  <?php 
echo Yii::t('StoreModule.default', 'Поставщик:');
?>
                                  <a class="postav" onclick="ga('send', 'event', 'UI', 'Нажал на Компанию','store-show-'); return true;" href="/company/<?php 
echo $product->user->company->id;
?>
" id="firm-title" class="link"><?php 
echo $product->user->company->name;
 public function up()
 {
     Yii::app()->setImport(['application.modules.store.models.*']);
     $pos = \Yii::app()->db->createCommand()->select('count(`id`)')->from('site_store_attribute_option')->where('attribute_id=7')->queryScalar();
     $pos = $pos === NULL ? 0 : $pos;
     $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'шт']);
     if ($m === NULL) {
         $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'шт', 'position' => $pos]);
         $pos = $pos + 1;
     }
     $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'кг']);
     if ($m === NULL) {
         $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'кг', 'position' => $pos]);
         $pos = $pos + 1;
     }
     $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'м3']);
     if ($m === NULL) {
         $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'м3', 'position' => $pos]);
         $pos = $pos + 1;
     }
     $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'литр']);
     if ($m === NULL) {
         $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'литр', 'position' => $pos]);
         $pos = $pos + 1;
     }
     $pos = 0;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Австрия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Албания', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Андорра', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Белоруссия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Бельгия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Болгария', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Босния и Герцеговина', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Ватикан', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Великобритания', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Венгрия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Германия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Греция', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Дания', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Ирландия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Исландия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Испания', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Италия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Латвия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Литва', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Лихтенштейн', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Люксембург', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Македония', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Мальта', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Молдавия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Монако', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Нидерланды', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Норвегия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Польша', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Португалия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Россия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Румыния', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Сан-Марино', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Сербия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Словакия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Словения', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Украина', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Финляндия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Франция', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Хорватия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Черногория', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Чехия', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Швейцария', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Швеция', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Эстония', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Китай', 'position' => $pos]);
     $pos = $pos + 1;
     $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'США', 'position' => $pos]);
     $this->execute("\n\t\t\tALTER TABLE `site_store_category`\n\t\t\t\tADD COLUMN `type` ENUM('tovary','uslugi') NOT NULL DEFAULT 'tovary' AFTER `tiu_id_item`;\n\t\t");
     $this->update('site_store_category', ['type' => 'uslugi'], 'slug="uslugi"');
 }
Пример #6
0
 public function afterSave()
 {
     // удаляем старые значения
     AttributeOption::model()->deleteAllByAttributes(['attribute_id' => $this->id]);
     if (in_array($this->type, [Attribute::TYPE_DROPDOWN])) {
         $newOptions = explode("\n", $this->rawOptions);
         $newOptions = array_filter($newOptions, function ($x) {
             return strlen(trim($x));
         });
         foreach (array_values((array) $newOptions) as $key => $op) {
             $option = new AttributeOption();
             $option->attribute_id = $this->id;
             $option->value = trim($op);
             $option->position = $key;
             $option->save();
         }
     }
     parent::afterSave();
 }
 public function addOption($spec, $attr)
 {
     $options = AttributeOption::model()->findAllByAttributes(['attribute_id' => $attr->id]);
     $list = CHtml::listData($options, 'position', 'value');
     if (!in_array($spec['value'], $list)) {
         end($list);
         $key = key($list);
         $option = new AttributeOption();
         $option->attribute_id = $attr->id;
         $option->position = $key + 1;
         $option->value = $spec['value'];
         $option->save();
         if (!$option->save()) {
             echo "\n";
             echo "Error: save AttributeOption for id_product = {$spec['id_product']} \n";
             echo "\n";
         }
     }
 }