<?php
    
    namespace common\behaviors;
    
    use common\models\ProductSpec;
    use common\modules\product\models\Product;
    use yii\base\Behavior;
    use yii\db\ActiveRecord;

    /**
     * Class TechBehavior
     * @package common\behaviors
     * @property Product $owner
     */
    class TechBehavior extends Behavior
    {
        public function events()
        {
            return [
                ActiveRecord::EVENT_AFTER_INSERT => 'afterInsert',
            ];
        }
        
        public function afterInsert($event) {
            $owner = $this->owner;
            $spec = new ProductSpec([
                'product_id' => $owner->product_id,
            ]);
            $spec->generateLangs();
            $spec->save(false);
        }
    }