From 740819d41c8ca39207e25967bb5a61c05ed3d72b Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 19 Oct 2016 19:06:54 +0300 Subject: [PATCH] Images fix --- common/behaviors/MultipleImgBehavior.php | 21 +++++++++++++++++++-- common/modules/product/models/Product.php | 3 +++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/common/behaviors/MultipleImgBehavior.php b/common/behaviors/MultipleImgBehavior.php index cd6d521..09e3ef8 100755 --- a/common/behaviors/MultipleImgBehavior.php +++ b/common/behaviors/MultipleImgBehavior.php @@ -23,6 +23,13 @@ * @var array */ public $links = []; + + /** + * Will be passed to get image and get images queries + * + * @var array + */ + public $conditions = []; /** * Full namespaced image model @@ -51,7 +58,12 @@ * @var ActiveRecord $owner */ $owner = $this->owner; - return $owner->hasOne($this->model, $this->links); + $query = $owner->hasOne($this->model, $this->links); + $conditions = $this->conditions; + foreach($conditions as $condition) { + $query->andWhere($condition); + } + return $query; } /** @@ -65,7 +77,12 @@ * @var ActiveRecord $owner */ $owner = $this->owner; - return $owner->hasMany($this->model, $this->links); + $query = $owner->hasMany($this->model, $this->links); + $conditions = $this->conditions; + foreach($conditions as $left => $right) { + $query->andWhere([$left => $right]); + } + return $query; } /** diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index f77889f..d7a8881 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -109,6 +109,9 @@ 'links' => [ 'product_id' => 'product_id', ], + 'conditions' => [ + 'product_variant_id' => NULL, + ], 'model' => ProductImage::className(), 'config' => [ 'caption' => 'image', -- libgit2 0.21.4