Commit 740819d41c8ca39207e25967bb5a61c05ed3d72b
1 parent
3d4c8f83
Images fix
Showing
2 changed files
with
22 additions
and
2 deletions
Show diff stats
common/behaviors/MultipleImgBehavior.php
| @@ -23,6 +23,13 @@ | @@ -23,6 +23,13 @@ | ||
| 23 | * @var array | 23 | * @var array |
| 24 | */ | 24 | */ |
| 25 | public $links = []; | 25 | public $links = []; |
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * Will be passed to get image and get images queries | ||
| 29 | + * | ||
| 30 | + * @var array | ||
| 31 | + */ | ||
| 32 | + public $conditions = []; | ||
| 26 | 33 | ||
| 27 | /** | 34 | /** |
| 28 | * Full namespaced image model | 35 | * Full namespaced image model |
| @@ -51,7 +58,12 @@ | @@ -51,7 +58,12 @@ | ||
| 51 | * @var ActiveRecord $owner | 58 | * @var ActiveRecord $owner |
| 52 | */ | 59 | */ |
| 53 | $owner = $this->owner; | 60 | $owner = $this->owner; |
| 54 | - return $owner->hasOne($this->model, $this->links); | 61 | + $query = $owner->hasOne($this->model, $this->links); |
| 62 | + $conditions = $this->conditions; | ||
| 63 | + foreach($conditions as $condition) { | ||
| 64 | + $query->andWhere($condition); | ||
| 65 | + } | ||
| 66 | + return $query; | ||
| 55 | } | 67 | } |
| 56 | 68 | ||
| 57 | /** | 69 | /** |
| @@ -65,7 +77,12 @@ | @@ -65,7 +77,12 @@ | ||
| 65 | * @var ActiveRecord $owner | 77 | * @var ActiveRecord $owner |
| 66 | */ | 78 | */ |
| 67 | $owner = $this->owner; | 79 | $owner = $this->owner; |
| 68 | - return $owner->hasMany($this->model, $this->links); | 80 | + $query = $owner->hasMany($this->model, $this->links); |
| 81 | + $conditions = $this->conditions; | ||
| 82 | + foreach($conditions as $left => $right) { | ||
| 83 | + $query->andWhere([$left => $right]); | ||
| 84 | + } | ||
| 85 | + return $query; | ||
| 69 | } | 86 | } |
| 70 | 87 | ||
| 71 | /** | 88 | /** |
common/modules/product/models/Product.php
| @@ -109,6 +109,9 @@ | @@ -109,6 +109,9 @@ | ||
| 109 | 'links' => [ | 109 | 'links' => [ |
| 110 | 'product_id' => 'product_id', | 110 | 'product_id' => 'product_id', |
| 111 | ], | 111 | ], |
| 112 | + 'conditions' => [ | ||
| 113 | + 'product_variant_id' => NULL, | ||
| 114 | + ], | ||
| 112 | 'model' => ProductImage::className(), | 115 | 'model' => ProductImage::className(), |
| 113 | 'config' => [ | 116 | 'config' => [ |
| 114 | 'caption' => 'image', | 117 | 'caption' => 'image', |