Commit 740819d41c8ca39207e25967bb5a61c05ed3d72b

Authored by Yarik
1 parent 3d4c8f83

Images fix

common/behaviors/MultipleImgBehavior.php
... ... @@ -23,6 +23,13 @@
23 23 * @var array
24 24 */
25 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 35 * Full namespaced image model
... ... @@ -51,7 +58,12 @@
51 58 * @var ActiveRecord $owner
52 59 */
53 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 77 * @var ActiveRecord $owner
66 78 */
67 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 109 'links' => [
110 110 'product_id' => 'product_id',
111 111 ],
  112 + 'conditions' => [
  113 + 'product_variant_id' => NULL,
  114 + ],
112 115 'model' => ProductImage::className(),
113 116 'config' => [
114 117 'caption' => 'image',
... ...