@freshik312

Почему столбец не хочет сохраняться yii2?

Вся форма сохраняется, но только 1 поле (is_hit) отказывается реагировать, а полная ее копия parent_id отлично сохраняется.
Базу проверил вручную принять значение может.
Форма
<?= $form->field($model, 'is_hit')->dropDownList([
        0 => 0,
        1 => 1
    ]); ?>


Модель
<?php
namespace products\models;

use usni\library\db\TranslatableActiveRecord;
use usni\Ecocom;
use products\utils\ProductUtil;

/**
 * Product Active Record
 *
 * @package products\models
 */
class Product extends TranslatableActiveRecord
{
    use \products\traits\DownloadTrait;
    
    const TYPE_DEFAULT = 1;
    const TYPE_DOWNLOADABLE = 2;
    const IN_STOCK = 1;
    const OUT_OF_STOCK = 2;
    const DEFAULT_PAGE_SIZE = 10;
    public $uploadInstance;
    public $is_hit;
    public $savedImage;
    public $categories = [];
    protected $categoriesList = [];
    public $relatedProducts = [];
    public $category_id;
    public $tagNames;
    public $totalPrice;
    public $itemPerPage;
    public $sort_by;
    public $discounts;
    public $specials;
    public $images = [];
    public $productImageData = [];
    const NOTIFY_PRODUCTREVIEW = 'productReview';
    public $downloads = [];
    public $download_option;
    
    public function init()
    {
        parent::init();
        if ($this->scenario == 'create') {
            $this->type = self::TYPE_DEFAULT;
        }
    }

    public function rules()
    {
        if ($this->checkIfExtendedConfigExists()) {
            $configInstance = $this->getExtendedConfigClassInstance();
            $rules = $configInstance->rules();
            return $rules;
        } else {
            return [
                [['name', 'alias', 'is_hit', 'sku', 'price', 'super_opt', 'opt', 'stop_price', 'stop_opt', 'quantity', 'categories', 'type'], 'required', 'except' => 'search'],
                [['image'], 'required', 'on' => 'create'],
                ['downloads', 'required',
                    'whenClient' => "function(attribute, value){
                        return $('#product-type').val() === '2';
                     }",
                    'when' => [$this, 'validateDownloads'],
                    'message' => Ecocom::t('products', 'Downloads are required')],
                [['image', 'uploadInstance'], 'image', 'skipOnEmpty' => true, 'extensions' => 'jpg, png, gif, jpeg'],
                ['name', 'unique', 'targetClass' => ProductTranslated::className(), 'targetAttribute' => ['name', 'language'], 'on' => 'create'],
                ['alias', 'unique', 'targetClass' => ProductTranslated::className(), 'targetAttribute' => ['alias', 'language'], 'on' => 'create'],
                ['name', 'unique', 'targetClass' => ProductTranslated::className(), 'targetAttribute' => ['name', 'language'], 'filter' => ['!=', 'owner_id', $this->id], 'on' => 'update'],
                ['alias', 'unique', 'targetClass' => ProductTranslated::className(), 'targetAttribute' => ['alias', 'language'], 'filter' => ['!=', 'owner_id', $this->id], 'on' => 'update'],
                [['quantity', 'status', 'minimum_quantity'], 'number', 'integerOnly' => true],
                ['minimum_quantity', 'default', 'value' => 1],
                ['price', 'match', 'pattern' => '/^[0-9]{1,12}(\.[0-9]{0,4})?$/'],
                ['super_opt', 'match', 'pattern' => '/^[0-9]{1,12}(\.[0-9]{0,4})?$/'],
                ['opt', 'match', 'pattern' => '/^[0-9]{1,12}(\.[0-9]{0,4})?$/'],
                ['stop_price', 'match', 'pattern' => '/^[0-9]{1,12}(\.[0-9]{0,4})?$/'],
                ['stop_opt', 'match', 'pattern' => '/^[0-9]{1,12}(\.[0-9]{0,4})?$/'],
                ['name', 'string', 'max' => 128],
                ['alias', 'string', 'max' => 128],
                ['model', 'string', 'max' => 64],
                ['relatedProducts', 'safe'],
                ['type', 'default', 'value' => self::TYPE_DEFAULT],
                ['hits', 'number'],
                [['length', 'width', 'height', 'weight'], 'number'],
                [['location', 'length', 'width', 'height', 'date_available', 'weight', 'length_class', 'weight_class'], 'safe'],
                [['name', 'is_hit', 'description', 'metakeywords', 'metadescription', 'tagNames', 'minimum_quantity',
                    'subtract_stock', 'requires_shipping', 'manufacturer', 'alias', 'categories',
                    'image', 'is_featured', 'relatedProducts', 'model', 'sku', 'price', 'super_opt', 'opt', 'stop_price', 'stop_opt', 'quantity', 'status', 'tax_class_id', 'stock_status',
                    'length_class', 'weight_class', 'buy_price', 'initial_quantity', 'type', 'downloads', 'hits', 'upc', 'ean', 'jan', 'isbn',
                    'mpn', 'download_option', 'buy_currency'], 'safe'],
            ];
        }
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        if ($this->checkIfExtendedConfigExists()) {
            $configInstance = $this->getExtendedConfigClassInstance();
            $scenarios = $configInstance->scenarios();
            return $scenarios;
        } else {
            $scenarios = parent::scenarios();
            $scenarios['create'] = $scenarios['update'] = ['name', 'parent_id', 'is_hit', 'description', 'metakeywords', 'metadescription', 'tagNames',
                'minimum_quantity', 'subtract_stock', 'requires_shipping', 'manufacturer',
                'alias', 'categories', 'image', 'is_featured', 'relatedProducts',
                'model', 'sku', 'price', 'super_opt', 'opt', 'stop_price', 'stop_opt', 'quantity', 'status', 'tax_class_id', 'stock_status', 'location',
                'length', 'width', 'height', 'date_available', 'weight', 'length_class', 'weight_class',
                'buy_price', 'initial_quantity', 'downloads', 'type', 'hits', 'upc', 'ean', 'jan',
                'isbn', 'mpn', 'download_option', 'buy_currency'];
            $scenarios['bulkedit'] = ['status'];
            $scenarios['search'] = ['name', 'category_id'];
            $scenarios['deleteimage'] = ['image'];
            return $scenarios;
        }
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        if ($this->checkIfExtendedConfigExists()) {
            $configInstance = $this->getExtendedConfigClassInstance();
            return $configInstance->attributeLabels();
        } else {
            $labels = ProductUtil::getProductLabels();
            return parent::getTranslatedAttributeLabels($labels);
        }
    }

    /**
     * @inheritdoc
     */
    public function attributeHints()
    {
        if ($this->checkIfExtendedConfigExists()) {
            $configInstance = $this->getExtendedConfigClassInstance();
            return $configInstance->attributeHints();
        } else {
            return ProductUtil::getProductHints();
        }
    }
}
  • Вопрос задан
  • 132 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы