Product.php
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
    /**
     * Created by PhpStorm.
     * User: stes
     * Date: 20.09.17
     * Time: 18:52
     */
    
    namespace common\models;
    
    use artbox\core\behaviors\BitMaskBehavior;
    use artbox\core\behaviors\GalleryBehavior;
    use artbox\core\behaviors\LanguageBehavior;
    use artbox\core\behaviors\ManyToManyBehavior;
    use artbox\core\models\Image;
    use yii\behaviors\TimestampBehavior;
    class Product extends \artbox\catalog\models\Product
    {
        public $imgIds;
        public function behaviors()
        {
            return [
                'language'       => [
                    'class' => LanguageBehavior::className(),
                ],
                'timestamp'      => [
                    'class' => TimestampBehavior::className(),
                ],
                [
                    'class' => ManyToManyBehavior::className(),
                ],
                [
                    'class'  => BitMaskBehavior::className(),
                    'fields' => [
                        'top'       => 0,
                        'new'       => 1,
                        'akcia'     => 2,
                        'exclusive' => 3,
                    ],
                ],
                [
                    'class' => GalleryBehavior::className(),
                ],
            ];
        }
        public function getImages()
        {
            $ids = [];
            $gallery = $this->gallery;
            if (!empty($gallery)) {
                $ids = array_filter(json_decode($gallery));
            }
            if (!empty($this->image_id)) {
                $ids[] = $this->image_id;
            }
            $this->imgIds = $ids;
            return $this->hasMany(Image::className(), [ 'id' => 'imgIds' ]);
        }
    } 
